Quantum computing state vector simulator with linear XEB benchmarking
Project description
Qomputing Simulator
Qomputing Simulator is a lightweight, pure Python toolkit for simulating quantum state vectors and running linear cross-entropy benchmarking (XEB) experiments end-to-end.
Install: pip install qomputing
(Or from source: pip install . in the repo, or pip install git+https://github.com/d2Anubis/state-vector-simulator.git)
Use it after install
Once pip install qomputing is done, people can use it in two ways.
1. From the command line (CLI)
Run these in a terminal (bash/shell), not inside Python or IPython.
# Random circuit + XEB benchmark
qomputing-sim random-circuit --qubits 3 --depth 5 --shots 1000
# Simulate a circuit from a JSON file (use a real path to your circuit file)
qomputing-sim simulate --circuit circuits/example.json --shots 512 --seed 42
2. From Python (library)
Run this code in a Python script or notebook (e.g. IPython/Jupyter).
Backend API (recommended): Import QomputingSimulator, get a backend, then backend.run(qc, shots=...) and result.get_counts():
from qomputing import QomputingSimulator, QuantumCircuit
backend = QomputingSimulator.get_backend("state_vector")
# Circuit with 4 qubits and 4 classical bits; measure qubits 0,1,2 into classical 0,1,2
qc = QuantumCircuit(4, 4)
qc.h(0).cx(0, 1)
qc.measure(range(3), range(3))
result = backend.run(qc, shots=1024)
counts = result.get_counts()
print(counts)
# Optional: result.get_statevector(), result.get_probabilities()
Simple API (no backend): Build a circuit and use run() for a quick result:
from qomputing import run, QuantumCircuit, run_xeb, random_circuit
circuit = QuantumCircuit(2)
circuit.h(0).cx(0, 1) # Bell state
result = run(circuit, shots=1000, seed=42)
print(result.final_state, result.probabilities, result.counts)
circuit = random_circuit(num_qubits=3, depth=5, seed=7)
xeb = run_xeb(circuit, shots=1000, seed=7)
print(xeb.fidelity, xeb.sample_probabilities)
3. Run on Google Colab
- Open Google Colab and create a new notebook.
- First cell (install):
!pip install qomputing -q
- Next cell (use the library; the CLI is for terminals only):
from qomputing import QomputingSimulator, QuantumCircuit backend = QomputingSimulator.get_backend("state_vector") qc = QuantumCircuit(2) qc.h(0).cx(0, 1) result = backend.run(qc, shots=1000, seed=42) print("Counts:", result.get_counts())
How people install (step-by-step)
-
Install
pip install qomputing
Optional: use a virtual environment first (
python3 -m venv .venvthensource .venv/bin/activateon macOS/Linux). -
Optional extras:
pip install qomputing[dev](adds pytest),pip install qomputing[build](adds build tool).
Where you push and how to publish (maintainer)
1. Push code to GitHub (or GitLab, etc.)
-
Where: Your Git remote (e.g. GitHub).
-
Create a repo if needed, then from your project folder:
git remote add origin https://github.com/YOUR_USERNAME/qomputing.git git add . git commit -m "Rename to qomputing" git push -u origin main
GitHub permission (browser redirect + passcode): If git push asks for login, use GitHub’s web flow so you’re redirected to GitHub to approve:
./scripts/github-auth.sh
That script uses the GitHub CLI (gh). It will open your browser → you log in on GitHub → GitHub shows a one-time code → you paste the code back in the terminal. After that, git push origin main works without a password.
If you don’t have gh: install it (e.g. brew install gh on macOS), then run ./scripts/github-auth.sh again.
- People can clone and install from source:
git clone https://github.com/YOUR_USERNAME/qomputing.gitthenpip install .in the repo.
2. Publish to PyPI (so anyone can pip install qomputing)
PyPI is the default place pip installs from. Steps:
-
Create accounts
- pypi.org (for real releases)
- test.pypi.org (optional, for testing uploads)
-
Install build tools
pip install build twine
-
Build the package
cd /path/to/simulator python -m build
This creates
dist/qomputing-0.1.0-py3-none-any.whlanddist/qomputing-0.1.0.tar.gz. -
Upload to Test PyPI (optional)
twine upload --repository testpypi dist/*
When prompted, use your Test PyPI username and password (or token). Test install with:
pip install --index-url https://test.pypi.org/simple/ qomputing -
Upload to PyPI (real release)
twine upload dist/*
Use your PyPI username and password, or an API token.
-
Later releases: Bump
versioninpyproject.toml, runpython -m buildagain, thentwine upload dist/*. You cannot reuse the same version number on PyPI.
After step 5, anyone can run pip install qomputing without cloning the repo.
Quick Start (development / from source)
Install from source (development or local)
git clone https://github.com/YOUR_USERNAME/qomputing.git
cd qomputing
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install -e ".[dev]"
pip install -e .installs the simulator and Cirq; the optional[dev]extra addspytest.- To install as a normal (non-editable) library:
pip install .(no-e).
Build wheels only (for offline or custom install)
From the project root:
pip install build
python -m build
Install the wheel anywhere: pip install dist/qomputing-*.whl
Offline / no wheel build
If you cannot use pip to fetch the package:
export PYTHONPATH="$PWD"
python -m qomputing.cli random-circuit --qubits 3 --depth 5 --shots 1000
Repository Layout
qomputing/
├── circuit.py # QuantumCircuit builder, JSON (de)serialization
├── gates/ # Single-, two-, and multi-qubit gate handlers
├── engine/ # StateVectorSimulator core, result dataclass, sampling
├── linalg.py # Shared tensor/linear algebra helpers
├── cli.py # CLI entry point (`qomputing-sim`)
├── xeb.py # Linear XEB fidelity helpers
├── tools/cirq_comparison.py # Parity harness against Cirq
└── tests/ # Pytest parity checks for representative gates
CLI Usage
-
Run a random-circuit XEB benchmark:
qomputing-sim random-circuit --qubits 3 --depth 5 --shots 1000
Use
--single-qubit-gates/--two-qubit-gates/--multi-qubit-gatesto override the default gate pools (["h","rx","ry","rz","s","t"],["cx","cz","swap"], none). -
Simulate a circuit defined in JSON:
qomputing-sim simulate --circuit circuits/example.json --shots 512 --seed 123
Library usage
You can run the simulator from Python:
from qomputing import (
QuantumCircuit,
load_circuit,
run,
run_xeb,
random_circuit,
)
# Build a circuit and run (state vector only if shots=0)
circuit = QuantumCircuit(2)
circuit.h(0).cx(0, 1)
result = run(circuit, shots=1000, seed=42)
print(result.final_state, result.probabilities, result.counts)
# Load from JSON
circuit = load_circuit("circuits/example.json")
result = run(circuit, shots=512)
# Random circuit and linear XEB
circuit = random_circuit(num_qubits=3, depth=5, seed=7)
xeb_result = run_xeb(circuit, shots=1000, seed=7)
print(xeb_result.fidelity, xeb_result.sample_probabilities)
See examples/library_usage.py for a runnable example.
Example Circuits
Ready-made demonstrations live in qomputing/examples/demo_circuits.py. After activating your environment, run them as a module from the project root:
python -m qomputing.examples.demo_circuits --example bell
python -m qomputing.examples.demo_circuits --example deutsch-jozsa --oracle balanced --shots 1024 --seed 7
python -m qomputing.examples.demo_circuits --example ghz --shots 1000 --seed 123
Each command prints the final state vector, measurement probabilities, and (when --shots > 0) sampled counts. Use --example bell|deutsch-jozsa|ghz and, for Deutsch–Jozsa, pick --oracle constant|balanced.
Circuit Specification
Circuits are defined as JSON documents of the following structure:
{
"num_qubits": 2,
"gates": [
{"name": "h", "targets": [0]},
{"name": "cx", "controls": [0], "targets": [1]},
{"name": "rz", "targets": [0], "params": {"theta": 1.5708}}
]
}
Supported gate names (and their parameters):
- Single-qubit:
id,x,y,z,h,s,sdg,t,tdg,sx,sxdg,rx(θ),ry(θ),rz(θ),u1(λ),u2(φ,λ),u3(θ,φ,λ) - Two-qubit:
cx,cy,cz,cp(φ),csx,swap,iswap,sqrtiswap,rxx(θ),ryy(θ),rzz(θ) - Multi-qubit:
ccx,ccz,cswap
Testing & Validation
-
Unit tests (Pytest)
pytest
The tests execute representative single-, two-, and three-qubit circuits and assert that our simulator matches Cirq to ≤1e-7 after global phase alignment.
-
Parity harness against Cirq
export PYTHONPATH="$PWD" # only needed if not pip-installed python tools/cirq_comparison.py \ --min-qubits 1 --max-qubits 5 \ --depths 3 5 \ --circuits-per-config 3 \ --shots 256 \ --seed 7
The summary at the end reports maximum amplitude/probability/XEB deviations. Pass
--helpto explore gate-pool overrides or larger qubit ranges. For qubits ≥20, allocate ample RAM (≥16 GB) and expect runtimes of multiple minutes. -
Large-scale sweep (optional)
python tools/cirq_comparison.py \ --min-qubits 5 --max-qubits 25 \ --depths 5 \ --circuits-per-config 1 \ --shots 0 \ --seed 42 \ > comparison_results_25q.txt
This tests state-vector parity without sampling. Inspect the resulting file for per-configuration error logs and the summary block.
Development Workflow
- Run
pytestbefore committing. - Use
qomputing-sim random-circuitto generate sample workloads or JSONs for reproducible scenarios. - Benchmark changes with
tools/cirq_comparison.pyto confirm parity with Cirq remains within tolerance. - Generated artifacts (
comparison_results*.txt,__pycache__/, virtual environments) are ignored via.gitignore.
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qomputing-0.1.5.tar.gz.
File metadata
- Download URL: qomputing-0.1.5.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9cc93e677ee9347facccb77cb664750b90f25b83794450143118b1339a349eff
|
|
| MD5 |
32f7281b41bc7d331974df6f5a59c85a
|
|
| BLAKE2b-256 |
29c02b2028abf5294d221bf7d762c403aab19bb0d1182d290bab9e0c43db442d
|
File details
Details for the file qomputing-0.1.5-py3-none-any.whl.
File metadata
- Download URL: qomputing-0.1.5-py3-none-any.whl
- Upload date:
- Size: 30.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71a218fd934501c119c5776a429f0eba4f5c397fc9271d9b9913328b0292d32d
|
|
| MD5 |
e32b2501ae21483efdacbc78dd418d0b
|
|
| BLAKE2b-256 |
99fb146cf59fe07989271bf688437f50d157fd8e240cc3acb1f0a4be02c2e8a1
|