You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.
Two-qubit gates: CNOT, CZ, SWAP
Controls and targets, the matrices, and how CZ is a CNOT in disguise.
- 01Apply CNOT to each of the four basis states.
- 02Convert a CZ into a CNOT with two Hadamards.
- 03Decompose 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.
01Useful 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];
2 questions · one try each counts
CNOT acts on |10⟩ (control = qubit 1 written first, target = qubit 0). What comes out?
Sign in to answer and climb the ranks; you will come back to this lesson.
How many CNOTs does a SWAP cost?
Sign in to answer and climb the ranks; you will come back to this lesson.