Quantum Virtual Machine (QVM)
A Python quantum computing toolkit that works like a classical toolchain: install it, point it at a circuit, run it. QVM ingests quantum programs (OpenQASM 3.0 / 2.0 / JSON / Qiskit / Cirq), transpiles them onto hardware topologies, simulates them exactly, and exports them anywhere else — through one canonical Intermediate Representation.
QASM 3 ──┐ ┌──► QVM Statevector / MPS simulation
QASM 2 ──┤ ┌────────────────┐ ├──► QVM Transpiler (Greedy / SABRE routing)
JSON ───┼──►│ QVM IR │─────────┼──► Qiskit (export · Aer backend)
Qiskit ──┘ │ (the pivot) │ └──► Cirq (export · Cirq simulator)
Cirq ──────►└────────────────┘
v0.4 highlights
- Installable package (
pip install) with aqvmCLI entry point - Strict framework interop: unsupported operations raise, they are never silently dropped
- Full bidirectional gate coverage between QVM ↔ Qiskit ↔ Cirq (22-gate vocabulary)
- Domain exception hierarchy (
QVMErrorroot) for reliable error handling - In-place O(2^N) statevector kernels, configurable execution budgets, cached QASM3 parser
Installation
Requires Python ≥ 3.9. The core depends only on numpy and lark; everything else is opt-in:
pip install quantum-virtual-machine # lean core: parse, transpile, simulate
pip install "quantum-virtual-machine[qiskit]" # + Qiskit & Aer interop
pip install "quantum-virtual-machine[cirq]" # + Cirq interop
pip install "quantum-virtual-machine[viz]" # + matplotlib visualizations
pip install "quantum-virtual-machine[server]" # + FastAPI dashboard stack
pip install "quantum-virtual-machine[dev]" # + pytest and dev tooling
From source (development):
git clone https://github.com/qayumXD/quantum-virtual-machine.git
cd quantum-virtual-machine
pip install -e ".[dev]"
Optional backends degrade gracefully: calling an interop API without the matching extra raises MissingBackendError with the exact pip install command to fix it.
Quickstart
CLI
qvm circuit.qasm # simulate a QASM file
qvm circuit.json --nqubits 4 # simulate a JSON gate list
qvm bell.qasm --shots 1024 --seed 42 # shot-based sampling
qvm bell.qasm --transpile --routing sabre # route onto linear topology
qvm bell.qasm --device fake_5q # hardware noise profile
qvm vqe_circuit.json --nqubits 2 --expectation ZZ # Pauli expectation value
Python API
from qvm.parser import OpenQASM2Parser
from qvm.transpiler import Transpiler
from qvm.simulator import Simulator
from qvm.architecture import get_linear_architecture
qc = OpenQASM2Parser.parse(open("examples/bell_state.qasm").read())
arch = get_linear_architecture(qc.num_qubits)
qc = Transpiler(arch, strategy="sabre").transpile(qc)
state, classical_memory = Simulator().simulate(qc)
print((abs(state) ** 2).round(3))
Framework bridge
import cirq, qiskit
from qvm.ir import QuantumCircuit
circuit = cirq.Circuit(cirq.H(cirq.LineQubit(0)), cirq.CNOT.on(cirq.LineQubit(0), cirq.LineQubit(1)))
qk_circuit = QuantumCircuit.cirq_to_qiskit(circuit) # Cirq → QVM IR → Qiskit
Framework interoperability
All conversions go through the QVM IR pivot (N+M converters instead of N×M). The interop layer is governed by two guarantees:
- No silent drops. Every operation either converts faithfully or raises
UnsupportedGateErrornaming the offending gate. A conversion that returns means the returned circuit is your circuit. - Physical equivalence. Exported circuits reproduce QVM's measurement probability distributions (validated by a triple-engine test suite: QVM vs Qiskit vs Cirq).
Supported vocabulary:
| Class | Gates |
|---|---|
| 1-qubit, no parameters | h, x, y, z, s, sdg, t, tdg, sx, sxdg, id |
| 1-qubit, 1 angle | rx(θ), ry(θ), rz(θ), p(λ) |
| 2-qubit, no parameters | cx, cz, swap |
| 2-qubit, 1 angle | rxx(θ), rzz(θ), cp(λ) |
| 3-qubit | ccx |
| Ancillary | measure, barrier, delay |
Notes:
- Parameters: symbolic parameters survive conversion (Qiskit
Parameter↔ QVMParameter↔ Cirq sympy symbols). Fully-bound expressions export as floats; partially-bound ones raiseQVMConversionErroruntil you callbind_parameters(). - Measurements: Cirq keys use the canonical
"register[index]"format; legacy tuple-string keys are still parsed on import. - Global phase is not represented in the IR and is therefore not preserved (physically unobservable, same convention as OpenQASM).
- Anything outside the vocabulary — control flow, arbitrary unitaries, exotic gates — fails loudly with a message listing the supported set.
Full details: docs/guides/INTEROP.md
Error handling
Every QVM error derives from one base class, so callers can catch broadly or narrowly:
from qvm.exceptions import (
QVMError, # root
QVMParseError, # syntax / grammar failures (ValueError)
QVMCompilationError, # routing / decomposition / conversion failures
UnsupportedGateError, # gate outside a subsystem's vocabulary
QVMConversionError, # unfaithful-or-impossible format conversion
MissingBackendError, # optional Qiskit/Cirq extra not installed (ImportError)
QVMRuntimeError, # simulation failures (RuntimeError)
QVMResourceLimitError, # op-budget breaches (RuntimeError)
)
Concrete classes also inherit the built-in shown in parentheses, so existing except ValueError / except RuntimeError code keeps working during migration.
Validation is eager: malformed arities (cx on one qubit), measurements into undeclared registers, and unknown gates all fail at circuit-construction time — never mid-simulation.
Simulation engines
| Engine | Use case | Notes |
|---|---|---|
Simulator (statevector) |
Exact amplitudes, N ≲ 12–16 | In-place tensor-stride kernels, full classical memory + label/jump control flow, stochastic Kraus noise trajectories |
MPSSimulator |
Low-entanglement circuits, 20+ qubits | Bond-dimension-truncated SVD evolution |
Noise modeling supports depolarizing, amplitude damping, and phase damping channels plus device profiles (fake_5q, fake_7q, ideal). For a candid assessment of scaling limits beyond this range, see docs/production_readiness_analysis.md.
Testing
pytest # whole unit + interop suite
pytest tests/test_interop_roundtrip.py -v # interop guarantees (triple-engine equivalence)
python -m benchmarks.run_audit --all # 19-algorithm audit corpus (QASM/Qiskit/Cirq/VQE/QAOA)
The interop suite verifies probability agreement across QVM, Qiskit, and Cirq for every gate in the vocabulary, round-trip structural preservation, and that unsupported inputs raise rather than corrupt. The audit corpus runs textbook-to-industry algorithms end-to-end and cross-validates against native simulators — see docs/reports/algorithm_audit_2026-08-24.md.
Project layout
quantum-virtual-machine/
├── pyproject.toml # packaging, extras, console script
├── src/qvm/ # the installable `qvm` package
│ ├── ir.py # QuantumCircuit IR + framework converters
│ ├── parser.py # QASM 2.0 + JSON ingestion
│ ├── qasm3_parser.py # OpenQASM 3.0 (Lark LALR, module-cached)
│ ├── transpiler.py # Greedy / SABRE routing
│ ├── decomposer.py # gate decomposition passes
│ ├── simulator.py # dense statevector engine
│ ├── mps_simulator.py # tensor-network engine
│ ├── noise.py # Kraus channels & noise models
│ ├── observable.py # Hamiltonians / Pauli expectations
│ ├── vqe.py / qaoa.py / gradient.py / parameter.py
│ ├── cli.py # `qvm` command
│ ├── exceptions.py # domain error hierarchy
│ └── util/export.py # exporters
├── api/app.py # optional FastAPI service
├── web/ # optional Next.js dashboard
├── tests/ # pytest suite (incl. interop + stress)
└── docs/ # design docs, guides, readiness analysis
License
MIT — see distribution metadata.
Release files for quantum-virtual-machine 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| quantum_virtual_machine-0.4.0.tar.gz | 72.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| quantum_virtual_machine-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 131.4 kB
Release files / quantum_virtual_machine-0.4.0.tar.gz
| Download URL | quantum_virtual_machine-0.4.0.tar.gz |
|---|---|
| Size | 72.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
33a8c6a932407efe351a95255b01fc591355cbf1bc0022a962bd5496344d20f5
|
|
BLAKE2b-256 checksum How to use checksums |
fe133ad1a65f03f88b7d607b6ae65bbfe7c020f2267d89fdf81821e94ba58cf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / quantum_virtual_machine-0.4.0-py3-none-any.whl
| Download URL | quantum_virtual_machine-0.4.0-py3-none-any.whl |
|---|---|
| Size | 59.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b76c657f076d3a35acd5ebe4c2c3e567786774951e39886166281cd67a48dd51
|
|
BLAKE2b-256 checksum How to use checksums |
36c1168f08b70bfcf0cdb84598f04c895766f6c4576d5a9cb7ed9727dd4acfb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|