Introduction to Quantum Circuits
Quantum computation uses quantum bits, or qubits, to encode and process information. Qubits may exist in superpositions of the |0⟩ and |1⟩ states, and several qubits can be entangled so that measurements on one are correlated with the others. A quantum oracle can act coherently on a superposition of inputs, but measurement does not reveal all corresponding function values. Quantum algorithms instead arrange interference so that amplitudes associated with useful outcomes are enhanced while others cancel.
Quantum circuits are the framework for designing quantum algorithms. They consist of sequences of quantum gates that manipulate qubits, creating complex states and enabling computations that, for certain tasks, are infeasible for classical computers. The final step in a quantum circuit is measurement, which collapses the quantum state into a classical result.
Quantum circuits can be visualised as diagrams where qubits are represented by horizontal lines and gates are applied at discrete time steps. This visual representation helps in understanding how quantum information flows through the circuit.
This documentation introduces the fundamental ideas behind quantum circuits. It explains the role of qubits, how basic gates transform them, and how measurements extract classical results. The ideal-gate exercises marked as simulator labs can be recreated on the Quantum Simulator , which displays probabilities and reduced-state Bloch spheres after you run a circuit. Sections on configurable noise, arbitrary oracles and large composite subroutines are theoretical unless a specific QSim decomposition is provided.
For the most efficient learning workflow, begin with the Quantum Circuits simulator guide. It explains QSim’s qubit ordering, gate-target conventions, presets, shot counts, conditional measurement, result views and JSON or URL sharing. The remaining pages include focused simulator laboratories for rotations and entangling gates, measurement bases, teleportation, Grover search, the QFT and elementary error correction.
A Practical QSim Learning Path
Work through the simulator in short, testable stages rather than building a large algorithm immediately:
- Learn the interface with one qubit. Run
X,H,RX,RYandRZ, comparing probabilities with the Bloch values after every change. Use the gate laboratory. - Separate probability from sampling. Repeat one circuit at several shot counts and implement X- and Y-basis readout with pre-rotations. Use the measurement laboratory.
- Add correlations. Load Bell and GHZ presets, then build teleportation with conditional corrections. Use the entanglement laboratory.
- Study interference and recovery. Test Grover and the two-qubit QFT, then inject controlled faults into the repetition code. Use the algorithm laboratory and error-correction laboratory.
At each stage, begin from a preset or exported JSON known to work, predict the output before selecting Run, and change one variable at a time. This procedure is both faster and more reliable than diagnosing several new gates, indices and parameters simultaneously.
Qubits
A qubit is described by a two-dimensional complex vector. The basis states are written |0⟩ and |1⟩. A general single‑qubit state can be written as
Here, and are complex coefficients that represent the probability amplitudes of measuring the qubit in the |0⟩ or |1⟩ state, respectively. The condition ensures that the total probability is normalised to 1, as required by quantum mechanics.
The state can also be expressed in matrix form as
This representation allows us to manipulate qubit states using linear algebra. The state vector can be visualised on the Bloch sphere, where the north pole corresponds to |0⟩, the south pole to |1⟩, and every other point on the surface represents a superposition of the two.
Any pure single‑qubit state can be written in terms of two angles and that fix its position on the sphere:
where is the polar angle ( to ) and is the azimuthal angle ( to ). Comparing with the expression above, the amplitudes are and , so the normalisation condition is satisfied automatically.
Two real parameters suffice because an overall phase is unobservable: and produce identical statistics for every measurement. The convention above spends that freedom on making real and non‑negative, which leaves the relative phase between the two amplitudes as the only phase with physical meaning.
When a qubit is measured in the computational basis, it collapses to |0⟩ or |1⟩ with probabilities given by the squared magnitudes of the amplitudes: and . The measurement process is probabilistic, reflecting the inherent uncertainty in quantum mechanics.
Multiple qubits are represented by tensor products of individual qubit states. For two qubits the most general state is
with all amplitudes satisfying . Entangled states such as cannot be written as a product of single‑qubit states, which is exactly what makes them a resource that has no classical counterpart.
Gates
Quantum gates are unitary matrices that evolve qubit states. A single‑qubit gate is represented by a matrix that satisfies . When a gate acts on a qubit, the state is updated via . Common single‑qubit gates include the Pauli operators X, Y, Z, the Hadamard gate H, and arbitrary rotations.
A gate acting on qubits is a unitary. Applying single‑qubit gates in parallel corresponds to a tensor product such as , and such a product can never entangle qubits that started out unentangled. Some non-product unitaries, most notably the controlled‑NOT (CNOT), can create entanglement from suitable product inputs. Non-product alone is not sufficient: SWAP, for example, is not a tensor product of single-qubit gates but maps every product state to another product state. The Quantum Gates page provides an in-depth description of each gate and its matrix representation.
Quantum gates can be visualised as rotations on the Bloch sphere. For example, the Hadamard gate transforms the state |0⟩ to , moving it from the north pole to the equator, while the Pauli gates correspond to half‑turns about the X, Y and Z axes.
Circuits
A quantum circuit is a sequence of gates acting on a set of qubits. The state of the qubits is transformed step by step until a measurement is performed. By arranging gates carefully we can build algorithms that outperform their classical counterparts on certain tasks. See the Quantum Circuits page for detailed examples and a walkthrough of building circuits on the Quantum Simulator.
Measurement
Measurement is the one step of a basic gate-model circuit that is neither unitary nor reversible, and it is where amplitudes determine the probabilities of classical outcomes. The Measurement and Mixed States page covers the Born rule, how to measure along axes other than Z, and density matrices, which describe mixed states and subsystems of entangled states.
Entanglement
Entangled qubits can produce correlations that no local hidden-variable model can reproduce. Entanglement and Protocols catalogues the Bell states, explains why universal perfect cloning is impossible, and works through quantum teleportation, superdense coding and the Bell test.
Algorithms
Quantum algorithms combine gates and measurements in specific patterns. Famous examples include Grover’s search, Shor’s factoring algorithm and variational algorithms used for chemistry and optimisation. An overview of these algorithms can be found in the Quantum Algorithms section.
Error Correction
Present-day physical qubits are too noisy to run many large fault-tolerant algorithms directly. Quantum Error Correction shows how information is spread across physical qubits so that faults can be diagnosed through syndrome measurements without directly measuring the encoded data.
This site aims to give an accessible introduction without tying the mathematics to one software framework. QSim is an educational state-vector and measurement-branch simulator, so it is excellent for inspecting ideal circuits and controlled experiments. A successful small browser simulation is not by itself evidence of hardware noise tolerance or computational speedup. Export the circuit JSON, state the initial ket and shot count, and record the expected outputs whenever an experiment needs to be reproducible.