It’s late, your compiler just threw a cryptic error, and you’re wondering if you can just ask an AI to port your Qiskit code to NVIDIA’s high-performance CUDA-Q. The answer, according to a new study from Red Hat, is a resounding "maybe—but watch your step."
TL;DR
Translating quantum code isn't like translating Python to C++; it’s more like translating a recipe where a single typo creates a different universe. This paper demonstrates that while small open-source LLMs can learn to port Qiskit to CUDA-Q, fine-tuning them often comes at the cost of "forgetting" the original Qiskit language—a phenomenon known as the "alignment tax."
What Problem Does This Paper Address?
The quantum computing world is currently split. Most developers write in Qiskit (Python-based, great for research), but to get real performance on supercomputers, you often need NVIDIA CUDA-Q (which integrates tightly with GPUs). Manually porting code between them is a chore.
The challenge is verification. In classical code, if it compiles and passes a unit test, you’re usually fine. In quantum code, a model might generate code that looks perfect but introduces a tiny "phase error" that renders the entire computation useless. Most existing benchmarks are "lazy"—they just check if the text looks right. This paper introduces an execution-verified approach: it actually runs the generated code and compares the resulting quantum state vectors. If the math doesn't match the reference to a fidelity of 0.999, the AI fails.
Methods
The researchers took a "trust but verify" approach:
- Execution-Verified Evaluation: They didn't use an "LLM Judge." They used a physics engine. They executed both the source Qiskit and the target CUDA-Q code, comparing the final quantum states.
- LoRA Fine-tuning: They used Low-Rank Adaptation (LoRA) to train small models (like Nemotron 3 Nano 4B and Qwen2.5-Coder) on a single L4 GPU.
- Negative Control: To prove their evaluator was tough enough, they intentionally corrupted 600 correct translations. They found that simply checking "measurement counts" (a common shortcut) missed 100% of phase-only errors. You must check the state vector.
- Regression Probing: They used QuantumKatas (a set of Qiskit exercises) to see if fine-tuning the model to speak CUDA-Q made it forget how to speak Qiskit.
Datasets
The authors built a robust 640-task benchmark divided into three "generalization splits" to see if the AI could handle more than just what it was trained on:
- Size Test: Can it handle 6–7 qubits if it only saw 2–5 in training?
- Structure Test: Can it handle entirely new types of quantum circuits?
- Style Test: Can it handle "messy" Qiskit code written with different idioms (e.g., using
np.piinstead ofmath.pi, or wrapping code in helper functions)?
They also tested against the QED-C application benchmarks—real-world, complex quantum programs.
Key Insights and Ideas
- The "Alignment Tax" is Real: Fine-tuning a model to be an expert in CUDA-Q makes it significantly worse at its original Qiskit tasks. On the Nemotron 4B model, Qiskit proficiency dropped from 23.8% to a measly 8.9% after tuning.
- Prompting is More Robust to "Messy" Code: If a developer uses weird coding styles (see Table 2 below), a 4-shot prompt often outperforms a fine-tuned model. The fine-tuned model becomes "brittle," expecting the clean, canonical style it saw during training.
- Base Models are CUDA-Q Illiterate: Out of the box, none of the tested base models could write a single valid CUDA-Q kernel. They often hallucinated C++ code that looked like CUDA but wasn't.
- Mixed Replay is the Antidote: By mixing a bit of the original Qiskit training data back into the fine-tuning process ("mixed replay"), researchers could recover most of the lost Qiskit ability without hurting the translation performance.
Key Results
- Qwen2.5-Coder 7B was the star performer, reaching 92.0% accuracy with fine-tuning, significantly beating its 4-shot prompt (82.8%).
- Nemotron 3 Nano 4B was a toss-up: fine-tuning reached 83.9%, while a 4-shot prompt hit 83.1%. Given the "alignment tax," prompting might be the better choice for this smaller model.
- The "Final Boss" (QED-C): Every single model scored 0% on real-world QED-C kernels. While the AI can handle "textbook" circuits, it still chokes on complex programs with branches, loops, and sub-circuits.
Limitations and Future Work
The study was limited to small circuits (up to 7 qubits) and "static" code. It didn't touch mid-circuit measurements or complex classical control flows.
The authors suggest that the next frontier isn't just "line-by-line" translation, but idiomatic porting. A human doesn't just swap Qiskit commands for CUDA-Q commands; they rethink the algorithm to take advantage of GPU features like cudaq.observe. Future benchmarks will need to measure not just "is the state correct?" but "is this code actually efficient?"
Summary updated