When Does Fine-Tuning Beat Prompting for Qiskit-to-CUDA-Q Translation? An Execution-Verified Study
Organizations: Red Hat
Abstract
Moving quantum code from Qiskit to NVIDIA CUDA-Q is a practical adoption cost that language models are starting to automate. We ask whether a small open model can learn this translation, and how to measure it so that the result can be trusted. Both programs can be executed and their state vectors compared, so a kernel counts as correct only if it prepares the same state as the Qiskit reference (fidelity >= 0.999), with no text matching and no LLM judge. We build a 640-task benchmark with three test sets (larger circuits, an unseen circuit family, an unseen Qiskit coding style) and a QuantumKatas regression probe, and we test the evaluator before training. Measurement counts miss every phase-only error; a surface rule-based translator solves two of three original splits (text substitution); a converter that executes the Qiskit input and maps the circuit solves all 640 tasks -- so the benchmark measures source-level translation, not whether a circuit can be ported after running it. No base model emits a valid CUDA-Q kernel zero-shot. On Nemotron 3 Nano 4B, LoRA reaches 83.9%, tying a 4-shot prompt (83.1%), but generalizes worse to unseen style (48.5% vs. 65.5%) and cuts QuantumKatas from 23.8% to 8.9%; on Qwen2.5-Coder 7B, LoRA beats the prompt overall (92.0% vs. 82.8%) and on unseen style (78.5% vs. 65.0%), and on the 1.5B model as well, so whether fine-tuning pays off depends on the base model, while the Qiskit regression appears in all three. Mixing two replay formats is the best mitigation trade-off (84.4% translation, Katas 21.5%). On 48 parametric functions that must become kernels with arguments -- where executing the input cannot yield a parametric kernel -- models reach up to 83%; on 27 real QED-C kernels, every model scores 0%. Language models can do source-level translation of simple parametric code, but not yet of real programs.
Figures & tables
| Split | Pairs | Content | Question |
|---|---|---|---|
| Train / validation | 1,355 / 151 | random, GHZ, W, QFT, Grover; 2–5 qubits | |
| Size test | 240 | same families, 6–7 qubits | generalization in size? |
| Structure test | 200 | hardware-efficient ansatz, never seen | generalization in structure? |
| Style test | 200 | test circuits rewritten with common Qiskit idioms | generalization in coding style? |
| Idiom | What changes on the Qiskit side |
|---|---|
| nome | circuit variable is not named qc |
| registro | QuantumRegister and indices qr[i] |
| difusao | multi-target one-qubit calls, e.g. h([0, 2]) / h(range(n)) |
| append | gate objects, e.g. append(RYGate( ), [q]) |
| funcao | body wrapped in a helper that takes the circuit |
| barreira | barrier() in the middle |
| Setting | Value | Why |
|---|---|---|
| Rank / alpha | 32 / 64 | enough capacity for a narrow task |
| Target modules | attention (q, k, v, o) and MLP (up, down) | PEFT rejects LoRA on the Mamba out_proj / conv1d of this model, and vLLM does not map LoRA onto the fused Mamba in_proj |
| Effective batch | 16 | about 170 optimizer steps over 2 epochs |
| Learning rate | , 5% warmup, cosine | common range for LoRA; not tuned |
| Loss | completion only | do not learn to repeat the prompt |
| Checkpoint | lowest validation loss (step 160 of 170) | selected without looking at the test sets |
| Surface rules | Circuit conv. | Base | Base + 4-shot | Fine-tuned (LoRA) | |
|---|---|---|---|---|---|
| Valid output | |||||
| All (640) | 68.8% | 100% | 0% | 91.4% [89.0–93.3] | 84.2% [81.2–86.8] |
| State equivalence | |||||
| Larger circuits (240) | 100% | 100% | 0% | 89.6% | 100% [98.4–100] |
| Unseen family (200) | 100% | 100% | 0% | 93.0% | 100% [98.1–100] |
| Unseen style (200) | 0% | 100% | 0% | 65.5% [58.7–71.7] | 48.5% [41.7–55.4] |
| All tasks (640) | Unseen style (200) | W family | HEA family | |
|---|---|---|---|---|
| Set 0 (original) | 83.1% | 65.5% | 77% | 93% |
| Set 1 | 81.9% | 63.5% | 83% | 92% |
| Set 2 (no rx / ry ) | 48.3% | 38.0% | 0% | 35% |
| Set 2, random example covering all gates | 71.9% | 58.5% | 57% | 73% |
| LoRA (reference) | 83.9% | 48.5% |
| Category | Base | 4-shot | LoRA | Replay (script) | Styles (A) | Replay (function, B) |
|---|---|---|---|---|---|---|
| No CUDA-Q kernel | 358 | – | 3 | 2 | – | – |
| CUDA C instead of CUDA-Q | 193 | – | – | – | – | – |
| Truncated | 89 | 9 | 1 | – | 1 | 2 |
| Qiskit API in kernel ( qc. ) | – | – | 42 | – | – | 31 |
| Qiskit construct copied ( barrier , measure_all ) | – | 13 | 19 | 38 | – | 44 |
| Qiskit gate class ( X , CRY ) | – | – | 14 | – | 39 | 1 |
| All tasks (640) | Unseen style (200) | Held-out idioms (120) | QuantumKatas (349) | |
|---|---|---|---|---|
| Nemotron 4B, LoRA seed 0 / 1 / 2 | 83.9 / 82.5 / 80.2% | 48.5 / 45.0 / 37.0% | 27.5 / 29.2 / 15.8% | 8.9 / 6.9 / 7.4% |
| Nemotron 4B, LoRA + style variety (A) | 85.3% | 53.0% | 21.7% | 7.4% |
| Nemotron 4B, LoRA s0 + GRPO (200 steps) | 86.9% | 59.5% | 35.8% | 8.6% |
| Nemotron 4B, LoRA s0 + 1-shot / 2-shot prompt | 74.8 / 78.4% | 40.0 / 46.5% | 31.7 / 43.3% | — |
| Nemotron 4B, base, 4-shot | 83.1% | 65.5% | 59.2% | 23.8% |
| Qwen2.5-Coder 1.5B, base, 4-shot | 50.5% | 19.5% | 19.2% | 17.8% |
| Valid kernel | Equivalent at all three settings | |
|---|---|---|
| Circuit-level converter (executes with the first setting) | 0% | 0% |
| Nemotron 4B, base, zero-shot | 0% | 0% |
| Nemotron 4B, base, 4-shot | 52% | 48% |
| Nemotron 4B, LoRA | 73% | 63% |
| Nemotron 4B, LoRA + GRPO | 85% | 71% |
| Nemotron 4B, LoRA + mixed replay | 92% | 83% |
| State equivalence | Base + 4-shot | LoRA | + replay, script | + style variety (A) | + replay, function (B) | + replay, mixed |
|---|---|---|---|---|---|---|
| Training style (size 240 / family 200) | 89.6% / 93.0% | 100% / 100% | 100% / 99.0% | 100% / 100% | 100% / 99.5% | 99.6% / 97.5% |
| Unseen style (200) | 65.5% | 48.5% | 53.0% | 53.0% | 37.0% | 53.0% |
| idioms seen in A’s training (80) | 75.0% | 80.0% | 53.8% | 100% | — | 60.0% |
| held-out idioms append / helper function (120) | 59.2% | 27.5% | 52.5% | 21.7% | — | 48.3% |
| All translations (640) | 83.1% | 83.9% | 85.0% | 85.3% | 80.2% | 84.4% |
| QuantumKatas (349) (base 23.8%) | 23.8% | 8.9% | 15.2% | 7.4% | 20.3% | 21.5% |
| Qiskit | Idiomatic CUDA-Q |
|---|---|
| Estimator with a SparsePauliOp observable | cudaq.observe(kernel, spin_op, ...) with cudaq.spin |
| circuit.inverse() , compose() | cudaq.adjoint(kernel, ...) , kernels calling kernels |
| Parameter and assign_parameters in an optimization loop | kernel arguments with cudaq.observe inside the optimizer, or cudaq.vqe |
| Mid-circuit measurement with if_test / c_if | mz and an ordinary if inside the kernel a |
| Sweeps over many parameter values | batched observe / sample calls and GPU or multi-QPU targets |
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.
Appendix
| Category | LoRA | + mixed replay | + GRPO | + 2-shot prompt | Qwen 1.5B LoRA | Qwen 7B LoRA |
|---|---|---|---|---|---|---|
| Qiskit construct copied ( barrier , measure_all ) | 19 | 47 | – | 36 | 110 | 34 |
| Invented gate ( r_y ) | 12 | 28 | 12 | 30 | 6 | – |
| Qiskit gate class ( X , CRY ) | 14 | – | 44 | 14 | – | – |
| Qiskit API in kernel ( qc. ) | 42 | – | – | 1 | – | – |
| Qiskit gate name ( cx , cp ) | – | 1 | 1 | 1 | – | – |
| Raw integer indices | – | 1 | 3 | – | – | – |