AG-CoT: Verified Algorithmic Traces for LLM Program Synthesis on Clifford Circuits
Organizations: Data Science Department, Stony Brook University · Department of Computer Science, Stony Brook University · Dahlem Center for Complex Quantum Systems, Freie Universität Berlin · Westlake University
Abstract
Scientific code generation can produce executable programs that fail to compute the intended scientific object. We study this problem in language-model synthesis of Clifford circuits, which prepare the stabilizer states used in quantum error correction and admit exact classical verification. In our target-conditioned framework, each target is given as compact signed stabilizer generators, and an exact verifier checks the generated OpenQASM circuits. We supervise models with Aaronson-Gottesman chain-of-thought (AG-CoT) traces checked by the verifier, and continue training on model generations that the verifier accepts. Across two independently trained model families (3B and 7B), AG-CoT supervision multiplies greedy-decode state-equivalence accuracy by four to six times over circuit-only baselines, and verifier-filtered continuation training adds a further consistent gain atop both. A complementary 32B study shows that supervised models achieve near-perfect syntax and Clifford validity while the strongest direct model reaches 6.14% state equivalence per target, rising to over 10% under verifier-guided selection with multiple candidates. These results show that algorithmic trace supervision gives a large, statistically significant gain in both model families and that verifier-filtered continuation adds a further repeated gain. The persistent gap between Clifford validity and state equivalence confirms that exact verification is necessary: a circuit can be syntactically and physically valid yet prepare the wrong quantum state.
Figures & tables
| System | Correct/total | Suc(%) |
| Qwen2.5-3B-Instruct | ||
| Base model | 0 / 3,661 | 0.00 |
| Direct SFT | 33 / 3,661 | 0.90 |
| AG-CoT SFT | 201 / 3,661 | 5.49 |
| RFT ver. 1 | 213 / 3,661 | 5.82 |
| RFT ver. 2 | 215 / 3,661 | 5.87 |
| Earlier | Later | Exact | Holm | |
|---|---|---|---|---|
| Comparison | only | only | ||
| Direct SFT to AG-CoT SFT | 2 | 170 | 4.97 10 -48 | – |
| AG-CoT SFT to RFT ver. 1 | 7 | 19 | 0.029 | 0.058 |
| AG-CoT SFT to RFT ver. 2 | 7 | 21 | 0.013 | 0.038 |
| AG-CoT SFT to RFT ver. 3 | 9 | 18 | 0.122 | 0.122 |
| Surface validity | Target match | ||||
|---|---|---|---|---|---|
| System | Syntax | Clifford | Exact@1 lab. | StateEq@1 | 95% CI |
| Zero-shot | 39.9 | 39.9 | 0.10 | 0.33 | [0.15, 0.52] |
| Basic AG-CoT | 99.9 | 99.9 | 2.62 | 5.37 | [4.67, 6.06] |
| Step AG-CoT | 99.9 | 99.9 | 2.31 | 4.83 | [4.15, 5.50] |
| GRPO-v2 | 99.9 | 99.9 | 2.21 | 5.26 | [4.57, 5.98] |
| RFT-v1 | 99.6 | 99.6 | 3.13 | 6.14 | [5.37, 6.91] |
| Model | Criterion | 1 | 4 | 8 | 16 | 32 | 64 |
|---|---|---|---|---|---|---|---|
| RFT-v1 | Label | 3.18 | 3.69 | 4.00 | 4.37 | 4.78 | 5.19 |
| Basic AG-CoT | Label | 2.13 | 2.93 | 3.44 | 3.78 | 4.01 | 4.42 |
| Basic AG-CoT | StateEq | 4.65 | 6.40 | 7.33 | 8.29 | 9.24 | 10.07 |
| System | Errors | Mean deficit | Median deficit | Deficit Count (%) | Deficit Count (%) |
|---|---|---|---|---|---|
| Direct SFT | 3,616 | 8.22 | 9 | 39 (1.08) | 148 (4.09) |
| AG-CoT SFT | 3,425 | 7.66 | 8 | 103 (3.01) | 266 (7.77) |
| RFT ver. 1 | 3,398 | 7.61 | 8 | 121 (3.56) | 278 (8.18) |
| RFT ver. 2 | 3,409 | 7.60 | 8 | 108 (3.17) | 279 (8.18) |
| RFT ver. 3 | 3,416 | 7.57 | 8 | 115 (3.37) | 274 (8.02) |
Appendix figures & tables23 assets
Supplementary material from the paper’s appendix.
Appendix
| Component | Object | Verifier role |
|---|---|---|
| Evaluation source | QCircuitBench Clifford random-circuit instances | Provides targets with exact stabilizer-tableau verification. |
| Prompt target | Signed Pauli generators | Specifies the target state without exposing a reference circuit. |
| Candidate output | OpenQASM 3.0 program | Defines an executable state-preparation circuit from . |
| Strict 32B criterion | , , and | Measures saved-label Exact@1. |
| State-equivalence criterion | , , and | Removes generator-basis sensitivity. |
| Controlled task criterion | StateEq plus gate, qubit, header, and completion requirements | Measures task success in Table 1 . |
| Representation | Model-facing object | Role in this study |
|---|---|---|
| State vector | complex amplitudes | General but long text. |
| Stabilizer-state tableau | Signed Pauli generators; bits before formatting | Compact exact Clifford target. |
| OpenQASM output | Clifford circuit program | Executable candidate. |
| Split or check | Count | Notes |
|---|---|---|
| Accepted AG-CoT examples | 38,940 | Before train/test split. |
| Generation failures | 0 | During AG-CoT construction. |
| Training examples | 35,046 | 90% split. |
| Held-out test prompts | 3,894 | 10% split. |
| Conversion check | 500 | Random tableau/circuit checks. |
| AG validation | 1,000 | Random Clifford tests. |
| Qubits | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Prompts | 30 | 51 | 107 | 145 | 219 | 311 | 367 | 475 | 618 | 702 | 869 |
| Component | Required record | Reproducibility role |
|---|---|---|
| Held-out prompts | 3,894 targets plus metadata | Replay held-out evaluation inputs. |
| Verifier/evaluator | Extraction, Clifford conversion, Exact@1 , StateEq@1 , Pass@ | Recompute reported metrics. |
| AG-CoT construction | Row-reduction traces plus verifier acceptance | Rebuild SFT data. |
| Evaluation records | Commands, evaluated checkpoints, decoding settings, checksums | Identify the evaluated configuration. |
| Dependencies | Qiskit and model-stack versions | Recreate the software environment. |
| Package | 32B study | 3B eval. |
|---|---|---|
| Python | 3.11 | 3.12.3 |
| PyTorch | 2.9.1 | 2.5.1 |
| Transformers | 4.57.6 | 4.52.4 |
| TRL | 0.27.2 | – |
| PEFT | 0.19.1 | – |
| vLLM | 0.15.0 | 0.6.4.post1 |
| System | A6000 | H200 NVL | Shared successes |
|---|---|---|---|
| AG-CoT SFT | 201 | 202 | 201 |
| RFT version 1 | 213 | 213 | 213 |
| Qubits | Targets | Direct SFT | AG-CoT SFT |
|---|---|---|---|
| 3 | 30 | 0 | 3 |
| 4 | 95 | 1 | 8 |
| 5 | 135 | 3 | 12 |
| 6 | 201 | 2 | 10 |
| 7 | 282 | 4 | 16 |
| 8 | 355 | 7 | 29 |
| Family | Checkpoint | Correct / total | Task success (%) |
|---|---|---|---|
| Qwen | Base | 0 / 3,661 | 0.00 |
| Qwen | Direct SFT | 41 / 3,661 | 1.12 |
| Mistral | Base | 0 / 3,661 | 0.00 |
| Mistral | Direct SFT | 78 / 3,661 | 2.13 |
| Qubits | Prompts | Pass@1 (%) | Pass@64 (%) |
|---|---|---|---|
| 2 | 30 | 21.15 | 86.67 |
| 3 | 51 | 7.20 | 21.57 |
| 4 | 107 | 6.57 | 13.08 |
| 5 | 145 | 4.70 | 7.59 |
| 6 | 219 | 3.30 | 4.57 |
| 7 | 311 | 7.11 | 8.04 |
| Run | Samples | Metric | Value (%) |
|---|---|---|---|
| Zero-shot | 1 | Exact / StateEq | 0.10 / 0.33 |
| Basic AG-CoT | 1 | Exact / StateEq | 2.62 / 5.37 |
| Step AG-CoT | 1 | Exact / StateEq | 2.31 / 4.83 |
| GRPO-v2 | 1 | Exact / StateEq | 2.21 / 5.26 |
| RFT-v1 | 1 | Exact / StateEq | 3.13 / 6.14 |
| RFT-v1 Best-of-64 | 64 | Pass@64 | 5.19 |
| Run | Max tok. | Rate (%) | |||
|---|---|---|---|---|---|
| Syntax | Exact@1 | StateEq@1 | Trunc. | ||
| QASM-only SFT | 2048 | 24.91 | 5.50 | 7.68 | 83.00 |
| Event | Errors | Observed | Expected | Std. dev. |
|---|---|---|---|---|
| Deficit at most two | 961 | 112 | 8.84 | 2.45 |
| Sign conflict | 2,581 | 1,335 | 1,639.2 | 16.5 |
| (a) Mean constraint deficit | ||||||
| Cap (%) | Observed (SE) | Empty | Length | Uniform | ||
| 2 | 19 | 0.0 | 1.47 (0.12) | 1.84 | 1.58 | 1.75 |
| 3 | 46 | 0.0 | 2.09 (0.12) | 2.24 | 2.51 | 2.65 |
| 4 | 95 | 0.0 | 3.11 (0.10) | 3.29 | 3.51 | 3.61 |
| 5 | 131 | 0.0 | 3.79 (0.11) | 4.08 | 4.39 | 4.59 |
| 6 | 207 | 0.0 | 4.68 (0.10) | 4.84 | 5.37 | 5.58 |
| Deficit | Nonzero | count | count | Total |
|---|---|---|---|---|
| 1 | 70 | 72 | 142 | |
| 2 | 100 | 92 | 192 | |
| 3 | 106 | 72 | 178 | |
| 4 | 143 | 92 | 235 | |
| 5 | 116 | 88 | 204 | |
| 6 | 153 | 147 | 300 |
| System | Exact | Syntax fail | Non-Cliff. | Label mismatch |
|---|---|---|---|---|
| Basic AG-CoT | 102 | 5 | 0 | 3787 |
| GRPO-v2 | 86 | 5 | 0 | 3803 |
| RFT-v1 | 122 | 17 | 0 | 3755 |
| Layer bucket | Correct / total | Exact@1 (%) | Test share (%) |
|---|---|---|---|
| 1–2 | 35 / 47 | 74.5 | 1.2 |
| 3–5 | 27 / 64 | 42.2 | 1.6 |
| 6–10 | 17 / 132 | 12.9 | 3.4 |
| 11–14 | 5 / 102 | 4.9 | 2.6 |
| 15–20 | 1 / 142 | 0.7 | 3.6 |
| 21–50 | 0 / 664 | 0.0 | 17.1 |
| Direct target match | |||
|---|---|---|---|
| System | Exact@1 lab. (%) | StateEq@1 (%) | 95% CI |
| Zero-shot | 0.10 | 0.33 | [0.15, 0.52] |
| Basic AG-CoT | 2.62 | 5.37 | [4.67, 6.06] |
| Step AG-CoT | 2.31 | 4.83 | [4.15, 5.50] |
| GRPO-v2 | 2.21 | 5.26 | [4.57, 5.98] |
| RFT-v1 | 3.13 | 6.14 | [5.37, 6.91] |
| Run | Exact successes | Exact@1 (%) | 95% CI |
|---|---|---|---|
| Basic AG-CoT | 102 / 3894 | 2.62 | [2.13, 3.13] |
| GRPO-v2 | 86 / 3894 | 2.21 | [1.77, 2.70] |
| RFT-v1 | 122 / 3894 | 3.13 | [2.59, 3.70] |
| Search run | Covered | Missed |
|---|---|---|
| RFT-v1 Best-of-64 | 202 | 3692 |