Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand conditional quantum logic: Controlled-NOT (CNOT), Controlled-Z (CZ), Controlled-Phase (CPHASE), and multi-qubit gates.
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 , the target qubit is left completely untouched.
If the control qubit is in state , the gate 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!Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.8
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Controlled-U 4×4 matrix | Two-qubit conditional logic operator | |
| Inactive branch (control = 0) | Leaves target qubit unchanged (top-left Identity block) | |
| Active branch (control = 1) | Applies gate to target qubit (bottom-right block) | |
| Kronecker tensor product | Combines independent quantum operations across multi-qubit systems |
Constructing and verifying Controlled-Z (CZ) where U = Z = [[1, 0], [0, -1]]:
Result: CZ only applies the -1 phase flip when BOTH qubits are in state 1 ().
Decomposes state into control=|0> and control=|1> subspaces.
Leaves control=|0> branch untouched; applies U to control=|1> branch.
Generates non-local correlations if control was in superposition.
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.
Interactive activity component
Construct multi-qubit controlled gates in Qiskit and demonstrate controlled phase kickback and symmetry.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install qiskit1 from qiskit import QuantumCircuit 2 from qiskit.quantum_info import Statevector
from qiskit import QuantumCircuit → Circuit constructor
from qiskit.quantum_info import Statevector → Statevector analysis
1 # Controlled-Z applies a -1 phase ONLY when BOTH qubits are in state |1> 2 qc = QuantumCircuit(2) 3 qc.h([0, 1]) # Put both qubits into superposition |+>|+> 4 print('State before CZ (|++>):', Statevector.from_instruction(qc).data.round(2)) 5 qc.cz(0, 1) # Apply Controlled-Z 6 sv_after = Statevector.from_instruction(qc) 7 print('State after CZ: ', sv_after.data.round(2)) 8 print('\nNotice: Only the amplitude of |11> flipped from +0.5 to -0.5!') 9 print('Circuit diagram:') 10 print(qc.draw('text'))
# 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
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
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 10 from qiskit import QuantumCircuit 11 from 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> 15 qc = QuantumCircuit(2) 16 qc.h([0, 1]) # Put both qubits into superposition |+>|+> 17 print('State before CZ (|++>):', Statevector.from_instruction(qc).data.round(2)) 18 qc.cz(0, 1) # Apply Controlled-Z 19 sv_after = Statevector.from_instruction(qc) 20 print('State after CZ: ', sv_after.data.round(2)) 21 print('\nNotice: Only the amplitude of |11> flipped from +0.5 to -0.5!') 22 print('Circuit diagram:') 23 print(qc.draw('text'))
Apply H to both qubits, creating equal superposition of |00>, |01>, |10>, |11>.
The CZ gate conditionally applies a pi phase shift only when both control and target are 1.
State transforms into cluster state (|00> + |01> + |10> - |11>)/2.
QuantumCircuit(2) with H on both wires and CZ(0, 1).
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.
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.
Hadamard, CNOT, Bell-state intuition, and correlated quantum circuits.
Test your understanding with these questions. Remember, this is for learning, not examination!