Skip to main content
Simulate quantum computation in Go with a clean, chainable API. Build circuits from individual qubits and gates, run canonical quantum algorithms, and study quantum noise and error correction — all using only the Go standard library.

Quickstart

Install the library and run your first quantum circuit in minutes.

Core Concepts

Understand qubits, gates, superposition, entanglement, and measurement.

Algorithm Guides

Step-by-step walkthroughs of Bell states, teleportation, Grover, and Shor.

API Reference

Complete reference for the simulator, gates, qubits, and quantum channels.

Get started in three steps

1

Install the package

Add q to your Go module.
go get github.com/itsubaki/q
2

Create a simulator and qubits

Instantiate the simulator and allocate qubits in the |0⟩ state.
import "github.com/itsubaki/q"

qsim := q.New()
q0 := qsim.Zero()
q1 := qsim.Zero()
3

Apply gates and measure

Build a Bell state with a Hadamard and CNOT gate, then read the output.
qsim.H(q0)
qsim.CNOT(q0, q1)

for _, s := range qsim.State() {
    fmt.Println(s)
}
// [00][  0]( 0.7071 0.0000i): 0.5000
// [11][  3]( 0.7071 0.0000i): 0.5000

What you can simulate

Standard quantum gates

H, X, Y, Z, S, T, R, RX, RY, RZ, and the universal U gate — all with multi-qubit support.

Controlled operations

CNOT, CCNOT, CCCNOT, CZ, CR, and arbitrary controlled unitaries via C() and Controlled().

Quantum Fourier Transform

Built-in QFT and InvQFT for use in phase estimation and factoring algorithms.

Density matrices & noise

Model open quantum systems with bit flip, phase flip, depolarizing, and amplitude damping channels.
q requires Go 1.23 or later and has zero external dependencies — it relies exclusively on the Go standard library.

Build docs developers (and LLMs) love