Quantum Gates
Quantum gates are reversible transformations applied to qubits. Mathematically they are represented by unitary matrices, which preserve the norm and therefore the total probability of a quantum state. Gates may act on a single qubit or on multiple qubits simultaneously. The Quantum Simulator implements most operations below directly; the notes identify equivalent parameterized gates when there is no separate button.
These are the fundamental building blocks of quantum circuits, allowing us to manipulate qubits and create complex quantum states. Each gate corresponds to a unitary operation that transforms the state of one or more qubits. The following sections describe common single‑qubit and multi‑qubit gates, their matrix representations, and their effects on qubit states.
Single-Qubit Gates
| Gate | Matrix | Description |
|---|---|---|
| X | Bit flip analogous to the classical NOT. Rotates the Bloch vector by about the X‑axis. | |
| Y | Combined bit and phase flip. Rotates by about the Y‑axis. | |
| Z | Phase flip. Rotates by about the Z‑axis, negating the amplitude of . | |
| H | Creates superposition. A rotation about the diagonal axis , which exchanges the X‑ and Z‑axes of the sphere. | |
| S | Adds relative phase ; equivalent up to global phase to a rotation about Z. Satisfies . | |
| T | Adds relative phase ; equivalent up to global phase to a rotation about Z. Satisfies . |
Each of these gates is a rotation of the Bloch sphere by a fixed angle about a fixed axis. Useful identities to keep in mind are , , and .
QSim has no separate S or T button. Use RZ with angle for S or for T; each implementation differs from the named phase gate only by an unobservable global phase.
Rotation gates provide arbitrary rotations around the Bloch sphere axes:
These gates rotate the Bloch vector by an angle around the specified axis. For example, flips the qubit state (it equals , which differs from X only by an unobservable global phase), while maps |0⟩ to the equal superposition .
Expanding for a Pauli matrix gives the explicit matrices:
is diagonal because it only adds a relative phase between |0⟩ and |1⟩; it does not change computational-basis probabilities when applied immediately before measurement. It is closely related to the phase gate , since . The two differ only by a global phase. With this convention and .
The Hadamard gate is particularly important because it turns a basis state into a superposition, which is how a register is spread over all inputs at the start of an algorithm. It rotates the state vector from the north pole (representing |0⟩) to the equator, and applying it a second time brings the qubit back to |0⟩: the two routes to |1⟩ arrive with opposite signs and cancel. That cancellation is interference in its simplest form, and it is why .
The single‑qubit gates listed above can be combined to create more complex operations. For example, the Hadamard gate H can be built from rotations about the Y and Z axes:
The leading factor is a global phase, so on hardware H and are indistinguishable. Note that the rightmost factor is applied first, matching the order in which the gates appear on a circuit diagram read left to right.
Any single‑qubit unitary can be decomposed into a sequence of these rotations. A convenient form uses Euler angles
where the global phase has no observable effect. This decomposition underlies many quantum compilation techniques.
Single‑qubit gates act on one qubit line at a time, so no sequence of them can create entanglement from a product state. Creating entanglement requires a suitable interaction between qubits, such as a CNOT applied to a control in superposition. The Quantum Simulator lets you place single-qubit gates on any line, run the circuit and inspect the resulting Bloch vector.
Multi-Qubit Gates
- CNOT: Flips the target qubit when the control qubit is
|1⟩in the computational basis. - CZ: Multiplies the
|11⟩basis component by . - Swap: Exchanges the states of two qubits.
- Toffoli (CCNOT): A two‑control CNOT; Toffoli gates together with suitable ancillas can implement arbitrary classical reversible computation.
- Controlled‑Phase: Multiplies the
|11⟩component by a specified phase in the two-qubit case; multiply controlled versions phase the all-ones component.
QSim exposes controlled phase as CP. Setting its angle to implements CZ exactly, so a separate CZ button is unnecessary.
Multi‑qubit gates operate jointly on two or more qubits. Some, including CNOT and CZ, can generate entanglement from suitable product inputs; others, such as SWAP, cannot. A gate on qubits is a unitary acting on the joint state. An entangling gate maps at least one product input to an entangled output. Every entangling gate is non-product, but not every non-product gate is entangling.
Ordering the two‑qubit basis as with qubit 0 as the leftmost (most significant) bit, the common two‑qubit gates are:
The matrix written for CNOT above takes qubit 0 as the control and qubit 1 as the target. Swapping those roles gives a different matrix,
so the wiring matters. CZ and the standard two-qubit controlled‑phase gates are symmetric, so it makes no difference which qubit is labelled the control. CZ and CNOT are related by for the CNOT convention above. Three alternating CNOTs make a swap: .
Single‑qubit rotations together with the CNOT gate form a universal gate set. That means any unitary acting on a collection of qubits can be approximated to arbitrary precision using only these primitives. The Quantum Simulator allows you to place multi‑qubit gates across different lines to observe how entanglement forms.
Example: Bell State
A simple circuit that demonstrates entanglement uses a Hadamard gate followed by a CNOT:
- Apply
Hto qubit 0, creating on that line, so the two‑qubit state is . - Use qubit 0 as the control of a CNOT acting on qubit 1, which flips qubit 1 only in the branch.
The resulting two‑qubit state is
This state cannot be written as a product of two single‑qubit states. Tracing out either qubit leaves the other in the maximally mixed state , rather than a pure superposition. Each qubit on its own yields an unbiased bit when measured in any direction. Its reduced-state Bloch vector is at the origin, while the joint state retains the correlations of .
When qubit 0 is measured it yields |0⟩ or |1⟩ with probability each, and the two‑qubit state collapses so that qubit 1 must give the matching result: measuring |0⟩ leaves qubit 1 in |0⟩, and measuring |1⟩ leaves it in |1⟩. The outcomes are perfectly correlated, yet each on its own is completely random.
Perfect correlation in the computational basis alone is not proof of entanglement; a shared random bit reproduces it. For , the expectation values are and . Suitable tilted measurement axes give the CHSH value , exceeding the bound of obeyed by local hidden-variable models. Bell-state entanglement is also the resource used by quantum teleportation and superdense coding.
Try running the preparation first with only the Hadamard, then add the CNOT and run it again. After the CNOT, both reduced-state Bloch vectors vanish. For the known pure two-qubit state prepared here, those mixed marginals certify entanglement; a zero local Bloch vector by itself would not certify an arbitrary joint state as entangled.
Simulator Lab: Learn Gates by Controlled Comparison
The fastest way to understand a gate in the Quantum Simulator is to compare inputs that isolate its different effects.
QSim gate-entry reference
The target list is ordered, and QSim uses the first selected target as local bit 0 of a multi-qubit matrix. The interface enforces the following arities:
| Builder button | JSON gateName | Targets | Extra input |
|---|---|---|---|
H | Hadamard | 1 | none |
X | PauliX | 1 | none |
Y | PauliY | 1 | none |
Z | PauliZ | 1 | none |
RX, RY, RZ | same as button | 1 | angle in radians |
CNOT | CNOT | 2 | first target is control |
Swap | Swap | 2 | target order has no physical effect |
Toffoli | Toffoli | 3 | first two targets are controls, third is target |
CP | ControlledPhaseShift | 2 | angle in radians |
Oracle | Oracle | one or more | marked local basis-state integer |
Diffusion | Diffusion | one or more | none |
This table is especially useful when reviewing exported JSON, but use the builder to create the initial file. The interface checks target count, distinct indices and range before adding an operation, while hand-edited files make those mistakes easier to introduce.
Single-qubit rotations
Use one qubit and start in |0⟩:
- Add
RYonq0with angle and run. The probabilities should be , and the Bloch vector should point along . - Reset and add
RXwith the same angle. The Z-basis probabilities are again equal, but the vector points along . This demonstrates why probabilities in one basis do not determine a state. - Add
RZafterRYand vary its angle. The Z-basis probabilities remain unchanged while the Bloch vector moves around the equator. Exporting results only in the computational basis would miss this phase change, whereas the Bloch view exposes it.
Angles in the gate-entry field are always radians. The Angles selector in the Bloch section changes only how displayed and values are formatted; it does not change the units accepted by RX, RY, RZ or controlled phase.
Control and target ordering
Use two qubits and set the initial basis state to integer 2, displayed as |10⟩. Add CNOT with targets 0,1 and run, then reset and repeat with 1,0. The results differ because the first index is the control. Always hover the completed circuit column and verify which line has the control dot before building on it.
Global phase versus relative phase
Run these two one-qubit circuits from |0⟩:
H,Z,HX
Both produce |1⟩, consistent with . Next compare RX with angle against X. Both have the same probabilities and Bloch vector because they differ only by the global factor . The simulator correctly has no observable that distinguishes those two output rays.
An efficient entanglement check
Load the Bell (2) preset and run it. Confirm all of the following rather than relying on one picture:
- only
|00⟩and|11⟩have nonzero probability; - each has probability ;
- each local Bloch radius is zero;
- increasing Shots makes the two sampled counts approach equal values but does not force them to be exactly equal.
Then remove the CNOT and rerun. The outcome probabilities remain split between two basis states, but the second qubit is no longer correlated with the first. This comparison separates mere local superposition from entanglement.