B1045 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

B10 · Lesson 45 · Quantum gates and circuits

Building computations from one- and two-qubit operations

Lesson 26 turned a qubit with a timed microwave pulse: a single-qubit gate. Lesson 44 showed that two qubits can share an entangled state with no classical counterpart. A quantum computer is built from just these pieces: single-qubit rotations and one two-qubit gate that can entangle, arranged in a circuit and followed by measurement. This lesson writes the gates as matrices, builds an entangled pair from scratch, runs a small algorithm that beats any classical one, and counts what errors cost, which is why a superconducting processor's gate fidelity is quoted to three or four nines.

  • A circuit of N gates, each succeeding with fidelity F, gives the right answer with probability about FN. The curve shows that against N.
  • At 99% per gate, a hundred gates leave a 37% chance of success; at 99.9%, 90%. Deep circuits need either much better gates or error correction.

Predict

A Hadamard gate takes |0⟩ to (|0⟩+|1⟩)/2. What does a second Hadamard do to that state?

Name it

Single-qubit gates

With |0⟩=(10) and |1⟩=(01), gates are 2×2 unitary matrices:

X=[0110]Z=[100−1]H=12[111−1]Rz(ϕ)=[100ejϕ]

X flips (a NOT gate), Z flips the phase, H makes equal superpositions, and Rz turns the phase. On hardware each is a calibrated pulse, a rotation on lesson 26's Bloch sphere.

Two qubits and the CNOT

Two qubits live in a four-dimensional space with basis |00⟩,|01⟩,|10⟩,|11⟩ (first qubit first). The controlled-NOT flips the second qubit when the first is 1:

CNOT=[1000010000010010]

A gate on one qubit alone is a Kronecker product with the identity: H on the first qubit is H⊗I. Single-qubit gates plus CNOT are universal: any unitary on any number of qubits can be built from them.

A Bell pair

Start in |00⟩, apply H to the first qubit, then CNOT:

|00⟩→H⊗I|00⟩+|10⟩2→CNOT|00⟩+|11⟩2

Measuring either qubit gives 0 or 1 at random, but the two always agree: lesson 44's entangled state, made with two gates.

Measurement

A measurement in the |0⟩,|1⟩ basis returns each outcome with probability |amplitude|2 and leaves the qubit in that state. To learn an amplitude you repeat the whole circuit many times; to measure in another basis you rotate first.

Errors

Each gate succeeds with fidelity F=1−ε, so a circuit of N gates succeeds with probability about FN≈e−Nε, and each qubit loses its state over its coherence time T2. With 30 ns gates and T2 = 100 µs, a qubit lasts about 3300 gate times. Error correction encodes one logical qubit in many physical ones, and only works once ε is below a threshold near 1%.

Worked example

Apply H twice to |0⟩, writing out the matrices.

Show the solution
  1. First Hadamard. H|0⟩=12(11)
  2. Second Hadamard. H(12(11))=12(1+11−1)=(10)=|0⟩
  3. Why |1⟩ cancels. The |1⟩ amplitude is 12(1−1)=0: two paths, one through |0⟩ and one through |1⟩, with opposite signs.
  4. Measuring in between. Measuring between the two Hadamards would destroy that cancellation and leave a 50-50 result.

Answer two Hadamards bring |0⟩ back to |0⟩.

Worked example

Deutsch's problem: a black-box function f takes one bit to one bit. Is it constant (f(0)=f(1)) or balanced? Classically you must evaluate f twice. Show how one quantum evaluation suffices.

Show the solution
  1. Prepare. Start in |0⟩|1⟩ and apply H to both qubits.
  2. Query the box once. It maps |x⟩|y⟩→|x⟩|y⊕f(x)⟩. The second qubit, in (|0⟩−|1⟩)/2, turns the query into a phase (−1)f(x) on the first qubit's |x⟩, so the first qubit becomes 12((−1)f(0)|0⟩+(−1)f(1)|1⟩)
  3. Hadamard and measure. Apply H to the first qubit and measure it. The Hadamard sends that state to ±|0⟩ if f is constant and ±|1⟩ if balanced.
  4. One query. One query, a certain answer: the global property was read out through interference.

Answer after one query and a final Hadamard, the first qubit reads 0 if f is constant and 1 if it's balanced.

Worked example

A processor's two-qubit gates have 99.5% fidelity and its single-qubit gates 99.95%. Estimate the success probability of a circuit with 40 two-qubit and 120 single-qubit gates.

Show the solution
  1. Two-qubit gates. 0.99540=0.818
  2. Single-qubit gates. 0.9995120=0.942
  3. The whole circuit. 0.818×0.942=0.771
  4. Which gates cost more. The two-qubit gates, fewer but ten times as error-prone, cost three times as much. That's why circuit compilers work hardest to minimize two-qubit gates, and why two-qubit fidelity is the headline number for a quantum processor.

Answer the circuit succeeds with probability of about 0.771.

Check

A circuit has 100 gates, each with an error probability of 0.001. About what is the chance all of them succeed?

Check

Start in |0⟩ and apply a Hadamard gate.

(a)

What is the amplitude of |0⟩ afterward?

(b)

And of |1⟩?

Check

Using NumPy, build H, I2 and CNOT as matrices and start from the two-qubit state whose basis index is k = 1 (|00⟩,|01⟩,|10⟩,|11⟩ are 0 to 3). Apply H to the first qubit (np.kron(H, I2)), then CNOT. Set psi to the final state and probs to the four measurement probabilities.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Simulate Deutsch's algorithm for the one-bit function picked by f = 1: 0 is f(x)=0, 1 is f(x)=1, 2 is f(x)=x, 3 is f(x)=1−x. Build the oracle as a 4×4 matrix mapping |x,y⟩→|x,y⊕f(x)⟩, start from |01⟩, apply H⊗H, the oracle, then H⊗I, and set p1 to the probability that the first qubit is 1, and balanced to whether p1 > 0.5.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

A qubit's coherence time is 50 µs and its gates take 30 ns. About how many gate times fit in one coherence time?

Check

Apply H to a general state a|0⟩+b|1⟩ with real amplitudes.

Step 1

What is the new amplitude of |0⟩?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Check

Why does a Hadamard on the first qubit followed by a CNOT entangle two qubits, while either gate alone does not?

Explain why

Why is a circuit's success probability so sensitive to the error rate per gate, and what does that imply for building a useful quantum computer?

Practice

Keep practicing

7 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.