QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
HomeLearnCatalogRanksPlaygroundDocs
03 · Two-qubit gates: CNOT, CZ, SWAP0%

You are reading without signing in. Sign in or continue as guest to take quizzes and climb the ranks.

Learn/QC 102Gates and Circuits·Lesson 3 of 7

Two-qubit gates: CNOT, CZ, SWAP

Controls and targets, the matrices, and how CZ is a CNOT in disguise.

Beginner12 min read5 sections · 2 questions+45
By the end you will be able to
  1. 01Apply CNOT to each of the four basis states.
  2. 02Convert a CZ into a CNOT with two Hadamards.
  3. 03Decompose SWAP into three CNOTs.
CNOT=​1000​0100​0001​0010​​;(∣ct⟩→∣c,;t⊕c⟩),CZ=diag(1,1,1,−1)
CNOT flips the target when the control is 1. CZ adds a −1 phase only to |11⟩ and is symmetric: either qubit can be called the control.

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.
Hands-on

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
OPENQASM 3.0;
include "stdgates.inc";
qubit[2] q;
h q[1];
cx q[0], q[1];
h q[1];
Sign in to run (nothing is saved)
Open in the IDE Open in the Playground
Knowledge check

2 questions · one try each counts

Question 1

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.

Question 2

How many CNOTs does a SWAP cost?

Sign in to answer and climb the ranks; you will come back to this lesson.

Key takeaway

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.

Finished reading?

Knowledge check: 2 questions waiting above. Questions are optional. Mark it complete, or press Next: moving on marks it complete too.

Up next
Lesson 4 · 14 min
Entanglement and the Bell states
Build the four Bell states, test them with correlations, and see why they cannot be factored.
Further reading
  • Docs: multi-qubit gate cards
More in Gates and Circuits
  • Pauli gates: X, Y, Z
  • Phase and rotation gates
  • Phase Kickback: The Algorithm Secret
Phase and rotation gatesEntanglement and the Bell states
In this lesson0%
  1. Introduction
  2. Useful identities
  3. Try it: Prove CZ ≡ H·CNOT·H
  4. Knowledge check
  5. Key takeaway
QubitLab
IDELearnPlaygroundDocsCommunity
Log in
QubitLab
IDELearnPlaygroundDocsCommunity
Log in