Quantum state-vector simulator for Apple Silicon
Project description
macquerel
A quantum state-vector simulator targeting Apple Silicon's unified-memory architecture.
Features
- CPU backend — pure NumPy reference implementation using the tensordot reshape trick
- MLX backend — Apple Silicon GPU acceleration via MLX, with graceful fallback on other platforms
- Gate fusion compiler — greedy left-to-right fusion of adjacent gates (up to 4 qubits) into composite unitaries
- Gate classification — automatically classifies gates as
diagonal,permutation, ordensefor optimized dispatch - Full gate library — I, H, X, Y, Z, S, T, Rx, Ry, Rz, P, CNOT, CZ, SWAP, CP
Installation
Requires Python 3.11+.
uv sync
To enable the MLX backend on Apple Silicon:
uv sync --extra mlx
Usage
from macquerel import Circuit, Simulator
# Bell state
circuit = Circuit(2)
circuit.h(0).cx(0, 1).measure_all()
sim = Simulator() # defaults to CPU backend
counts = sim.run(circuit, shots=1000)
print(counts) # Counter({'00': ~500, '11': ~500})
# Statevector (no measurement)
circuit = Circuit(2)
circuit.h(0).cx(0, 1)
sv = sim.statevector(circuit)
print(sv) # [0.707+0j, 0+0j, 0+0j, 0.707+0j]
# Apple Silicon GPU backend
sim = Simulator(backend="mlx")
Available gates
| Method | Gate |
|---|---|
.h(q) |
Hadamard |
.x(q) / .y(q) / .z(q) |
Pauli X/Y/Z |
.s(q) / .t(q) |
S / T phase |
.rx(q, θ) / .ry(q, θ) / .rz(q, θ) |
Rotation gates |
.p(q, λ) |
Phase gate |
.cx(ctrl, tgt) |
CNOT |
.cz(ctrl, tgt) |
Controlled-Z |
.swap(q0, q1) |
SWAP |
.cp(ctrl, tgt, λ) |
Controlled-Phase |
.measure(qubits) / .measure_all() |
Measurement |
Builders return self for chaining.
Architecture
macquerel/
├── gates.py # Gate matrices + classify()
├── circuit.py # Circuit / Gate / MeasureOp dataclasses
├── compiler.py # Gate fusion (fuse_gates)
├── simulator.py # Simulator — statevector() and run()
└── backends/
├── cpu.py # NumPy backend
└── mlx_backend.py # MLX backend (Apple Silicon)
Running tests
uv run pytest
MLX backend tests are automatically skipped when MLX is not installed.
Benchmarks
Quick smoke run (completes in a few seconds):
uv run python tests/benchmarks/bench_backends.py --qubits 10 14 --reps 1
Full benchmarks (may take several minutes at 24+ qubits):
# CPU vs MLX backend — random circuits, various qubit counts
uv run python tests/benchmarks/bench_backends.py
# Single-gate throughput (GB/s)
uv run python benchmarks/bench_single_gate.py
# QFT, random, QAOA circuits + fusion-width sweep
uv run python benchmarks/bench_circuits.py
All scripts print results live as each configuration completes. Pass --json FILE to save results for later comparison.
Requirements
- Python ≥ 3.11
- numpy ≥ 1.24
- mlx ≥ 0.3.0 (optional, Apple Silicon only)
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 macquerel-0.2.0.tar.gz.
File metadata
- Download URL: macquerel-0.2.0.tar.gz
- Upload date:
- Size: 2.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
306e3a976f223348756c4bf616629319040b3ba3f2db1c7518f1c49bf9b7f9e7
|
|
| MD5 |
64cf3ec16352418d5b409a3fbf2ac4c0
|
|
| BLAKE2b-256 |
4bb8e515c4668bc82a6d6f175d989c4512edd51f3ffd369f0612d30046339310
|
Provenance
The following attestation bundles were made for macquerel-0.2.0.tar.gz:
Publisher:
release.yml on guenp/macquerel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
macquerel-0.2.0.tar.gz -
Subject digest:
306e3a976f223348756c4bf616629319040b3ba3f2db1c7518f1c49bf9b7f9e7 - Sigstore transparency entry: 1739960900
- Sigstore integration time:
-
Permalink:
guenp/macquerel@770215620e68be55fdb39fe02e2b00e91d480ff6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/guenp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@770215620e68be55fdb39fe02e2b00e91d480ff6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file macquerel-0.2.0-py3-none-any.whl.
File metadata
- Download URL: macquerel-0.2.0-py3-none-any.whl
- Upload date:
- Size: 28.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91db44bd0343c85ea5a68d06d61b5887eb65aa055b9f0eed9dece987016acb18
|
|
| MD5 |
8d5aa49ae340b54b3daf25eda8d13707
|
|
| BLAKE2b-256 |
53477823e75ac3040b8d6fc8c5fb1fa4761ae0bfe52bbdc630bdf5769c1a1ec5
|
Provenance
The following attestation bundles were made for macquerel-0.2.0-py3-none-any.whl:
Publisher:
release.yml on guenp/macquerel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
macquerel-0.2.0-py3-none-any.whl -
Subject digest:
91db44bd0343c85ea5a68d06d61b5887eb65aa055b9f0eed9dece987016acb18 - Sigstore transparency entry: 1739960917
- Sigstore integration time:
-
Permalink:
guenp/macquerel@770215620e68be55fdb39fe02e2b00e91d480ff6 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/guenp
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@770215620e68be55fdb39fe02e2b00e91d480ff6 -
Trigger Event:
push
-
Statement type: