Skip to main content

Python-accessible, Julia-powered simulation tools for open quantum systems.

Project description

OpenQuantumSim

CI Docs PyPI Python License

QuTiP is excellent general-purpose quantum dynamics software. OpenQuantumSim is for researchers who want a Python interface while moving expensive open-system propagation into a Julia backend: Lindblad solvers, Monte Carlo wave-function trajectories, Dicke-space collective spins, restartable parameter sweeps, HDF5 outputs, phase-space tools, and state diagnostics in one package.

On the current Apple M1 benchmark snapshot, OpenQuantumSim is 1.3x-2.6x faster than QuTiP on deterministic Lindblad reference cases up to Hilbert dimension 80. For a qubit MCWF trajectory scaling smoke test, OpenQuantumSim is 5.0x-10.4x faster end-to-end than QuTiP, with 9.7x-19.7x faster Julia backend trajectory aggregation when using four Julia threads. The benchmark commands and environment are documented so these numbers can be reproduced and challenged.

OpenQuantumSim benchmark summary

Documentation: https://mohammadjafariph.github.io/OpenQuantumSimulation/

The package is currently released as an alpha. The API is usable, tested, and published on PyPI, but minor interface changes may still occur before a stable 0.1 release.

Installation

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.

For development from source:

git clone https://github.com/mohammadjafariph/OpenQuantumSimulation.git
cd OpenQuantumSimulation
python -m pip install -e ".[dev]"
python setup_julia.py

Features

  • Hilbert-space helpers for finite Fock spaces, spin spaces, tensor-product systems, and symmetric Dicke manifolds.
  • State and operator constructors for common open-system models.
  • Lindblad master-equation propagation with dense and sparse backends.
  • Monte Carlo wave-function trajectories with backend-side aggregation for selected diagnostics.
  • Time-dependent Hamiltonians with callable or interpolated coefficients.
  • Steady-state solves, two-time correlations, and parameter sweeps.
  • State metrics including purity, entropy, fidelity, trace distance, populations, coherences, and Bloch-vector components.
  • Wigner and Husimi-Q phase-space distributions for finite Fock spaces.
  • HDF5 result persistence for solver outputs and sweep summaries.
  • Validation scripts comparing analytic limits and QuTiP reference models.

Quick Example

The example below solves spontaneous emission for a two-level system and compares the excited-state population with the analytic result exp(-gamma * t).

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)

More complete scripts are available under examples/gallery/, including deterministic decay, a time-dependent driven qubit, Jaynes-Cummings dynamics, Monte Carlo trajectories, phase-space plots, and restartable parameter sweeps. Each one supports a quick smoke run:

python examples/gallery/qubit_decay.py --fast
python examples/gallery/phase_space.py --fast

Tutorial notebooks are available in the documentation, including qubit decay, Dicke synchronization, parameter sweeps, phase-space plots, and state metrics:

Time-Dependent Hamiltonians

Time-dependent systems can be written as H(t) = H0 + sum_i f_i(t) H_i.

drive = oqs.InterpolatedCoefficient([0.0, 5.0], [0.0, 0.2])
H_t = oqs.time_dependent_hamiltonian(
    0.5 * oqs.sigmaz(atom),
    [(oqs.sigmax(atom), drive)],
)

result = oqs.mesolve(H_t, rho0, np.linspace(0.0, 5.0, 101), c_ops=[collapse])

Monte Carlo Trajectories

result = oqs.mcsolve(
    H,
    excited,
    times,
    c_ops=[collapse],
    e_ops=[projector],
    n_traj=1000,
    options=oqs.Options(seed=2026, max_step=0.01, progress=True),
)

population_mean = result.expect[0].real
population_stderr = result.expect_stderr[0].real

Long trajectory runs can checkpoint partial sums and resume from the same operators, seed, time grid, and solver options:

result = oqs.mcsolve(
    H,
    excited,
    times,
    c_ops=[collapse],
    e_ops=[projector],
    n_traj=20_000,
    options=oqs.Options(
        seed=2026,
        max_step=0.01,
        checkpoint_file="runs/mcsolve_checkpoint.h5",
        checkpoint_every=100,
    ),
)

State Diagnostics

State diagnostics can be evaluated during deterministic solves, single trajectories, and supported trajectory aggregations.

metrics = oqs.state_metrics(
    purity=True,
    fidelity_to=excited,
    population_indices=[0, 1],
)

trajectory = oqs.single_trajectory(
    H,
    excited,
    times,
    c_ops=[collapse],
    state_observables=metrics,
    options=oqs.Options(seed=2026, max_step=0.01),
)

purity = trajectory.state_observables["purity"].real

Parameter Sweeps

ParameterSweep expands a parameter grid, skips completed points on rerun, writes a restartable manifest, and saves aggregate summaries.

sweep = oqs.ParameterSweep(
    base_system={"model": "qubit_decay"},
    params={"gamma": [0.05, 0.1, 0.2]},
)

run = sweep.run(run_one_point, output_dir="runs/gamma_sweep")
print(run.summary)

Phase-Space Utilities

Finite Fock-space states can be inspected with Wigner and Husimi-Q distributions.

space = oqs.FockSpace(30)
rho = oqs.ket2dm(oqs.coherent(space, 1.0 + 0.5j))
x, p = oqs.phase_space_grid(xlim=(-5.0, 5.0), points=201)

W = oqs.wigner(rho, x, p)
Q = oqs.q_function(rho, x, p)
ax = oqs.plot_wigner(rho, x, p)

Result Persistence

Solver results can be saved and loaded in HDF5 format.

result.save_hdf5("runs/qubit_decay.h5")
loaded = oqs.load_result("runs/qubit_decay.h5")

The schema stores time points, expectation series, optional saved states, state-observable series, Monte Carlo uncertainty estimates, entropy, and solver statistics.

Validation

The validation suite includes analytic qubit decay and a damped Jaynes-Cummings comparison against QuTiP.

python -m pip install -e ".[validation]"
python scripts/validate_jaynes_cummings_qutip.py

Performance comparison scripts are available under benchmarks/. Benchmark results depend strongly on problem size, backend warmup, hardware, and thread configuration; record those settings with any reported timings.

Documentation

Build the local documentation with:

python -m pip install -e ".[docs]"
sphinx-build -b html docs docs/_build/html

The documentation includes API pages, tutorials, validation examples, benchmark notes, and the HDF5 result schema.

Development

Run the Python test suite:

python -m pytest

Run the Julia backend tests:

julia --project=src/OpenQuantumSimJL -e 'using Pkg; Pkg.test()'

Repository layout:

openquantumsim/             Python frontend
src/OpenQuantumSimJL/       Julia backend package
tests/                      Python test suite
docs/                       Sphinx documentation
benchmarks/                 Benchmark scripts
scripts/                    Development and validation helpers
examples/                   Domain examples built on the public API

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openquantumsim-0.1.0a3.tar.gz (84.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openquantumsim-0.1.0a3-py3-none-any.whl (77.8 kB view details)

Uploaded Python 3

File details

Details for the file openquantumsim-0.1.0a3.tar.gz.

File metadata

  • Download URL: openquantumsim-0.1.0a3.tar.gz
  • Upload date:
  • Size: 84.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for openquantumsim-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 d6b2bf48e6ccb7dff3361fb53c81633d3af0a5bc8726055fd8300a86911a4b67
MD5 dfd200df97dd974373217fd454c77e29
BLAKE2b-256 8503a1b908116544b7ba7bf47eb1f537d291a9a050494611a2b79092d6673ee5

See more details on using hashes here.

Provenance

The following attestation bundles were made for openquantumsim-0.1.0a3.tar.gz:

Publisher: release.yml on mohammadjafariph/OpenQuantumSimulation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openquantumsim-0.1.0a3-py3-none-any.whl.

File metadata

File hashes

Hashes for openquantumsim-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 460545d8f145a4a00ffd173068e15c5515d421a11548c7bc9c79029878a0a3c1
MD5 b9010e96046801b4de8a86e52675e0c1
BLAKE2b-256 b71eba6945a1a1ebc76850d5746a9233f362360ade1c9eaf5642cd0559a86618

See more details on using hashes here.

Provenance

The following attestation bundles were made for openquantumsim-0.1.0a3-py3-none-any.whl:

Publisher: release.yml on mohammadjafariph/OpenQuantumSimulation

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page