Quantum Computing Notes
Circuit construction, statevector simulation, parameterized QNodes, and tensor-network examples using Qiskit, PennyLane, and TensorCircuit.
Frameworks & Environment Setup
Most experiments in this notebook use Python 3.10+ inside an isolated virtual environment so simulator versions stay reproducible.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install qiskit qiskit-aer pennylane tensorcircuit
Circuit & Aer Simulation
Gate-level circuit building with QuantumCircuit, transpilation passes, and shot-based or statevector execution via qiskit_aer.
Differentiable QNodes
Hybrid quantum-classical circuits using @qml.qnode, parameter-shift gradients, and device-agnostic expectations.
Tensor-Network Engine
Fast tensor contraction simulator supporting JAX, PyTorch, and TensorFlow backends with JIT compilation and vmap batching.
Core Circuit Patterns
Side-by-side reference implementations for entanglement and variational circuits.
from qiskit import QuantumCircuit from qiskit_aer import AerSimulator qc = QuantumCircuit(2, 2) qc.h(0) qc.cx(0, 1) qc.measure([0, 1], [0, 1]) job = AerSimulator().run(qc, shots=1024) counts = job.result().get_counts() print(counts) # {'00': ~512, '11': ~512}
import pennylane as qml from pennylane import numpy as np dev = qml.device("default.qubit", wires=2) @qml.qnode(dev) def circuit(theta): qml.RX(theta, wires=0) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)) grad_fn = qml.grad(circuit) print(circuit(np.pi / 3), grad_fn(np.pi / 3))
import tensorcircuit as tc K = tc.set_backend("jax") def bell_expectation(): c = tc.Circuit(2) c.H(0) c.cnot(0, 1) return K.real(c.expectation_ps(z=[0, 1])) print(bell_expectation()) # 1.0 (ZZ correlation)
Quick Gate & Measurement Cheat Sheet
Common Gates
- H — Hadamard: maps |0〉 to (|0〉 + |1〉)/√2 superposition
- X / Y / Z — Pauli bit-flip, phase+bit-flip, and phase-flip
- RX / RY / RZ — Parameterized Bloch sphere rotations
- CX / CNOT — Controlled-NOT for 2-qubit entanglement
Readouts & Observables
- get_counts() — Qiskit bitstring frequencies over N shots
- qml.probs() — PennyLane computational basis probabilities
- qml.expval() — Expectation value 〈ψ|H|ψ〉 for VQE/QAOA
- expectation_ps() — TensorCircuit Pauli-string expectation