Show description
Quantum Computing Guide - Qiskit & Cirq
Quantum Computing Guide - Qiskit & Cirq
🌌 Quantum Computing Guide
A comprehensive guide to Qiskit & Cirq for classical programmers
Introduction to Quantum Computing
Quantum computing leverages quantum mechanical phenomena like superposition and entanglement to process information in fundamentally different ways than classical computers. Instead of bits (0 or 1), quantum computers use qubits that can exist in superposition of both states simultaneously.
Key Difference: Classical computing is deterministic; quantum computing is probabilistic. You run circuits multiple times and analyze the distribution of results.
Linear Algebra Essentials
Vectors
Quantum states are represented as vectors in complex vector spaces. A qubit state is a 2D vector:
|ψ⟩ = α|0⟩ + β|1⟩
Where |α|² + |β|² = 1 (normalization condition)
|0⟩ = [1, 0]ᵀ (basis state 0)
|1⟩ = [0, 1]ᵀ (basis state 1)
Matrices & Quantum Gates
Quantum gates are unitary matrices that transform qubit states. They must preserve probability (be reversible).
Pauli-X Gate (quantum NOT):
X = [0 1]
[1 0]
Hadamard Gate (creates superposition):
H = 1/√2 × [1 1]
[1 -1]
CNOT Gate (2-qubit controlled gate):
CNOT = [1 0 0 0]
[0 1 0 0]
[0 0 0 1]
[0 0 1 0]
Tensor Products
Multi-qubit states are tensor products of individual qubit states:
|ψ⟩ ⊗ |φ⟩ = |ψφ⟩
Example: |0⟩ ⊗ |1⟩ = |01⟩ = [0, 1, 0, 0]ᵀ
Key Linear Algebra Operations
Inner Product: ⟨ψ|φ⟩ = measure of overlap between states
Outer Product: |ψ⟩⟨φ| = creates operators/projections
Matrix Multiplication: How gates transform states
Eigenvalues/Eigenvectors: Measurement outcomes and basis states
Quantum Concepts Quick Reference
Superposition
A qubit can be in multiple states simultaneously until measured. Like a coin spinning in the air.
Entanglement
Two qubits become correlated such that measuring one instantly affects the other, regardless of distance.
Interference
Quantum amplitudes can add constructively or destructively, amplifying correct answers and canceling wrong ones.
Measurement
Collapses superposition to classical state.…
Quantum Computing Guide - Qiskit & Cirq
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quantum Computing Guide - Qiskit & Cirq</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #0a0e27;
color: #e4e4e7;
line-height: 1.6;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 40px;
border-radius: 12px;
margin-bottom: 30px;
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
h2 {
color: #a78bfa;
margin: 40px 0 20px 0;
font-size: 2em;
border-bottom: 2px solid #4c1d95;
padding-bottom: 10px;
}
h3 {
color: #c4b5fd;
margin: 30px 0 15px 0;
font-size: 1.5em;
}
h4 {
color: #ddd6fe;
margin: 20px 0 10px 0;
}
.section {
background: #1a1f3a;
padding: 30px;
border-radius: 8px;
margin-bottom: 20px;
border-left: 4px solid #667eea;
}
.code-block {
background: #0f1729;
border: 1px solid #2d3748;
border-radius: 6px;
padding: 20px;
margin: 15px 0;
overflow-x: auto;
font-family: 'Courier New', monospace;
font-size: 0.9em;
}
.code-block code {
color: #a78bfa;
}
.math {
background: #1e1b4b;
padding: 15px;
border-radius: 6px;
margin: 15px 0;
border-left: 3px solid #8b5cf6;
font-family: 'Times New Roman', serif;
}
.glossary-term {
background: #1e293b;
padding: 15px;
margin: 10px 0;
border-radius: 6px;
border-left: 3px solid #667eea;
}
.glossary-term strong {
color: #a78bfa;
font-size: 1.1em;
}
.note {
background: #312e81;
padding: 15px;
border-radius: 6px;
margin: 15px 0;
border-left: 4px solid #6366f1;
}
.framework-box {
background: #1e293b;
padding: 20px;
border-radius: 8px;
margin: 15px 0;
}
.framework-box h3 {
color: #60a5fa;
margin-top: 0;
}
ul, ol {
margin-left: 25px;
margin-top: 10px;
}
li {
margin: 8px 0;
}
a {
color: #818cf8;
text-decoration: none;
}
a:hover {
color: #a78bfa;
text-decoration: underline;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #2d3748;
}
th {
background: #1e1b4b;
color: #a78bfa;
}
tr:hover {
background: #1e293b;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin: 20px 0;
}
.card {
background: #1e293b;
padding: 20px;
border-radius: 8px;
border: 1px solid #2d3748;
}
.card h4 {
color: #818cf8;
margin-top: 0;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>🌌 Quantum Computing Guide</h1>
<p>A comprehensive guide to Qiskit & Cirq for classical programmers</p>
</header>
<div class="section">
<h2>Introduction to Quantum Computing</h2>
<p>Quantum computing leverages quantum mechanical phenomena like superposition and entanglement to process information in fundamentally different ways than classical computers. Instead of bits (0 or 1), quantum computers use qubits that can exist in superposition of both states simultaneously.</p>
<div class="note">
<strong>Key Difference:</strong> Classical computing is deterministic; quantum computing is probabilistic. You run circuits multiple times and analyze the distribution of results.
</div>
</div>
<div class="section">
<h2>Linear Algebra Essentials</h2>
<h3>Vectors</h3>
<p>Quantum states are represented as vectors in complex vector spaces. A qubit state is a 2D vector:</p>
<div class="math">
|ψ⟩ = α|0⟩ + β|1⟩
<br><br>
Where |α|² + |β|² = 1 (normalization condition)
<br><br>
|0⟩ = [1, 0]ᵀ (basis state 0)
<br>
|1⟩ = [0, 1]ᵀ (basis state 1)
</div>
<h3>Matrices & Quantum Gates</h3>
<p>Quantum gates are unitary matrices that transform qubit states. They must preserve probability (be reversible).</p>
<div class="math">
<strong>Pauli-X Gate (quantum NOT):</strong>
<br>
X = [0 1]
<br>
[1 0]
<br><br>
<strong>Hadamard Gate (creates superposition):</strong>
<br>
H = 1/√2 × [1 1]
<br>
[1 -1]
<br><br>
<strong>CNOT Gate (2-qubit controlled gate):</strong>
<br>
CNOT = [1 0 0 0]
<br>
[0 1 0 0]
<br>
[0 0 0 1]
<br>
[0 0 1 0]
</div>
<h3>Tensor Products</h3>
<p>Multi-qubit states are tensor products of individual qubit states:</p>
<div class="math">
|ψ⟩ ⊗ |φ⟩ = |ψφ⟩
<br><br>
Example: |0⟩ ⊗ |1⟩ = |01⟩ = [0, 1, 0, 0]ᵀ
</div>
<h3>Key Linear Algebra Operations</h3>
<ul>
<li><strong>Inner Product:</strong> ⟨ψ|φ⟩ = measure of overlap between states</li>
<li><strong>Outer Product:</strong> |ψ⟩⟨φ| = creates operators/projections</li>
<li><strong>Matrix Multiplication:</strong> How gates transform states</li>
<li><strong>Eigenvalues/Eigenvectors:</strong> Measurement outcomes and basis states</li>
</ul>
</div>
<div class="section">
<h2>Quantum Concepts Quick Reference</h2>
<div class="grid">
<div class="card">
<h4>Superposition</h4>
<p>A qubit can be in multiple states simultaneously until measured. Like a coin spinning in the air.</p>
</div>
<div class="card">
<h4>Entanglement</h4>
<p>Two qubits become correlated such that measuring one instantly affects the other, regardless of distance.</p>
</div>
<div class="card">
<h4>Interference</h4>
<p>Quantum amplitudes can add constructively or destructively, amplifying correct answers and canceling wrong ones.</p>
</div>
<div class="card">
<h4>Measurement</h4>
<p>Collapses superposition to classical state. Probabilistic outcome based on amplitudes squared.</p>
</div>
</div>
</div>
<div class="section">
<h2>Qiskit Tutorial</h2>
<h3>Installation</h3>
<div class="code-block">
<code>pip install qiskit qiskit-aer qiskit-ibm-runtime</code>
</div>
<h3>Basic Circuit - Bell State (Entanglement)</h3>
<div class="code-block">
<code>from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit_aer import Aer
from qiskit.visualization import plot_histogram
import matplotlib.pyplot as plt
# Create quantum and classical registers
qr = QuantumRegister(2, 'q')
cr = ClassicalRegister(2, 'c')
circuit = QuantumCircuit(qr, cr)
# Build Bell State: creates entanglement
circuit.h(qr[0]) # Hadamard on qubit 0 (superposition)
circuit.cx(qr[0], qr[1]) # CNOT with 0 as control, 1 as target
# Measure
circuit.measure(qr, cr)
# Simulate
simulator = Aer.get_backend('qasm_simulator')
job = simulator.run(circuit, shots=1024)
result = job.result()
counts = result.get_counts(circuit)
print(counts) # Should show ~50% |00⟩ and ~50% |11⟩
# plot_histogram(counts)</code>
</div>
<h3>Common Gates in Qiskit</h3>
<div class="code-block">
<code># Single-qubit gates
circuit.x(0) # Pauli-X (NOT gate)
circuit.y(0) # Pauli-Y
circuit.z(0) # Pauli-Z (phase flip)
circuit.h(0) # Hadamard (superposition)
circuit.s(0) # S gate (π/2 phase)
circuit.t(0) # T gate (π/4 phase)
circuit.rx(θ, 0) # Rotation around X-axis
circuit.ry(θ, 0) # Rotation around Y-axis
circuit.rz(θ, 0) # Rotation around Z-axis
# Two-qubit gates
circuit.cx(0, 1) # CNOT (controlled-X)
circuit.cy(0, 1) # Controlled-Y
circuit.cz(0, 1) # Controlled-Z
circuit.swap(0, 1) # SWAP gate
# Three-qubit gates
circuit.ccx(0, 1, 2) # Toffoli (controlled-controlled-X)</code>
</div>
<h3>Quantum Teleportation Example</h3>
<div class="code-block">
<code>from qiskit import QuantumCircuit
from qiskit_aer import Aer
# Create circuit with 3 qubits
qc = QuantumCircuit(3, 3)
# Prepare state to teleport on qubit 0
qc.ry(1.0, 0) # Arbitrary state
# Create Bell pair between qubits 1 and 2
qc.h(1)
qc.cx(1, 2)
# Barrier for visualization
qc.barrier()
# Bell measurement on qubits 0 and 1
qc.cx(0, 1)
qc.h(0)
qc.measure([0, 1], [0, 1])
# Apply corrections to qubit 2 based on measurements
qc.barrier()
qc.cx(1, 2)
qc.cz(0, 2)
# Measure final qubit
qc.measure(2, 2)
# Run simulation
simulator = Aer.get_backend('qasm_simulator')
result = simulator.run(qc, shots=1024).result()
print(result.get_counts())</code>
</div>
<h3>Running on Real Quantum Hardware</h3>
<div class="code-block">
<code>from qiskit_ibm_runtime import QiskitRuntimeService
# Save your IBM Quantum account (one time)
# QiskitRuntimeService.save_account(channel="ibm_quantum", token="YOUR_TOKEN")
# Load account
service = QiskitRuntimeService(channel="ibm_quantum")
# Get least busy backend
backend = service.least_busy(operational=True, simulator=False)
# Run your circuit
job = backend.run(circuit, shots=1024)
result = job.result()
counts = result.get_counts()</code>
</div>
</div>
<div class="section">
<h2>Cirq Overview</h2>
<h3>Installation</h3>
<div class="code-block">
<code>pip install cirq cirq-google</code>
</div>
<h3>Basic Cirq Circuit</h3>
<div class="code-block">
<code>import cirq
# Create qubits
q0, q1 = cirq.LineQubit.range(2)
# Create circuit
circuit = cirq.Circuit()
# Add gates
circuit.append([
cirq.H(q0), # Hadamard on q0
cirq.CNOT(q0, q1), # CNOT controlled by q0
cirq.measure(q0, q1, key='result')
])
# Simulate
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=1000)
print(result.histogram(key='result'))</code>
</div>
<h3>Cirq Gate Examples</h3>
<div class="code-block">
<code># Single qubit gates
cirq.X(qubit) # Pauli-X
cirq.Y(qubit) # Pauli-Y
cirq.Z(qubit) # Pauli-Z
cirq.H(qubit) # Hadamard
cirq.S(qubit) # S gate
cirq.T(qubit) # T gate
cirq.rx(angle)(qubit) # X rotation
cirq.ry(angle)(qubit) # Y rotation
cirq.rz(angle)(qubit) # Z rotation
# Two qubit gates
cirq.CNOT(control, target)
cirq.CZ(control, target)
cirq.SWAP(q0, q1)
# Measurements
cirq.measure(qubit, key='m')</code>
</div>
<h3>Key Differences: Qiskit vs Cirq</h3>
<table>
<thead>
<tr>
<th>Feature</th>
<th>Qiskit</th>
<th>Cirq</th>
</tr>
</thead>
<tbody>
<tr>
<td>Developer</td>
<td>IBM</td>
<td>Google</td>
</tr>
<tr>
<td>Focus</td>
<td>IBM quantum hardware, general purpose</td>
<td>Google hardware (Sycamore), NISQ algorithms</td>
</tr>
<tr>
<td>Circuit Syntax</td>
<td>circuit.gate(qubit)</td>
<td>gate(qubit) or circuit.append()</td>
</tr>
<tr>
<td>Qubit Notation</td>
<td>Indexed: qr[0], qr[1]</td>
<td>LineQubit, GridQubit objects</td>
</tr>
<tr>
<td>Documentation</td>
<td>Extensive tutorials, large community</td>
<td>More research-focused, smaller community</td>
</tr>
<tr>
<td>Hardware Access</td>
<td>IBM Quantum Platform</td>
<td>Google Quantum AI (limited access)</td>
</tr>
</tbody>
</table>
</div>
<div class="section">
<h2>Glossary of Terms</h2>
<div class="glossary-term">
<strong>Amplitude</strong><br>
Complex number coefficient in a quantum state superposition. The square of its magnitude gives the probability of measuring that state.
</div>
<div class="glossary-term">
<strong>Ancilla Qubit</strong><br>
Helper qubit used in quantum algorithms but not part of the final result. Often used for error correction or intermediate calculations.
</div>
<div class="glossary-term">
<strong>Basis State</strong><br>
Fundamental quantum states from which all other states can be constructed. For qubits: |0⟩ and |1⟩.
</div>
<div class="glossary-term">
<strong>Bell State</strong><br>
One of four maximally entangled two-qubit states. Example: (|00⟩ + |11⟩)/√2
</div>
<div class="glossary-term">
<strong>Bloch Sphere</strong><br>
Geometric representation of a single qubit state as a point on a unit sphere. North pole = |0⟩, South pole = |1⟩.
</div>
<div class="glossary-term">
<strong>Coherence Time</strong><br>
How long a qubit maintains its quantum properties before decoherence destroys it. Currently milliseconds to seconds.
</div>
<div class="glossary-term">
<strong>Decoherence</strong><br>
Loss of quantum properties due to environmental interference. Main source of errors in quantum computing.
</div>
<div class="glossary-term">
<strong>Deutsch-Jozsa Algorithm</strong><br>
Quantum algorithm that determines if a function is constant or balanced with one query (classical needs exponential queries).
</div>
<div class="glossary-term">
<strong>Entanglement</strong><br>
Quantum correlation where measuring one qubit instantly determines the state of another, regardless of distance.
</div>
<div class="glossary-term">
<strong>Gate Fidelity</strong><br>
Measure of how accurately a quantum gate operates. Perfect gate = 100% fidelity. Real hardware: 99-99.9%.
</div>
<div class="glossary-term">
<strong>Grover's Algorithm</strong><br>
Quantum search algorithm providing quadratic speedup for unstructured search. Finds item in √N time vs N classical.
</div>
<div class="glossary-term">
<strong>Hadamard Gate</strong><br>
Single-qubit gate creating equal superposition: |0⟩ → (|0⟩ + |1⟩)/√2, |1⟩ → (|0⟩ - |1⟩)/√2
</div>
<div class="glossary-term">
<strong>NISQ (Noisy Intermediate-Scale Quantum)</strong><br>
Current era of quantum computing: 50-1000 qubits with limited coherence, no full error correction.
</div>
<div class="glossary-term">
<strong>Oracle</strong><br>
Black-box function in quantum algorithms that marks solutions. Used in Grover's and Deutsch-Jozsa algorithms.
</div>
<div class="glossary-term">
<strong>Pauli Gates</strong><br>
Three fundamental single-qubit gates: X (bit flip), Y (bit + phase flip), Z (phase flip).
</div>
<div class="glossary-term">
<strong>Phase Kickback</strong><br>
Phenomenon where eigenvalue information from a target qubit is transferred to the control qubit. Key to many algorithms.
</div>
<div class="glossary-term">
<strong>Quantum Fourier Transform (QFT)</strong><br>
Quantum version of discrete Fourier transform. Exponentially faster than classical FFT. Core of Shor's algorithm.
</div>
<div class="glossary-term">
<strong>Quantum Register</strong><br>
Collection of qubits treated as a unit. In Qiskit: QuantumRegister(n, 'name')
</div>
<div class="glossary-term">
<strong>Quantum Supremacy / Advantage</strong><br>
Point where quantum computers solve problems classical computers practically cannot. Achieved by Google (2019) and others for specific tasks.
</div>
<div class="glossary-term">
<strong>Qubit</strong><br>
Quantum bit. Can be in superposition of |0⟩ and |1⟩ simultaneously. Physical implementations: superconducting circuits, trapped ions, photons.
</div>
<div class="glossary-term">
<strong>Shots</strong><br>
Number of times a quantum circuit is executed. More shots = better statistical accuracy of results.
</div>
<div class="glossary-term">
<strong>Shor's Algorithm</strong><br>
Quantum algorithm for factoring integers exponentially faster than known classical algorithms. Threatens RSA encryption.
</div>
<div class="glossary-term">
<strong>Superposition</strong><br>
Quantum state that's a linear combination of basis states. Allows quantum parallelism.
</div>
<div class="glossary-term">
<strong>Toffoli Gate</strong><br>
Three-qubit gate: controlled-controlled-NOT. Universal for reversible classical computing.
</div>
<div class="glossary-term">
<strong>Transpilation</strong><br>
Converting high-level quantum circuit to hardware-compatible gates and qubit layout. Required before running on real devices.
</div>
<div class="glossary-term">
<strong>Unitary Matrix</strong><br>
Matrix U where U†U = I (inverse equals conjugate transpose). All quantum gates must be unitary to preserve probability.
</div>
<div class="glossary-term">
<strong>Variational Quantum Eigensolver (VQE)</strong><br>
Hybrid quantum-classical algorithm for finding ground state energies. Popular NISQ algorithm for chemistry.
</div>
<div class="glossary-term">
<strong>Wave Function</strong><br>
Mathematical description of quantum state. Contains all information about the system's probabilities.
</div>
</div>
<div class="section">
<h2>Quick Start Resources</h2>
<h3>Qiskit Resources</h3>
<ul>
<li><a href="https://qiskit.org/textbook" target="_blank">Qiskit Textbook</a> - comprehensive learning resource</li>
<li><a href="https://qiskit.org/documentation/" target="_blank">Official Documentation</a></li>
<li><a href="https://quantum-computing.ibm.com/" target="_blank">IBM Quantum Platform</a> - free access to real quantum computers</li>
<li><a href="https://github.com/Qiskit/qiskit-tutorials" target="_blank">Tutorial Notebooks</a></li>
</ul>
<h3>Cirq Resources</h3>
<ul>
<li><a href="https://quantumai.google/cirq" target="_blank">Cirq Documentation</a></li>
<li><a href="https://quantumai.google/cirq/tutorials" target="_blank">Cirq Tutorials</a></li>
<li><a href="https://github.com/quantumlib/Cirq" target="_blank">Cirq GitHub</a></li>
</ul>
<h3>General Learning</h3>
<ul>
<li><a href="https://www.youtube.com/watch?v=F_Riqjdh2oM" target="_blank">Qiskit YouTube Channel</a></li>
<li>Nielsen & Chuang - "Quantum Computation and Quantum Information" (the bible)</li>
<li><a href="https://quantum.country/" target="_blank">Quantum Country</a> - interactive essay series</li>
</ul>
</div>
<div class="section">
<h2>Practical Next Steps</h2>
<ol>
<li>Install Qiskit and run the Bell state example above</li>
<li>Work through the Qiskit textbook basics (first 3 chapters)</li>
<li>Implement Deutsch-Jozsa algorithm yourself</li>
<li>Try running a circuit on IBM's real quantum hardware</li>
<li>Build a quantum random number generator</li>
<li>Explore VQE for a simple molecule (H2)</li>
<li>Compare same algorithm implementation in Qiskit and Cirq</li>
</ol>
<div class="note">
<strong>Reality Check:</strong> Quantum computing is still experimental. Focus on understanding the principles and exploring algorithms rather than expecting to build production applications yet. Most valuable skill right now is knowing when quantum advantage actually applies to a problem.
</div>
</div>
</div>
</body>
</html>