Overview
Curated: · Written: · Reviewed:
Quantum Gates & the Circuit Model
In one line
A circuit is an ordered list of unitary gates on qubits, ending in measurements. Reach for it whenever you must state what a small program outputs, and name the conventions (qubit order, matrix order, global phase, control and target) that make that output correct.
Key definitions
- Unitary: $U^\dagger U = I$. It preserves inner products and total probability, so every ideal gate is reversible.
- Global phase: a factor $e^{i\alpha}$ on the whole state. It is unobservable alone and becomes observable once the gate is controlled.
- Clifford group: generated by H, S and CNOT. Clifford circuits are efficiently simulable (Gottesman-Knill).
- Native gate set: the instructions a backend runs directly. Everything else is decomposed into them.
- Routing: inserting SWAPs so every two-qubit gate acts on a physically coupled pair.
- Mid-circuit measurement: non-unitary. It collapses the qubit and can drive classical control.
Formulas and complexity
SWAP costs three CNOTs. A standard Toffoli uses six CNOTs plus single-qubit gates. On a line of $n$ qubits, a CNOT between qubits at distance $d$ needs $d-1$ SWAPs.
How it works
Gates are applied in diagram order (left to right in time), but matrices multiply right to left, so $U = G_n \cdots G_2 G_1$. Each gate acts on the state produced by the one before it.
- Bell state: H on q0 gives (|00⟩+|10⟩)/√2. CNOT(q0,q1) sends |10⟩ to |11⟩, giving (|00⟩+|11⟩)/√2.
- Qiskit puts q0 at the least significant bit, so the amplitude of |q1 q0⟩ = |10⟩ sits at index 2. State the convention before reading any index.
- A Z-basis measurement is blind to Z, S and T. Those gates only show up after a basis change.
When to use and when not to
| Situation | Answer | Why |
|---|---|---|
| Exact output of a few-qubit circuit | Compute amplitudes by hand or statevector | Exact and cheap at small n |
| Clifford-only circuit, many qubits | Stabilizer simulator | Polynomial in qubit count |
| Circuit with T gates, large n | Statevector, cost grows as 2^n | T is non-Clifford, no shortcut |
| Equality of two small rewrites | Full unitary comparison, including phase | Catches phase errors in controlled use |
| Equality of two large rewrites | Inverse composition on random inputs, or sampling | Never materializes the unitary |
Traps interviewers probe
- Treating X as a phase multiply. X must swap the two amplitudes. Multiplying both by one phase leaves |0⟩ unchanged. Fix: assert the amplitude vector, not just measurement counts.
- Calling Y a phased X. Y|0⟩ = i|1⟩ and Y|1⟩ = -i|0⟩ carry relative signs that X does not. Fix: write the action on both basis states.
- Dropping the global phase on a block that will be controlled. Controlled-(-U) equals controlled-U followed by Z on the control. Fix: record the phase and test the block in controlled form.
- Reading X-basis results without the final H. Z before measurement does not change Z counts. For |+⟩, then Z, then H, then Z-measure, all 1000 shots read 1. Fix: apply H before a Z-basis readout to measure in the X basis.
- Quoting abstract gate counts. A SWAP costs three CNOTs, and routing on a line adds them quickly. Fix: report the transpiled two-qubit count and layout next to the abstract count.
Interview tips
Open by fixing the conventions: qubit order, control and target, and matrix order. Then trace the state in amplitudes, one gate at a time.
Expect these follow-ups:
- Why CZ is symmetric and CNOT is not.
- Why T costs more than CNOT in fault-tolerant compilation (magic-state distillation).
- How many SWAPs a distance-d CNOT needs on a line.
- How you would verify a rewrite of a 20-qubit circuit.
30-second outline: pin the conventions. H gives an equal superposition, and CNOT correlates the qubits. Measurement gives 00 and 11 at 50 percent each. On hardware, CNOT is the expensive gate, routing adds three CNOTs per SWAP, and equivalence is checked by comparing unitaries with phase, or by sampling on asymmetric inputs.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.