You are reading without signing in. Sign in or continue as guest to take quizzes and keep XP.
Two-qubit gates: CNOT, CZ, SWAP
Controls and targets, the matrices, and how CZ is a CNOT in disguise.
- Apply CNOT to each of the four basis states.
- Convert a CZ into a CNOT with two Hadamards.
- Decompose SWAP into three CNOTs.
In the composer, the filled dot is the control and the ⊕ is the target. On a superposed control the gate acts on both branches at once: that is how CNOT turns a product state into an entangled one, the subject of the next lesson.
Useful identities
- CNOT = (I ⊗ H) · CZ · (I ⊗ H): sandwich the target with Hadamards. Hardware with a native CZ (IBM Heron) compiles every CNOT this way.
- SWAP = CNOT(a,b) · CNOT(b,a) · CNOT(a,b): three two-qubit gates, which is why the transpiler avoids SWAPs when it can.
- Controlled-U for any U: the composer offers CU, CP, CRX, CRY, CRZ, CH.
Prove CZ ≡ H·CNOT·H
Compile this circuit (any fake backend) and compare the unitary: the Levels tab shows the transpiler folding the three gates into a single CZ on a CZ-native target.
OPENQASM 3.0; include "stdgates.inc"; qubit[2] q; h q[1]; cx q[0], q[1]; h q[1];
CNOT acts on |10⟩ (control = qubit 1 written first, target = qubit 0). What comes out?
Sign in to answer and earn XP; you will come back to this lesson.
How many CNOTs does a SWAP cost?
Sign in to answer and earn XP; you will come back to this lesson.
CNOT flips the target when the control is 1 and acts on all branches of a superposition; CZ is the same gate seen from the X basis; SWAP costs three CNOTs.
Up next: Entanglement and the Bell states