Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Construct, manipulate, and compile quantum circuits using industry-standard Python frameworks (Qiskit QuantumCircuit API).
python
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
``
Today, Qiskit is the most widely used quantum programming framework in the world, downloaded millions of times and supported across academic and enterprise research.qc = QuantumCircuit(2, 2): Create a circuit with 2 qubits and 2 classical bits.
2. qc.h(0): Put qubit 0 into superposition!
3. qc.cx(0, 1): Entangle qubit 0 and qubit 1 with a CNOT gate!
4. qc.measure_all(): Measure all qubits!
5. Send to a simulator or real IBM quantum computer to run!QuantumCircuit class represents an internal directed acyclic graph (DAGCircuit) of quantum operations. Methods like qc.h(q), qc.cx(c, t), and qc.append(gate, qargs) append CircuitInstruction nodes to the DAG. Circuits serialize to standard OpenQASM intermediate representation for compiler passes and hardware transpilation.Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.11
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Quantum circuit object (QuantumCircuit) | The program structure containing qubits, gates, and classical registers | |
| Circuit depth (time slices) | Longest sequence of dependent gates along any single qubit wire | |
| Total gate count | Total number of quantum gate operations in the circuit | |
| Physical gate duration | Time needed by microwave pulse (single-qubit gate ns, CNOT ns) |
Analyzing depth and execution duration for a 2-qubit circuit with H on q0, H on q1, then CNOT(q0 → q1):
Result: Because 220 ns is far less than typical coherence time T2 ≈ 100 μs, the circuit executes with high fidelity.
Define qubit and bit counts: qc = QuantumCircuit(2, 2).
Call gate methods sequentially: qc.h(0), qc.x(1), qc.cx(0, 1).
Map quantum registers to classical bits: qc.measure(0, 0).
Problem: Submitting a quantum circuit from a laptop in London to run on a dilution refrigerator in Yorktown Heights, New York.
Solution: Qiskit Runtime serializes the QuantumCircuit and streams measurement counts back over secure HTTPS.
Interactive activity component
Construct an industry-standard 3-qubit Greenberger-Horne-Zeilinger (GHZ) state circuit in Qiskit and inspect its structure.
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 module
from qiskit.quantum_info import Statevector → Statevector module
1 # Build a 3-Qubit GHZ State: (|000> + |111>)/sqrt(2) 2 qc = QuantumCircuit(3, 3) 3 qc.h(0) # Superposition on qubit 0 4 qc.cx(0, 1) # Entangle q0 with q1 5 qc.cx(1, 2) # Entangle q1 with q2 6 qc.measure([0, 1, 2], [0, 1, 2]) 7 print('=== 3-Qubit GHZ State Circuit Diagram ===') 8 print(qc.draw('text')) 9 10 # Analyze Statevector before measurement 11 qc_no_meas = qc.remove_final_measurements(inplace=False) 12 sv = Statevector.from_instruction(qc_no_meas) 13 print('\nNon-zero basis state probabilities:') 14 for state, prob in sv.probabilities_dict().items(): 15 if prob > 0.01: 16 print(f' |{state}> : {prob * 100:.1f}%')
# Build a 3-Qubit GHZ State: (|000> + |111>)/sqrt(2)
GHZ circuit
qc = QuantumCircuit(3, 3)
3 qubits and 3 classical bits
qc.h(0) # Superposition on qubit 0
Step 1: H on q0
qc.cx(0, 1) # Entangle q0 with q1
Step 2: CNOT q0->q1
qc.cx(1, 2) # Entangle q1 with q2
Step 3: CNOT q1->q2
qc.measure([0, 1, 2], [0, 1, 2])
Measure all 3 qubits
print('=== 3-Qubit GHZ State Circuit Diagram ===')
Header
print(qc.draw('text'))
Print text diagram
# Analyze Statevector before measurement
Statevector analysis
qc_no_meas = qc.remove_final_measurements(inplace=False)
Strip measurement
sv = Statevector.from_instruction(qc_no_meas)
Compute statevector
print('\nNon-zero basis state probabilities:')
Label
for state, prob in sv.probabilities_dict().items():
Print probabilities
if prob > 0.01:
Filter non-zero
print(f' |{state}> : {prob * 100:.1f}%')
Show 50% |000> and 50% |111>
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Building and Drawing a 3-Qubit GHZ State Circuit 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 # Build a 3-Qubit GHZ State: (|000> + |111>)/sqrt(2) 15 qc = QuantumCircuit(3, 3) 16 qc.h(0) # Superposition on qubit 0 17 qc.cx(0, 1) # Entangle q0 with q1 18 qc.cx(1, 2) # Entangle q1 with q2 19 qc.measure([0, 1, 2], [0, 1, 2]) 20 print('=== 3-Qubit GHZ State Circuit Diagram ===') 21 print(qc.draw('text')) 22 23 # Analyze Statevector before measurement 24 qc_no_meas = qc.remove_final_measurements(inplace=False) 25 sv = Statevector.from_instruction(qc_no_meas) 26 print('\nNon-zero basis state probabilities:') 27 for state, prob in sv.probabilities_dict().items(): 28 if prob > 0.01: 29 print(f' |{state}> : {prob * 100:.1f}%')
Initialize superposition on qubit 0.
Propagate entanglement through qubits 1 and 2 to create tripartite correlation.
Inspect circuit diagram and verify non-local 3-qubit superposition (|000> + |111>)/sqrt(2).
QuantumCircuit(3, 3) implementing GHZ state.
q_0: ──[ H ]──■──────────────[ M ]
│ ║
q_1: ─────────X────■─────────[ M ]
│ ║
q_2: ──────────────X─────────[ M ]
Probabilities: |000>: 50.0%, |111>: 50.0%The GHZ state represents genuine tripartite entanglement: all 3 qubits are entangled such that measuring any single qubit immediately collapses all 3 qubits simultaneously.
Hadamard gate, quantum registers, simulation, and histogram measurement.
Test your understanding with these questions. Remember, this is for learning, not examination!