First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 6.8

Controlled Gates: The If-Then Logic of Quantum Circuits

Understand conditional quantum logic: Controlled-NOT (CNOT), Controlled-Z (CZ), Controlled-Phase (CPHASE), and multi-qubit gates.

Learning Objectives

  • ✓Define the Controlled-U operation: |0><0| ⊗ I + |1><1| ⊗ U
  • ✓Understand control and target qubits in circuit diagrams
  • ✓Examine Controlled-Z (CZ) symmetry and phase kickback

📖Let's Begin with a Story

In classical programming, the most fundamental conditional statement is the if-statement: ``python if condition == True: do_action() `` How do we do an "if-statement" in a quantum circuit without collapsing the quantum superposition? We use Controlled Gates! In a controlled gate, we connect two qubits: 1. The Control Qubit (marked with a solid black dot •). 2. The Target Qubit (marked with the gate box U). If the control qubit is in state ∣0⟩|0\rangle, the target qubit is left completely untouched. If the control qubit is in state ∣1⟩|1\rangle, the gate UU is applied to the target qubit. And what if the control qubit is in a superposition of both 0 and 1? Then the target qubit becomes entangled with the control qubit!

Why Should You Learn Controlled Gates: The If-Then Logic of Quantum Circuits?

🎯 Practical & Engineering Stakes

The engine of quantum correlation

Single-qubit gates can only rotate individual qubits. Controlled gates allow qubits to interact, communicate, and entangle, unlocking exponential computational spaces.

What Is It?

Simple Explanation

Controlled gates are quantum IF statements: - "IF the top qubit is 1, THEN do this move to the bottom qubit!" - "IF the top qubit is 0, do nothing!" Because the top qubit can be BOTH 0 and 1 at the same time, it does BOTH at the same time, creating spooky quantum entanglement!

Technical Explanation

A Controlled-U gate on a bipartite system Hc⊗Ht\mathcal{H}_c \otimes \mathcal{H}_t implements the block-diagonal unitary: C(U)=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗U=(I00U)C(U) = |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes U = \begin{pmatrix} I & 0 \\ 0 & U \end{pmatrix} If the control is in superposition α∣0⟩+β∣1⟩\alpha|0\rangle + \beta|1\rangle, the output state is α∣0⟩∣ψ⟩+β∣1⟩U∣ψ⟩\alpha|0\rangle|\psi\rangle + \beta|1\rangle U|\psi\rangle, synthesizing non-separable entangled states. In Controlled-Phase gates (CZ), CZ=∣00⟩⟨00∣+∣01⟩⟨01∣+∣10⟩⟨10∣−∣11⟩⟨11∣CZ = |00\rangle\langle 00| + |01\rangle\langle 01| + |10\rangle\langle 10| - |11\rangle\langle 11|, demonstrating symmetric control-target equivalence.

📚 Key Terms

Control Qubit

Simple: The qubit whose state decides whether the gate fires.
Technical: The conditioning register in a bipartite controlled unitary operation.

Target Qubit

Simple: The qubit that gets transformed if the control qubit is active.
Technical: The register to which unitary operator UU is applied conditioned on control subspace projection.

Phase Kickback

Simple: When an operation on the target qubit bounces backwards and changes the phase of the control qubit!
Technical: Quantum phenomenon where eigenvalues of an operator acting on the target qubit are transferred to the phase of the control qubit.

Q-Sphere Lab: Controlled Gates: The If-Then Logic of Quantum Circuits

IBM Q-Sphere Model

Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.8

Azimuth: 45°Elevation: 25°
+Z |0⟩-Z |1⟩+X |+⟩+Y |+i⟩01|ψ⟩
Q-Sphere Phase Color:
0 π/2 π 3π/2

Quantum Statevector

dim(H) = 2
|ψ⟩ = (1.000 + 0.000i)|0⟩
     + (0.000 + 0.000i)|1⟩
Polar Angle (θ):0.0° (0.000π rad)
Phase Angle (ϕ):0.0° (0.000π rad)

Born Rule Probabilities: P(x) = |⟨x|ψ⟩|²Σ P = 1.00

P(|0⟩) = |α|²100.0%
P(|1⟩) = |β|²0.0%
Quantum Measurement

Apply Single-Qubit Unitary Gates

Presets:
Continuous Polar Angle θ (0° = |0⟩, 180° = |1⟩):0.0°
Continuous Phase Angle ϕ (0° to 360°):0.0°
Recent Operations Log:
#1Initial state: |0⟩

📐 Mathematical Foundation

LaTeX KaTeX
C(U)=∣0⟩⟨0∣⊗I+∣1⟩⟨1∣⊗U=(1000010000u00u0100u10u11)C(U) = |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes U = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & u_{00} & u_{01} \\ 0 & 0 & u_{10} & u_{11} \end{pmatrix}

What does it mean?

Controlled-U Gate (Quantum If-Then Logic): Operates on two qubits: a control qubit and a target qubit. If the control qubit is ∣0⟩|0\rangle, the target qubit is left completely untouched (I). If the control qubit is ∣1⟩|1\rangle, the unitary gate U is applied to the target qubit. If the control is in superposition, it creates an entangled superposition of both branches simultaneously!

Understanding the Symbols

Symbol / TermMeaningBeginner Interpretation
C(U)C(U)Controlled-U 4×4 matrixTwo-qubit conditional logic operator
∣0⟩⟨0∣⊗I|0\rangle\langle 0| \otimes IInactive branch (control = 0)Leaves target qubit unchanged (top-left 2×22 \times 2 Identity block)
∣1⟩⟨1∣⊗U|1\rangle\langle 1| \otimes UActive branch (control = 1)Applies gate UU to target qubit (bottom-right 2×22 \times 2 block)
⊗\otimesKronecker tensor productCombines independent quantum operations across multi-qubit systems

📊 Numerical Example

Constructing and verifying Controlled-Z (CZ) where U = Z = [[1, 0], [0, -1]]:

Step 1: Construct CZ Matrix: CZ = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]] Step 2: Test on basis state ∣11⟩|11\rangle = [0, 0, 0, 1]^T: CZ ∣11⟩|11\rangle = CZ × [0, 0, 0, 1]^T = [0, 0, 0, -1]^T = -∣11⟩|11\rangle (Flipped sign!) Step 3: Test on basis state ∣01⟩|01\rangle = [0, 1, 0, 0]^T: CZ ∣01⟩|01\rangle = CZ × [0, 1, 0, 0]^T = [0, 1, 0, 0]^T = ∣01⟩|01\rangle (Unchanged!)

Result: CZ only applies the -1 phase flip when BOTH qubits are in state 1 (∣11⟩|11\rangle).

⚙️ How Does It Work?

1

Subspace Projection

Decomposes state into control=|0> and control=|1> subspaces.

2

Conditional Evolution

Leaves control=|0> branch untouched; applies U to control=|1> branch.

3

Entanglement Emergence

Generates non-local correlations if control was in superposition.

🌍 Where Is It Used?

Quantum Phase Estimation (QPE)

Problem: Estimating the eigenvalues and phase of a unitary operator with high precision.

Solution: Uses a cascade of Controlled-U^(2^j) gates to kick eigenvalues back into a measurement register.

🎯 Try It Yourself

The Controlled-Z (CZ) gate has matrix diag(1, 1, 1, -1). If you swap the control qubit and the target qubit, does the operation change?

Interactive activity component

🐍 Python Hands-On: Simulating Controlled-Z (CZ) and Phase Kickback in Qiskit

Construct multi-qubit controlled gates in Qiskit and demonstrate controlled phase kickback and symmetry.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install qiskit
Packages:
qiskit

2Import Libraries

Import Statementspython
1from qiskit import QuantumCircuit
2from qiskit.quantum_info import Statevector

from qiskit import QuantumCircuit → Circuit constructor

from qiskit.quantum_info import Statevector → Statevector analysis

3Demonstration Code & Logic

Python Execution Codepython
1# Controlled-Z applies a -1 phase ONLY when BOTH qubits are in state |1>
2qc = QuantumCircuit(2)
3qc.h([0, 1]) # Put both qubits into superposition |+>|+>
4print('State before CZ (|++>):', Statevector.from_instruction(qc).data.round(2))
5qc.cz(0, 1) # Apply Controlled-Z
6sv_after = Statevector.from_instruction(qc)
7print('State after CZ: ', sv_after.data.round(2))
8print('\nNotice: Only the amplitude of |11> flipped from +0.5 to -0.5!')
9print('Circuit diagram:')
10print(qc.draw('text'))
Step-by-Step Code Breakdown:

# Controlled-Z applies a -1 phase ONLY when BOTH qubits are in state |1>

CZ explanation

qc = QuantumCircuit(2)

2 qubits

qc.h([0, 1]) # Put both qubits into superposition |+>|+>

Equal superposition

print('State before CZ (|++>):', Statevector.from_instruction(qc).data.round(2))

Before CZ [0.5, 0.5, 0.5, 0.5]

qc.cz(0, 1) # Apply Controlled-Z

Apply CZ gate

sv_after = Statevector.from_instruction(qc)

Extract statevector

print('State after CZ: ', sv_after.data.round(2))

After CZ [0.5, 0.5, 0.5, -0.5]

print('\nNotice: Only the amplitude of |11> flipped from +0.5 to -0.5!')

CZ action

print('Circuit diagram:')

Diagram

print(qc.draw('text'))

Draw diagram

📋 Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Simulating Controlled-Z (CZ) and Phase Kickback in Qiskit
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install qiskit
8
9# Step 2: Import libraries
10from qiskit import QuantumCircuit
11from qiskit.quantum_info import Statevector
12
13# Step 3: Run Demonstration
14# Controlled-Z applies a -1 phase ONLY when BOTH qubits are in state |1>
15qc = QuantumCircuit(2)
16qc.h([0, 1]) # Put both qubits into superposition |+>|+>
17print('State before CZ (|++>):', Statevector.from_instruction(qc).data.round(2))
18qc.cz(0, 1) # Apply Controlled-Z
19sv_after = Statevector.from_instruction(qc)
20print('State after CZ: ', sv_after.data.round(2))
21print('\nNotice: Only the amplitude of |11> flipped from +0.5 to -0.5!')
22print('Circuit diagram:')
23print(qc.draw('text'))
⚡ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

🔄 Algorithmic Execution Flow

1
Initialize Joint Superposition

Apply H to both qubits, creating equal superposition of |00>, |01>, |10>, |11>.

→
2
Execute Controlled-Z

The CZ gate conditionally applies a pi phase shift only when both control and target are 1.

→
3
Observe Entangled State

State transforms into cluster state (|00> + |01> + |10> - |11>)/2.

📥 Input / Initial State
QuantumCircuit(2) with H on both wires and CZ(0, 1).
📤 Expected Output
Before CZ: [0.5, 0.5, 0.5, 0.5]
After CZ:  [0.5, 0.5, 0.5, -0.5]
Only |11> receives -1 phase factor.
💡 What Does This Demonstration Show?

Controlled gates enable conditional quantum logic. Because CZ is completely symmetric, control and target roles can be swapped with zero change to the resulting physical state.

Course Learning Resource • Slide DeckLesson 810 Slides

Lesson 8: Two Qubits and Entanglement

Hadamard, CNOT, Bell-state intuition, and correlated quantum circuits.

Author: Dr. Syed Muzamil Basha• FDP Approved Curriculum
Open in New Tab

📝 Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: What is the matrix dimension of a Controlled-NOT (CNOT) gate acting on a 2-qubit register?

Question 2: What is a controlled gate in quantum computing?

Question 3: How many qubits does a controlled-U gate operate on minimum?

Question 4: What is the matrix dimension of a 2-qubit controlled gate?

Question 5: Why are controlled gates essential for quantum computing?