Prerequisites
You need Go 1.23 or later. Check your installed version:If you need to install or upgrade Go, see go.dev/dl.
Install
Add No additional setup is required. The library has zero external dependencies.
q to your Go module:Bell state
A Bell state is the simplest example of quantum entanglement. Two qubits start in |0⟩|0⟩, a Hadamard gate puts the first qubit into superposition, and a CNOT gate entangles both qubits together.Reading the output: Before measurement,
qsim.State() shows two lines — [00] and [11] each with probability 0.5000. This is the superposition: the system is in both states simultaneously. After calling Measure(), the state collapses to exactly one outcome. Because the qubits are entangled, m0 and m1 are always equal — measuring one instantly determines the other.Each state line has the format [binary][index](real imaginary i): probability.Quantum teleportation
Quantum teleportation transfers an unknown quantum state from one qubit to another using entanglement and classical communication. Alice holds The state printed for
phi (the state to teleport) and q0. Bob holds q1. After the protocol, q1 holds an exact copy of the original phi state.q1 at the end is identical to the original phi state: amplitude 0.4472 for |0⟩ (probability 0.2) and 0.8944 for |1⟩ (probability 0.8). The state was teleported successfully.qsim.State(phi) accepts one or more qubit arguments to show the reduced state of a specific register rather than the full system.