Swift · Metal · Apple silicon
Quantum circuits that run in your app process.
Statevector and density-matrix engines on the GPU, CPU when there is no Metal. No Python. No cloud backend. Version 1.0.0.
QuantumKit
Install
macOS 13+, iOS 16+. Xcode: File → Add Package Dependencies… → the URL below.
dependencies: [
.package(url: "https://github.com/acemoglu/QuantumKit.git", from: "1.0.0")
]
import QuantumKit
var circuit = try QuantumCircuit(qubitCount: 2)
try circuit.h(0)
try circuit.cx(0, 1)
try circuit.measure(0)
try circuit.measure(1)
let backend = try QuantumBackendFactory.makeRecommended(circuit: circuit)
let result = try backend.run(
circuit: circuit,
options: QuantumRunOptions(seed: 1, shots: 1024)
)
print(result.bitstringCounts ?? [:])
Until a 1.0.0 git tag exists, add the package from main.
How it picks a path
QuantumBackendFactory.makeRecommended uses Metal when a GPU is there, otherwise CPU.
Noiseless circuits with trailing measurements evolve once, then sample — time follows width and gates, not shot count.
OpenQASM 2 and a core OpenQASM 3 subset import into the same IR.
Width limits
| Path | Max qubits |
|---|---|
| Metal statevector | 31 |
| CPU statevector | 16 |
| Metal density matrix | 14 |
| CPU density matrix | 8 |
n = 30 is about 8 GB of amplitude buffers. Metal engines use Float32 and renormalize every 50 gates by default. First Metal run at a width compiles shaders — time the next one.
The app
Visual circuit editor for Mac, iPhone, and iPad. Drag gates onto wires or write OpenQASM, then run locally on this library. No account, login, or network is required.
- Open Samples
- Select Bell State (or any other sample)
- Tap or click Run. A measurement histogram should appear (for Bell, roughly 00 and 11).
You can also write OpenQASM in the Code tab, or build a circuit on the Circuit canvas (tap a gate, then a qubit), then Run.