Skip to content

Instantly share code, notes, and snippets.

/* Numerically find the lowest energy bound states for a potential in 3D.
This uses a uniform cartesian grid finite difference approximation, where a
second-order accurate stencil is used for the Laplacian.
Dirichlet boundary conditions are imposed.
The eigenvalue problem is solved using Spectra (https://spectralib.org/),
and Eigen (https://eigen.tuxfamily.org/index.php?title=Main_Page).
If Spectra and Eigen are in the same directory as this file, compile with:
clang++ -std=c++17 -O3 -I${PWD} -c energy_eigenstates3d.cpp;
clang++ energy_eigenstates3d.o -o ees3d
<!DOCTYPE html>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<html>
<head>
<title>Pyodide Example</title>
<script src="https://cdn.jsdelivr.net/pyodide/v0.29.0/full/pyodide.js"></script>
</head>
<style>
* {
"""
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: