Quick Start¶
Install OpenQuantumSim from PyPI:
python -m pip install openquantumsim
OpenQuantumSim uses JuliaCall to load the packaged Julia backend. The first solver call on a new machine may spend a few minutes resolving and precompiling Julia packages.
Backend Setup and Startup Speed¶
Run the backend setup once after installing OpenQuantumSim:
oqs setup-julia
This moves Julia package resolution and precompilation out of the first solver call. For repeated simulation sessions, build a local Julia sysimage:
oqs build-sysimage
The sysimage build can take several minutes, but future solver calls
automatically reuse it through JuliaCall. Rebuild it after upgrading Julia or
OpenQuantumSim. Set OPENQUANTUMSIM_USE_SYSIMAGE=0 to disable automatic
sysimage use for a process, or set OPENQUANTUMSIM_JULIA_SYSIMAGE to point
at a custom sysimage.
Spontaneous Emission¶
This example solves spontaneous emission for a two-level system and compares the excited-state population with the analytic result.
import numpy as np
import openquantumsim as oqs
atom = oqs.SpinSpace(0.5, label="atom")
excited = oqs.basis(atom, "up")
gamma = 0.2
H = 0.0 * oqs.sigmaz(atom)
rho0 = oqs.ket2dm(excited)
collapse = np.sqrt(gamma) * oqs.sigmam(atom)
projector = oqs.Operator(oqs.ket2dm(excited), atom, "P_excited")
times = np.linspace(0.0, 0.2, 3)
result = oqs.mesolve(
H,
rho0,
times,
c_ops=[collapse],
e_ops=[projector],
options=oqs.Options(rtol=1e-8, atol=1e-10),
)
expected = np.exp(-gamma * times)
assert np.allclose(result.expect[0].real, expected, atol=2e-7)
print(result.expect[0].real)
Development Install¶
For local development from source:
git clone https://github.com/mohammadjafariph/OpenQuantumSimulation.git
cd OpenQuantumSimulation
python -m pip install -e ".[dev]"
oqs setup-julia
Run the Python and Julia tests with:
python -m pytest
julia --project=src/OpenQuantumSimJL -e 'using Pkg; Pkg.test()'