Skip to content

Instantly share code, notes, and snippets.

"""
Simple script to learn the basics of PySCF. This script computes
the optimal geometry of a molecule, and then visualizes its electron
density.
Commands for installing the necessary modules:
# Install PySCF
python3 -m pip install pyscf
import sys
def xor_each_byte(input_fname: str, xor_key: int, output_fname: str):
with open(input_fname, 'rb') as f:
bytes_arr = bytes([b^xor_key for b in f.read()])
with open(output_fname, 'wb') as f:
f.write(bytes_arr)
/* Bitonic sort.
Compile and run with gcc ./bitonic_sort.c -O3 -o program; ./program
Reference:
Wikipedia - Bitonic Sort
https://en.wikipedia.org/wiki/Bitonic_sorter
*/
"""Two particles trapped inside a 1D box.
This script is based on this article by Daniel Schroeder:
https://physics.weber.edu/schroeder/quantum/EntanglementIsntJustForSpin.pdf
as well as this accompanying interactive web page:
https://physics.weber.edu/schroeder/software/CollidingPackets.html
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
from scipy.fft import dst, idst
from scipy.integrate import trapezoid
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# Constants
N: int = 512
X = np.arange(0, N, dtype=np.float64)
"""
This script numerically solves the linear and nonlinear Schrodinger equation
using the split operator method, and then shows a matplotlib animation of the
results.
References:
Split operator method:
James Schloss. The Split Operator Method - Arcane Algorithm Archive.
https://www.algorithm-archive.org/contents/split-operator_method/
split-operator_method.html
/* Numerically solve for the time-dependent Schrodinger equation in 2D,
using the split operator method. To build and run, type:
rustc qm2d_split_op.rs
./qm2d_split_op
This will output a series of bmp images which show each frame of the
simulation.
References:
"""
Simulation of coupled Fermions by explicitly constructing the Fermion
operators as matrices and then diagonalizing the subsequent Hamiltonian
to find the energies and energy eigenvectors.
The primary reference for this is Chapter 4 of
Introduction to Many Body Physics by Piers Coleman, pg 71 - 77 on the
Jordan-Wigner transformation.
P. Coleman, Simple examples of second quantization,
"""
Using the Chebyshev method purely with finite differences
to numerically integrate the Schrodinger equation in 1D.
This is primarily based on the following article:
Tal-Ezer H., Kosloff R. (1984).
An accurate and efficient scheme for propagating
the time dependent Schrodinger equation.
J. Chem. Phys. 81(9), 3967-3971.