Introduction
- Introduction to the new wave of development: "AI Agent (Claude Code)"
- A tool that does more than just chat; it operates the local terminal, creating files, executing code, and resolving errors in a self-contained manner.
- This time's theme: "What happens if we delegate everything from setting up an experimental environment for Quantum Machine Learning (QML) to writing a report to this AI agent?"
1. Lightning-Fast Environment Setup and Experimental Design
We explain the smart approach suggested by AI to advance the experiment.
- Separation of workspace: To avoid cluttering existing repositories (such as web frontends), an independent sandbox environment named
quantum_ml_lab/was automatically created. - Library installation: The latest quantum computing SDK
blueqat(PyTorch Native Edition) was pulled from GitHub and installed within a virtual environment (venv).
2. Implemented Quantum Machine Learning (QML) Model
Here is an explanation of the Variational Quantum Classifier (VQC) coded by AI in just under one minute.
- Dataset: Two-dimensional synthetic data generated using
scikit-learn'smake_blobswas mapped to two qubits using angle encoding (\(RY\) rotation angles). - Variational Quantum Circuit (Ansatz): A quantum circuit combining \(\displaystyle RY(\theta_0) \otimes RY(\theta_1)\) with \(CX\) gates (entanglement).
- Hybrid Quantum-Classical Learning: Using PyTorch's
autograd, the expectation value of the quantum state observation \(\langle Z_0 \rangle\) was backpropagated, and parameters \(\theta\) were optimized using the Adam optimizer. - Results: The training loss converged beautifully. It achieved a training data accuracy of 92.9% and a test data accuracy of 77.8%.
3. The Drama Begins Here: The AI Agent "Self-Discovered" Bugs in the SDK
This is the highlight of this episode. Not only did it execute the code, but the AI itself noticed the "qualitative oddity" in the output and began debugging.
① Statistical Bug in the Shot Sampler (Important)
- Incident: When measuring the circuit
H[0].H[1](where two Hadamard gates are placed in series, which should result in an equal distribution where measurement outcomes00, 01, 10, 11each occur 25% of the time) 2000 times usingblueqat's default mode (tensornet), probabilities became extremely skewed toward specific bit strings, and some bit strings failed to appear at all. - AI Cause Analysis: The AI identified that in the marginal probability calculation logic around lines 333–380 of
blueqat/backends/torch_backend.py, instead of applying Born's rule (\(\vert{}\text{amplitude}\vert{}^2\)), it was performing tensor contraction on the amplitudes themselves (viatrace_vec=[1,1]). Consequently, it was incorrectly calculating the "sum of amplitudes" rather than "probabilities." - Workaround: By explicitly specifying
mode='statevector'for sampling, correct behavior (an equal 25% distribution) was confirmed, and the code was corrected.
② Identification of a Minor Display Bug
- While reviewing the code in
blueqat/gate.py, the AI also discovered a specification bug where full-width parentheses “(” and “)” were used for gate display brackets, causing the output format to break whenprint(circuit)was executed.
4. Finishing Touches: Automatic Generation of Beautiful PDF Reports via Matplotlib

In response to the request for a "concise report," Claude Code saved the results as JSON (results.json) to a temporary file. It then read this data and autonomously wrote and executed a PDF generator (make_report.py) that accurately plots charts without garbled text for Japanese fonts (Hiragino Kaku Gothic).
- Page 1: Execution environment, experimental overview, and circuit configuration expressed with mathematical formulas.
- Page 2: Graph showing the decrease in Loss per epoch, and a scatter plot indicating boundaries in the test data.
- Page 3: Histograms of measurement results for each class.
- Page 4 (Appendix): Graphs reproducing the data for the "Sampler Bug" discovered, along with proposed fixes for the development team.
5. Points to Note and Lessons Learned When Trying Quantum Computing with Claude Code
Practical tips for conducting research and development together with an AI agent.
- The Importance of "Watching Over" AI Execution: AI writes and executes code at lightning speed. However, physical phenomena and quantum mechanical correctness (e.g., whether expectation values satisfy probability conservation laws) require human double-checking by looking at the code and graphs ("Hmm, isn't this distribution strange?") or explicitly instructing the AI to "verify if it matches theoretical values." This leads to the discovery of critical bugs like those encountered here.
- Cleaning Up the Execution Environment: When handling heavy libraries or specific backends (such as PyTorch, Qiskit, Blueqat, etc.) for quantum computing, the golden rule is to ask the AI to "create a venv or Conda environment first before proceeding" to avoid breaking your local existing environment.
- Font Issues During PDF Output: When creating Japanese reports, Matplotlib does not include Japanese fonts by default, often resulting in tofu boxes (garbled text). It is essential to have the AI automatically recognize the OS-specific font system (Mac/Windows/Linux) and explicitly specify the font family (e.g.,
Hiragino SansorIPAexGothic).
Summary: AI Agents Become "Excellent Co-Researchers"
Through this trial, it was proven that Claude Code goes beyond simple "coding assistance." It acts as the ultimate practical partner, autonomously handling "hypothesis verification ➔ self-debugging of bugs ➔ documentation."
If you are learning about quantum computing or want to conduct experiments, try talking to an AI agent and saying, "Let's reproduce this paper together" or "Write a validation script and make a report"!