Quantum computing in JavaScript · npm i @kirkelliott/ket · zero dependencies · 1,308 tests
QAOA Max-Cut — Quantum Optimization
A 4-cycle graph has two optimal bipartitions: {0,2} vs {1,3} and {1,3} vs {0,2}, each cutting all 4 edges.
QAOA p=1 finds them — the two dominant peaks are the correct answers.
Self-contained SVG string — no external fonts or stylesheets. Same column layout as draw(). Embed directly in HTML, save to a file, or use in notebooks.
new Circuit(2).h(0).cnot(0, 1).toSVG()
// → self-contained SVG string
300×300 SVG for a single qubit's state using cavalier projection. Partial-traces over all other qubits — works on any circuit, including entangled states.
|0⟩
ground state
|+⟩
H gate
|1⟩
X gate
|−⟩
H · Z
|+i⟩
H · S
|T⟩
H · T
Grover's Search — Hardware Fidelity
The same 3-qubit Grover circuit (target: |101⟩) run across six backends with 4,096 shots each.
Lower gate error rates preserve the quadratic amplitude advantage.
All results use published device noise models — not real hardware runs.
Circuit toSVG()
Ideal
Statevector · no noise
94.53%
P(|101⟩) — target state
BEST
IonQ Forte-1
Trapped-Ion · 36 qubits
93.90%
P(|101⟩) — target state
IonQ Aria-1
Trapped-Ion · 25 qubits
93.04%
P(|101⟩) — target state
IonQ Harmony
Trapped-Ion · 11 qubits
90.06%
P(|101⟩) — target state
IBM Torino
Superconducting · 133 qubits
91.72%
P(|101⟩) — target state
IBM Sherbrooke
Superconducting · 127 qubits
90.72%
P(|101⟩) — target state
1,024-Qubit GHZ State CliffordSim
Stabilizer Tableau Heatmap Gottesman-Knill
A 1,024-qubit GHZ state built with one H gate + 1,023 CNOTs.
Classically infeasible with statevector simulation (21024 amplitudes),
but the Gottesman-Knill theorem lets us track it exactly in O(n²) space.
Each row is a stabilizer generator; each column is a qubit.
Row 0 (bright stripe): X⊗¹⁰²⁴ — all 1,024 qubits correlated via X. ·
Rows 1–1023 (diagonal): ZZ at adjacent qubit positions.
The trajectory-MPS backend simulates noisy circuits at 127+ qubits by representing the quantum state
as a product of rank-3 tensors. Bond dimension χ tracks entanglement, not qubit count —
a 127-qubit GHZ state maintains χ = 2 throughout, making it as cheap as a 3-qubit simulation.
Noisy trajectories are embarrassingly parallel: pass workers: N for N× speedup.
GHZ Fidelity vs Qubit Count noise model
P(|00…0⟩ + |11…1⟩) for an n-qubit GHZ state under depolarizing noise.
Bond dimension stays at χ = 2 for all n — fidelity decays from gate errors only, not simulation approximation.
IBM Sherbrooke: p₂ = 7.4 × 10⁻³IonQ Forte-1: p₂ ≈ 10⁻³Model: depolarizing channel · gate errors only
127-Qubit IBM Sherbrooke χ = 2
Statevector simulation of a 127-qubit circuit would require
2127 complex amplitudes — roughly 1020× more RAM than all data ever created.
MPS stores O(n · χ²) numbers — linear in qubit count.
import { Circuit, DEVICES } from '@kirkelliott/ket'
let c = new Circuit(127).h(0)
for (let i = 0; i < 126; i++) c = c.cnot(i, i+1)
const result = c.runMps({
shots: 256,
seed: 42,
noise: DEVICES['ibm_sherbrooke'].noise,
})
// → { '000…0': 2.3%, '111…1': 2.1%, … }
127
qubits · noisy · χ = 2
O(n)
memory — not O(2ⁿ)
Scalability — GHZ with Noise
256 shots, IBM Sherbrooke noise model, single-threaded. Time scales linearly with n because χ = 2 throughout the GHZ circuit.
Qubits
Time
χ
Statevector RAM
10
4ms
2
16 KB
20
7ms
2
16 MB
50
17ms
2
>16 PB
100
33ms
2
> universe
127
41ms
2
> universe
Multi-Core Speedup
Each noisy trajectory is an independent simulation — distribute across OS threads with workers: N. Requires built bundle and Node.js ≥ 22.
Von Neumann entropy S(b) at each bond cut — the entanglement structure of a quantum state at a glance.
Different circuits leave distinct fingerprints: GHZ saturates every bond, Bell pairs show sharp on/off alternation,
brickwork builds bulk entanglement peaked in the middle.
GHZ(8)
Maximum entanglement — every bond saturated at S = 1
Bond entropies of the optimized ground state — the area-law profile confirms the Heisenberg chain has limited entanglement, making MPS the ideal representation.