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), macOS (Intel and Apple silicon) and
Windows (x86_64). 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 isexp(−iHt). - Vectors and matrices are NumPy
float64/complex128arrays; array arguments accept lists, tuples or arrays. - Invalid input raises
ValueErrorwith 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 2.0:
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)
again = q.Circuit.from_qasm(text)
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
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))
More complete scripts are in
examples/.
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), 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, run_vqe, MaxCutQaoa, optimize_qaoa_layerwise, VariationalClassifier |
| Textbook | grover_search, estimate_phase |
| Walks | ContinuousWalk, SpatialSearch (optimize tunes rate and time jointly), DephasingWalk, classical_walk_probabilities, classical_hitting_times |
| Noise | Channel, NoiseModel, DensityMatrix, estimate_expectation |
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.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| metatron_qso-1.0.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| metatron_qso-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| metatron_qso-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| metatron_qso-1.0.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64, macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64) | Details |
Total release size: 4.4 MB
Release files / metatron_qso-1.0.0-cp39-abi3-win_amd64.whl
| Download URL | metatron_qso-1.0.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 812.3 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1fd9b4a6b4b280e23858a4debc9144bafcf92828b560c79693a95694b937b7e0
|
|
BLAKE2b-256 checksum How to use checksums |
8f29498c930a40b542fcd477ea210113f3d697fbbaa00363bbb6c50903c6d930
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / metatron_qso-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | metatron_qso-1.0.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 937.3 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
33f8678d4ce14878af1f739c4c706536ae7a5859f36c79f11a1b651c2de2ec35
|
|
BLAKE2b-256 checksum How to use checksums |
df4ffd25a4aeea4a638aa0a2b191b044d93f1bf0191d2175fdcb842a34630080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / metatron_qso-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | metatron_qso-1.0.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 896.0 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2931b380d2af552f53e605652f8efe471064e23572666fc40d327cf7cdcb59dc
|
|
BLAKE2b-256 checksum How to use checksums |
a2d32c798215566406bc504ecb2dc23f6611d9f3ad3595c07731b95a81189eda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / metatron_qso-1.0.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | metatron_qso-1.0.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 1.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 |
72ae616e2fc2e4affb04ddbd6bdd60ab769ebd82769cbff6677ccb769a9467de
|
|
BLAKE2b-256 checksum How to use checksums |
b75dbff53414b52fafcb9371764c21f597b6d969ddbd9e23afaa22c07aa62f9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for metatron-qso 1.0.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.