q is a quantum circuit simulator written entirely in Go. It uses only the Go standard library — no C bindings, no external packages — so it compiles and runs anywhere Go does.
You can allocate qubits, apply standard gates, build controlled operations, run the Quantum Fourier Transform, measure states, and model noise with density matrices and quantum channels, all through a clean chainable API.
q has zero external dependencies. The entire simulator is built on the Go standard library alone. Go 1.23 or later is required.Key capabilities
Qubit creation
Allocate qubits in the |0⟩ or |1⟩ state, or with arbitrary complex amplitudes using
qsim.New(...). Amplitudes are normalized automatically.Standard quantum gates
Apply H, X, Y, Z, S, T, R, RX, RY, RZ, U, and identity gates. All single-qubit gates accept multiple qubit targets in one call.
Controlled operations
Use CNOT, CCNOT, CCCNOT, CZ, CR, and arbitrary controlled unitaries via
C() and Controlled(). Apply gates conditionally with CondX() and CondZ().Quantum Fourier Transform
Built-in
QFT() and InvQFT() operate on any subset of qubits, enabling phase estimation and Shor’s algorithm.Measurement
Measure() collapses the quantum state probabilistically and returns the measured value. Measure individual qubits or the full register at once.Density matrices & noise
Model open quantum systems using density matrix representations and quantum noise channels including bit flip, phase flip, depolarizing, and amplitude damping.
Resources
| Resource | Link |
|---|---|
| Go package reference | pkg.go.dev/github.com/itsubaki/q |
| Source code | github.com/itsubaki/q |
| License | MIT |
Version note
Versions v1.0.0 through v1.1.11 are retracted due to breaking compatibility changes. Always install the latest version:go.mod retract directive prevents go get from selecting any retracted version automatically.