A real quantum playground for AI agents: run textbook circuits, watch parameter-shift gradients, and learn QML primitives (VQE, QAOA) against actual PennyLane executions — not slides, not mocked numbers.
A tiny Python package (quantum_playground) over PennyLane
default.qubit. Five experiments, one honest envelope on every
result (simulator: true, hardware: false):
bell_state() — (|00⟩+|11⟩)/√2, full probability distributionghz_state(n) — n-qubit GHZ state, n = 2..8rotation_demo(theta) — RX(θ)|0⟩: ⟨Z⟩ plus its analytic gradient via parameter-shiftvqe_h2() — variational ground-state energy of H₂ (STO-3G)qaoa_maxcut() — p=1 QAOA on the 4-node ringA qp CLI mirrors the API. qp demo runs everything.
| Experiment | Result |
|---|---|
| Bell state | P(00) = P(11) = 0.5, ⟨Z₀⟩ = ⟨Z₁⟩ = 0 |
| RX(0.5) | ⟨Z⟩ = 0.8776, d⟨Z⟩/dθ = −0.4794 (parameter-shift) |
| VQE H₂ @ 0.74 Å | −1.1168 → −1.1373 Ha in 10 gradient steps |
| QAOA MaxCut, 4-ring | expected cut 2.765 → 2.999 (Adam, 40 steps); most-likely outcomes 0101/1010 — the two optimal cuts |
from quantum_playground import bell_state, rotation_demo, vqe_h2
bell_state()["probs"]
# {'00': 0.5, '01': 0.0, '10': 0.0, '11': 0.5}
rotation_demo(0.5)["gradient"] # -0.4794
vqe_h2()["energy_final_hartree"] # -1.1373
pip install pennylane>=0.40
pip install cwi-quantum-playground
qp bell
qp ghz 3
qp rotation 0.5
qp vqe --steps 10
qp qaoa --steps 40
qp demo # everything
Use the qp CLI or the Python package: bell_state, ghz_state, rotation_demo, vqe_h2, qaoa_maxcut. Precomputed real runs in /results.json — 47/47 pytest green.