open source · python · numpy · mit

twenty qubits. one laptop. no magic.

a quantum circuit simulator written in numpy. state vector up to 24 qubits on 32gb of ram (past that, the array stops fitting). standard gate set, measurement, entanglement, noise models. shor factors 15 into 3 × 5. grover finds a marked item in √n calls. nothing imported from qiskit or cirq.

|ψ⟩ = α|0⟩ + β|1⟩  ·  |Φ⁺⟩ = (|00⟩ + |11⟩)/√2  ·  U = H ⊗ I
>>> circuit = Circuit(2)
>>> circuit.h(0); circuit.cx(0, 1)

   ┌───┐     ┌───┐
q₀ ┤ H ├──■──┤ X ├──● ──
   └───┘  │  └───┘  │
          │         │
q₁ ──────┤X├───────┤X├──
         └─┘       └─┘

>>> circuit.run(shots=1024)
   ┌─────┬──────┬──────┐
   │ 00  │  01  │  11  │
   │ 512 │   0  │  512 │
   └─────┴──────┴──────┘
   bell state prepared. perfect correlation.
|Φ⁺⟩ on two qubits, 1024 shots, no noise
a small experiment

shor's algorithm, narrated.

$ qubit run examples/shor.py --n 15

  [stage 1] pick random a = 7, gcd(7, 15) = 1  ok
  [stage 2] build modular exponentiation oracle
             ancilla register: 8 qubits · work register: 4 qubits
  [stage 3] apply qft to ancilla, measure
             peaks at 0, 64, 128, 192 → period r = 4
  [stage 4] gcd(7^(4/2) ± 1, 15) = gcd(48, 15), gcd(50, 15)
             → 3, 5

  factored in ~4.2s on m2 air (12 qubits allocated).
what's inside

linear algebra, carefully arranged.

state vector simulator

up to 24 qubits on 32gb of ram. sparse tensor contractions for commuting gates. kronecker products only when they earn it.

the standard gate set

h, x, y, z, s, t, cnot, cz, swap, toffoli, plus parameterised rotations and arbitrary unitaries if you bring a matrix.

noise channels

depolarizing, amplitude-damping, phase-flip. a real qubit decoheres; the moment you pretend it doesn't, you're studying a different problem.

shor's algorithm

factors semiprimes up to 15-bit in practice. modular exponentiation oracle, qft on the ancilla, continued-fraction post-processing. the whole pipeline, no shortcuts.

grover's search

over any boolean oracle you can write as a circuit. up to an 18-qubit problem space. amplitude amplification with the correct number of iterations, no more.

install

not public yet.

source drops on github soon. python 3.10+, numpy 1.24+ when it ships. email bennett@frkhd.com if you want a preview.

quantum is linear algebra on a bigger space.