Skip to main content

metatron-qso (Python)

Python bindings for QSO, a validated quantum simulator written in pure Rust (metatron-qso-rs): exact state-vector and density-matrix simulation, VQE and QAOA with exact gradients, Grover search, QFT and phase estimation, and continuous-time quantum walks on arbitrary graphs — including Metatron's Cube. Every algorithm is tested against closed-form or literature results.

Install

pip install metatron-qso

Wheels target the stable ABI (abi3, one wheel for CPython ≥ 3.9) and are provided for Linux (x86_64, aarch64; glibc and musl), macOS (Intel and Apple silicon) and Windows (x86_64, arm64). The only runtime dependency is NumPy. On other platforms pip builds from the source distribution, which needs a Rust toolchain ≥ 1.89.

From a clone of the repository:

pip install maturin
maturin develop --release -m metatron_qso_py/Cargo.toml   # into the active venv

Conventions

  • Qubit 0 is the least significant bit of a basis index (as in Qiskit); bit strings print qubit n−1 first ("001" means qubit 0 is 1).
  • Rotations are R_P(θ) = exp(−iθP/2); time evolution is exp(−iHt).
  • Vectors and matrices are NumPy float64 / complex128 arrays; array arguments accept lists, tuples or arrays.
  • Invalid input raises ValueError with a descriptive message.
  • Long-running calls (VQE, QAOA, walks, simulation) release the GIL.

Examples

Circuits, sampling and observables:

import metatron_qso as q

bell = q.Circuit(2).h(0).cx(0, 1)
state = q.simulate(bell)
print(state.amplitudes)                       # complex128 array of length 4
print(state.sample(1000, seed=1))             # {'00': ..., '11': ...}
print(state.expectation(q.PauliSum("Z0 Z1"))) # 1.0
print(state.entanglement_entropy([0]))        # 1.0 (bits)

Symbolic parameters, exact gradients and OpenQASM:

import numpy as np
import metatron_qso as q

c = q.Circuit(2)
a, b = c.new_parameters(2)
c.ry(0, a).cx(0, 1).rz(1, 2.0 * b + 0.5)
h = q.PauliSum("0.5*Z0 Z1 - X0")
value, grad = q.expectation_and_gradient(c, h, [0.3, 0.1])  # adjoint method
_, fd = q.expectation_and_gradient(c, h, [0.3, 0.1], method="finite_difference")
assert np.allclose(grad, fd, atol=1e-6)

text = c.to_qasm([0.3, 0.1], measure=True)      # OpenQASM 2.0
again = q.Circuit.from_qasm(text)
print(c.to_qasm3([0.3, 0.1]))                     # OpenQASM 3

Programs with mid-circuit measurement and feed-forward, from OpenQASM 2 or 3, with exact outcome probabilities:

import metatron_qso as q

p = q.Program.from_qasm('''
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
bit[2] c;
h q[0];
c[0] = measure q[0];
if (c[0] == 1) x q[1];
c[1] = measure q[1];
''')
print(p.probabilities())        # ≈ {'00': 0.5, '11': 0.5}, bit 0 on the right
print(p.sample(1000, seed=1))   # {'00': 504, '11': 496}
print(p.to_qasm3())

Ground state of H₂ (STO-3G) with VQE:

import metatron_qso as q

h2 = q.h2_sto3g()
result = q.run_vqe(h2["hamiltonian"], q.real_amplitudes(2, 1), restarts=4)
print(result["energy"] + h2["nuclear_repulsion"])  # -1.137306 Ha (full CI)

QAOA for MaxCut (depth 1 on a ring gives exactly 3/4):

import metatron_qso as q

qaoa = q.MaxCutQaoa(q.Graph.cycle(8), p=1)
result = qaoa.optimize(restarts=8, seed=0)
print(result["approximation_ratio"])     # 0.75
print(result["most_likely_bitstring"])   # an optimal cut, e.g. '10101010'

Quantum walks on Metatron's Cube (the complete graph K13 on the 13 Fruit-of-Life centres):

import math
import metatron_qso as q

cube = q.Graph.metatron_cube()
print(cube.automorphism_group_order())         # 6227020800 = 13!

walk = q.ContinuousWalk(cube)                   # H = γL, γ = 1
print(walk.limiting_distribution(0)[:2] * 169)  # [145. 2.]

search = q.SpatialSearch(cube, marked=[4], gamma=1 / 13)
print(search.success_probability(math.pi * math.sqrt(13) / 2))  # 1.0

Symmetry, state transfer and discrete-time walks:

import math
import metatron_qso as q

walk = q.QuotientWalk(q.Quotient.hypercube(30))       # 2^30 nodes, 31 cells
print(walk.cell_probabilities(0, math.pi / 2)[-1])     # 1.0: the antipode

print(q.StateTransfer(q.Graph.path(3), 0, 2, "adjacency").perfect_transfer_time)  # pi/sqrt(2)
print(q.Graph.shrikhande().is_isomorphic(q.Graph.rook(4, 4)))                     # False

skw = q.CoinedWalk(q.Graph.hypercube(10), "grover", marked=[0]).search(60)
print(skw["steps"], skw["success_probability"])        # 38 0.435
print(q.SzegedyWalk(q.Graph.cycle(64), 0).hitting_time(1000))                    # 16

Noise:

import metatron_qso as q

bell = q.Circuit(2).h(0).cx(0, 1)
rho = q.DensityMatrix.simulate(bell, noise=q.NoiseModel.depolarizing(0.01, 0.02))
print(rho.purity(), rho.fidelity_with_pure(q.simulate(bell)))
energy = q.estimate_expectation(bell, q.PauliSum("Z0 Z1"), shots=10_000,
                                noise=q.NoiseModel.depolarizing(0.01, 0.02))

Device models, trajectories and error mitigation (readout mitigation plus zero-noise extrapolation):

import metatron_qso as q

device = (q.DeviceModel("toy")
          .with_default_qubit(t1=100.0, t2=80.0, readout=(0.02, 0.04))
          .with_rule(gate="cx", duration=0.3, depolarizing=0.01)
          .with_rule(duration=0.035, depolarizing=0.001))
ghz = q.Circuit(3).h(0).cx(0, 1).cx(1, 2)
h = q.PauliSum("Z0 Z1 + Z1 Z2")                                  # noiseless value 2
cal = q.ReadoutCalibration.tensored(3, 100_000, seed=1, device=device)

def run(circuit):
    return q.estimate(circuit, h, 100_000, device=device, readout_calibration=cal, seed=2)[0]

raw, _ = q.estimate(ghz, h, 100_000, device=device, seed=2)
mitigated = q.zne(ghz, [1.0, 3.0, 5.0], run)["estimate"]
print(f"{raw.value:.3f} {mitigated.value:.3f} ± {mitigated.std_error:.3f}")  # 1.725 2.001 ± 0.007
print(q.TrajectorySimulator(device, 2000, seed=3).expectation(ghz, h).value)  # 1.969

Molecules, time evolution and amplitude estimation (run from the repository root, which holds the FCIDUMP files):

import metatron_qso as q

lih = q.MolecularIntegrals.from_file("metatron-qso-rs/examples/molecules/lih_sto3g.fcidump")
adapt = q.adapt_vqe(lih, "parity", two_qubit_reduction=True)          # 10 qubits
print(f"{adapt['energy'] - lih.fci_energies()[0]:.1e}", len(adapt["operators"]))  # 1.1e-05 30

h = q.heisenberg_xxz(4, 1.0, 0.5)
c = q.trotter_circuit(h, 4, 1.0, steps=20, order=2)
print(len(c), f"{q.trotter_error_bound(h, 1.0, steps=20, order=2):.4f}")  # 321 0.0229

r = q.ml_amplitude_estimation(q.AmplitudeProblem.bernoulli(0.3), levels=8, shots=100, seed=1)
print(f"{r['estimate']:.4f}", r["oracle_calls"])                        # 0.2998 26200

More complete scripts are in examples/; the user guide has tutorials and the full API reference.

API overview

Area Names
Graphs Graph (from_spec, metatron_cube, fruit_of_life, metatron_distance_graph, complete, cycle, path, star, complete_bipartite, hypercube, petersen, grid, platonic, random_regular, erdos_renyi, heawood, johnson, kneser, hamming, rook, paley, circulant, cayley_z2, shrikhande; cartesian_product, strongly_regular_parameters, girth, triangle_count, automorphisms, spectra; canonical_labelling, canonical_form, is_isomorphic, isomorphism, relabeled; from_edge_list/to_edge_list, from_graphml/to_graphml, from_networkx), metatron_line_lengths
Circuits Circuit, Parameter, qft, inverse_qft, grover_circuit
States StateVector, simulate, PauliSum, bitstring
Models h2_sto3g, transverse_field_ising, heisenberg_xxz, maxcut_cost
Variational real_amplitudes, efficient_su2, hardware_efficient, qaoa_maxcut_circuit, expectation_and_gradient, expectation_batch, expectation_and_gradient_batch, run_vqe, MaxCutQaoa, optimize_qaoa_layerwise, VariationalClassifier, GraphClassifier
Textbook grover_search, estimate_phase
Walks ContinuousWalk, SpatialSearch (optimize tunes rate and time jointly), DephasingWalk, DrivenWalk, classical_walk_probabilities, classical_hitting_times; Quotient, QuotientWalk, QuotientSearch, StateTransfer; CoinedWalk, DecoherentCoinedWalk, LineWalk, SzegedyWalk; circulant_walk_circuit, cayley_walk_circuit, trotter_walk_circuit, diagonal_unitary_circuit
Noise Channel, NoiseModel, DeviceModel, DensityMatrix, TrajectorySimulator, estimate_expectation
Estimation Estimate, estimate (uniform, weighted, adaptive shot allocation), ClassicalShadow
Mitigation ReadoutCalibration, nearest_probability_distribution, fold, extrapolate, zne, pec_expectation, twirl, twirled_average; noise learning: SparsePauliLindblad, learn_layer, pec_layered, pea_layered
Hamiltonian simulation Circuit.pauli_rotation, trotter_circuit, trotter_error_bound, qdrift_circuit, qdrift_error_bound
Chemistry FermionOperator, QubitOperator, MolecularIntegrals, uccsd, k_upccgsd, adapt_vqe
Excited states and geometry vqd, ssvqe, quantum_fisher_information, natural_gradient, quantum_natural_gradient, imaginary_time_evolution
Optimisation and estimation Qubo, Qaoa (X, XY and warm-start mixers), AmplitudeProblem, canonical_amplitude_estimation, iterative_amplitude_estimation, ml_amplitude_estimation
Boson sampling BosonSampler, ImperfectBosonSampler, permanent, haar_unitary, beam_splitter; Gaussian boson sampling: GaussianState, hafnian, hafnian_repeated, torontonian

Graph.from_spec accepts the graph specifications of the qso command-line tool, e.g. "metatron", "metatron:1", "hypercube:4", "platonic:cube" (full list in the main README).

Type information ships with the package (_core.pyi, py.typed).

Optimisers for run_vqe / MaxCutQaoa.optimize: lbfgs (default), adam, gradient_descent, nelder_mead, spsa. Gradient methods: adjoint (default), parameter_shift, finite_difference.

Tests

pip install pytest
pytest metatron_qso_py/tests -q

License

Apache-2.0

Metadata

Release files for metatron-qso 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for metatron-qso 1.7.0
File Size Uploaded Provenance Actions
metatron_qso-1.7.0.tar.gz 851.0 kB With provenance Details for metatron_qso-1.7.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for metatron-qso 1.7.0
File Actions
metatron_qso-1.7.0-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for metatron_qso-1.7.0-cp39-abi3-win_arm64.whl
metatron_qso-1.7.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for metatron_qso-1.7.0-cp39-abi3-win_amd64.whl
metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_x86_64.whl CPython 3.9 abi3 Linux musl 1.2+ x86-64 Details for metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_x86_64.whl
metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_aarch64.whl CPython 3.9 abi3 Linux musl 1.2+ ARM64 Details for metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_aarch64.whl
metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
metatron_qso-1.7.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.9 abi3 macOS 11.0+ ARM64, macOS 10.12+ x86-64, macOS 10.12+ universal2 (ARM64, x86-64) Details for metatron_qso-1.7.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 24.5 MB

Release files / metatron_qso-1.7.0.tar.gz

Download URL metatron_qso-1.7.0.tar.gz
Size 851.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f23185cc5c1169db71a48d87da99bddcfc681d319f86accd77fa28120fd64bef
BLAKE2b-256 checksum
How to use checksums
289a268acec6c059c13485c723171dca11aff6ca3ea9633f7501de8e782347ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-win_arm64.whl

Download URL metatron_qso-1.7.0-cp39-abi3-win_arm64.whl
Size 2.7 MB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
4ac751ac99bbf483af58bf0924b648242ed7213401f66b6316acc66b29599c59
BLAKE2b-256 checksum
How to use checksums
3430256631211e3383c937c9f396337376863d4ceec46558c6dbe391dfa789e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-win_amd64.whl

Download URL metatron_qso-1.7.0-cp39-abi3-win_amd64.whl
Size 3.0 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d03647c12fbfba457506e7fd22b97cfcf6ff7fe5a8fa2688c037f440997e8305
BLAKE2b-256 checksum
How to use checksums
bfbd932aa170a20f31802d90455189207a6271b21d94ddf6808d489fa400fbe8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_x86_64.whl

Download URL metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_x86_64.whl
Size 3.3 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
13a20b6da24b788d59824b257b3a959a40d14ad9c3ec2c48c77d235d1774400c
BLAKE2b-256 checksum
How to use checksums
da198b14573f6e74c41202557e7d3c7fa1059e7bcbe1ea303de912e13bae4513
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_aarch64.whl

Download URL metatron_qso-1.7.0-cp39-abi3-musllinux_1_2_aarch64.whl
Size 3.0 MB
Tags CPython 3.9 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
0d68cf4d46a07da3b8963f97972ad254028d1c241aceeadbd4e19e1963d8d6a1
BLAKE2b-256 checksum
How to use checksums
4e78bedd68954e9812d56e3188e762293fa22c82790de4af176483b04cdea125
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.1 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b6d54ae9f4262279b1291d1d6ad6a2c204ada7a1994f3113e1287995e0313023
BLAKE2b-256 checksum
How to use checksums
337e98d256dfca560b7a9f5fa910cea1d4ccb29680ebc2a823e00c6cce992da7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL metatron_qso-1.7.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 2.9 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
8969c0b1f7a941975d10d276cea47794215dfffbdc4ed3e34455c20fec094606
BLAKE2b-256 checksum
How to use checksums
90f6a0b6d289ca8c8ad679fa2def54da6c23df8a2519e10358356a3fd2fcbad6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / metatron_qso-1.7.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL metatron_qso-1.7.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 5.7 MB
Tags CPython 3.9 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6c5831c76224c69353fe1a7a56c631bd6e72b755edf2a34c715b9a95e440f7dc
BLAKE2b-256 checksum
How to use checksums
a1e89f5c31701a0e954f35686c84b634cbca00c56dccebaf22dde97128262d17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Security for metatron-qso 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for metatron_qso-1.7.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page