quantro-js · API Reference

Quantum Circuit Simulator for JavaScript

A clean-room, zero-dependency state-vector quantum circuit simulator, written in pure JavaScript. Runs in the browser via plain <script> or in Node.js via require(). MIT licensed.

→ Live interactive demo (Lab) · npm · source

Install

npm install quantro-js

 — or load straight from unpkg in any page:

<script src="https://unpkg.com/quantro-js"></script>

Quick start — a Bell pair

Two qubits, an H gate and a CNOT: that is entanglement. This is a real, reproducible run (seed 42):

const { QuantumCircuit, bellState, sampleDistribution } = require('quantro-js');

const qc = new QuantumCircuit(2);
bellState(qc);                     // |00> + |11>

console.log(qc.probabilities());
// [ 0.4999999999999999, 0, 0, 0.4999999999999999 ]

const counts = sampleDistribution(qc, 1024, 42);
console.log(counts);
// { 0: 494, 3: 530 }            → measured half in |00>, half in |11>

GHZ three-qubit state

Gates chain, and every method returns the circuit:

const qc = new QuantumCircuit(3);
qc.h(0).cx(0, 1).cx(0, 2);         // GHZ state  (|000> + |111>) / √2

console.log(qc.probabilities());
// [ 0.4999999999999999, 0, 0, 0, 0, 0, 0, 0.4999999999999999 ]

Single measurement

const qc = new QuantumCircuit(1);
qc.h(0);                            // superposition

qc.measureAll(() => 0.1);           // → 0
qc.measureAll(() => 0.9);           // → 1

API reference

APIDescription
new QuantumCircuit(n)n-qubit circuit (1 ≤ n ≤ 12, full 2ⁿ state vector)
.h(q) · .x(q) · .y(q) · .z(q)single-qubit gates (chainable)
.ry(theta, q)rotation around Y by theta radians
.cx(c, t) · .cz(c, t)controlled-X / controlled-Z (entanglement gates)
.probabilities()measurement probability distribution over the 2ⁿ basis states
.measureAll(rng)one sampled measurement (integer); rng = () => [0,1)
bellState(qc)prepare |00> + |11> (Bell pair)
ghzState(qc, qubits)prepare |0…0> + |1…1> (GHZ)
sampleDistribution(qc, shots[, seed])sample counts; seeded → fully reproducible
mulberry32(seed)seeded PRNG generator
H · X · Y · Z · I2gate matrices (complex-array form)

Why it exists

quantro-js is the engine behind this site's 13 interactive tools. It was written from scratch as a community critique of the assumption that "quantum computing needs big frameworks": the whole simulator fits in one MIT-licensed, dependency-free JavaScript file, and it is deliberately kept humble and inspectable so that anyone — student, developer, researcher — can read, run and extend it.

Companion project: ZENAI (4 brains)

The same author maintains ZENAI — a Turkish, local-first AI assistant built on a two-tier brain setup (a local Ollama 7B/14B code model + a cloud "mega brain"), with a four-brain deliberation layer: majority vote, a 12-criteria jury referee, verification, and self-correction. The badge below tracks its repository automatically, so what you see always reflects the latest upstream commit.

ZENAI · …