Language models can now rewrite small quantum programs, but real circuits do not fit in their prompts. A benchmark circuit can exceed 48,000 tokens of OpenQASM, the standard text format for quantum circuits, while a practical fine-tuning window is closer to 6,000. Today the circuit is squeezed in by deleting comments and replacing numbers with symbols. That treats every gate as equally worth showing to the model. On a real quantum chip they are not equally important. Noise varies from qubit to qubit and from one link to the next, so a small fraction of gates, those on poorly calibrated qubits or long-idling wires, accounts for most of the lost fidelity.
We propose to choose what goes into the model's context using a noise estimator that reads the circuit as a graph. A graph model trained on hardware calibration data scores how much each gate contributes to predicted error. We then cut out the connected, causally closed region with the highest total score that still fits the token budget and is narrow enough to verify exactly. The language model rewrites only that region, and the result is checked for equivalence and spliced back. In short, the circuit's dependency graph decides which gates can be taken out together, and the hardware noise decides which of those regions is worth the model's attention. Because selection depends on today's calibration and the rewriter does not, the same trained model can follow noise drift without retraining.
Core Claim
At a fixed token budget, a context built from a noise-attributed causal region of the circuit graph will let a fine-tuned rewriter recover more hardware fidelity than three alternatives: compressed full text, structure-only graph windows, or random regions of the same size. The advantage should grow as noise becomes more uneven across the device. A second, more modest claim is that this selection step is useful whatever rewriter sits behind it. We test that claim directly by giving the same regions to a classical resynthesis tool. If the classical tool does as well as the language model, the contribution is the selection policy, and we will report it that way.
Where This Sits
Three lines of work each supply part of the method. None of them combines the parts.
The closest work is Circuit Partitioning Using Large Language Models for Quantum Compilation and Simulations. It fine-tunes open models with low-rank adapters to imitate BQSKit's Quick Partition heuristic on MQT Bench. It handles over-length circuits by stripping comments and replacing parameters with symbols, and reports 53.39% algorithmic accuracy for Llama-3.1 70B with 100% functional correctness. This paper motivates our work, and it also constrains it in two ways. It shows fine-tuning is necessary, because 1-shot and 5-shot prompting scored 0%. It also exposes the gap we target: the input is flat text, the target imitates a heuristic that ignores noise, and the model never sees calibration data.
The method's ingredients come from two graph-based quantum tools. QuEst represents a circuit as a directed acyclic graph, with gates as nodes and time order as edges. Each node carries calibration features: relaxation and dephasing times, gate errors, and readout error. A graph transformer regresses fidelity from these features, trained on mirror-circuit success probability, with RMSE around 0.04 and R² above 0.95 on real IBM hardware. We reuse this kind of estimator as a scorer, not as an end product. DisMap cuts circuits onto multi-chip hardware so that noisy qubits are avoided, reporting up to 20.8% fidelity gain. It shows that noise-weighted graph partitioning matters, but it uses a fixed heuristic with no learned rewriter.
Two classical-software papers supply the context-management pattern. LEGO splits tensor computation graphs along module boundaries so that each piece fits a prompt, and reports up to 7x lower token use than monolithic prompting. SpIDER expands semantic seed matches through a few hops of the code graph under a fixed token budget, raising Recall@20 by at least 13%. Both choose regions by structure or textual meaning. Neither has a physical cost signal that says which region matters.
Can Large Language Models Understand Intermediate Representations in Compilers? supplies the negative result that rules out "just show it everything." GPT-4 reconstructs control flow graphs fully correctly in only 23.7% of cases, and its execution reasoning falls from 72% on source code to 36% on the equivalent low-level code.
Research Program
Noise estimator and attribution. We train a QuEst-style graph transformer on circuits labeled with mirror-circuit success probability, the scalable fidelity proxy from Quantum Circuit Transformations with a Multi-Level Intermediate Representation Compiler. Labels come from noisy simulators driven by real IBM calibration snapshots, plus a smaller set of hardware runs.
For each gate $v$ in circuit graph $G$ we define an attribution score
$$a_v = \hat F(G;\, \epsilon_v \to 0) - \hat F(G),$$
where $\hat F$ is the estimator's predicted fidelity and $\epsilon_v \to 0$ means the error and decoherence features on node $v$ are zeroed while the graph structure is kept. The score is the predicted fidelity we would gain if that gate were perfect. Computing it costs one batched forward pass per circuit, which matters because the estimator is reported to be 200x to 1,700x faster than noisy simulation.
Region selection. We select a region $R$ of the graph that is closed under the gates it contains: every path between two gates in $R$ stays inside $R$, so it can be removed and reinserted as a single block. The selection solves
$$\max_R \sum_{v \in R} a_v \quad \text{subject to} \quad \mathrm{tokens}(R) \le B,\;\; \mathrm{width}(R) \le w,$$
where $B$ is the token budget and $w$ is the number of qubits the region touches. We cap $w$ at about 8 to 10 qubits. At that size the region's unitary can be computed and compared exactly on a classical machine. That is what makes every rewrite verifiable rather than trusted. We solve the selection greedily, growing outward from the highest-scoring gate along qubit wires, and iterate: select, rewrite, splice, re-score.
Rewriter. We fine-tune an open model (Llama-3.1 8B, the size the circuit-partitioning study found only about 1.7% behind 70B) in two stages. The first stage is supervised warm-up on region pairs produced by classical resynthesis. The second is reinforcement learning with group relative policy optimization, following the online fine-tuning loop in GAE. The reward is zero if the exact equivalence check fails. Otherwise it is the predicted fidelity gain after the region is placed on its assigned physical qubits. The prompt contains the region's text, a short header listing the physical qubits and their calibration values, and the boundary wires. It never contains the rest of the circuit.
The reinforcement stage is what separates this from imitating a heuristic. The model is rewarded for reducing error on the noisy part of the chip, not for agreeing with Quick Partition.
Baselines
The naive reference point is the circuit after standard transpilation onto the target device with noise-aware qubit placement and no further rewriting. Every other condition starts from this circuit, so all gains are measured against the same compiled input.
The strongest existing language-model method is the text-compression pipeline from Circuit Partitioning Using Large Language Models. We apply its comment stripping and symbolic parameters, then cut the text into consecutive chunks of $B$ tokens. Each chunk goes to the same rewriter, trained with the same data, reward, and update budget. That paper reports 53.39% algorithmic accuracy and 100% functional correctness for its task. It reports no fidelity number, so our comparison uses our own measured fidelity. Beating it means higher mirror-circuit success probability at equal total tokens processed.
The structure-only ablation isolates the noise ingredient. It uses the same closure and width constraints but chooses regions in causal order, as in LEGO's boundary-based splitting, or by hop distance from the highest-error gate, as in SpIDER's expansion, ignoring the attribution scores. A random-region control matches region count and size. A shuffled-calibration control computes attributions from a different device's calibration. If that control does as well as ours, the scores are not carrying information about the real noise.
The LLM-free ablation is the most important comparison. It sends our selected regions to BQSKit resynthesis under a matched wall-clock budget. A tie means the selection policy is the contribution. The LLM rewriter counts as winning only if it beats this ablation by a margin larger than the variation across random seeds and calibration days.
Fairness is enforced in four ways. All conditions use the same circuits and calibration snapshots. Every language-model condition uses the same backbone, adapter rank, training budget, and number of reinforcement steps. Total tokens processed per circuit are matched. Hyperparameter search gets an equal number of trials per condition.
Why not just…?
Why not just use a long-context model and paste in the whole circuit? RepoDebug reports that debugging accuracy drops as code length grows, and the compiler-representation study shows models losing track of global state in verbose low-level code. Neither tests quantum circuits, so we add a direct condition. For circuits that fit in a long window, the same backbone receives the full compressed circuit. We report whether its fidelity gain matches ours at higher token cost or falls below.
Why not just prompt a strong model with a few examples? The circuit-partitioning study found 1-shot and 5-shot prompting scored 0%, with models often echoing their input unchanged. We include one few-shot frontier-model run on our regions as a sanity check, but we expect the same result.
Why not just skip the language model and use classical compilers? This is a real threat. Noise-aware placement in the style of QuantumNAS, DisMap-style cutting, and BQSKit resynthesis are deterministic and strong. Our LLM-free ablation exists for exactly this reason. If resynthesis on our regions matches the rewriter, we will say so and recommend noise-attributed selection as a way to direct classical synthesis effort. The language model has to earn its place through the case where it plausibly helps: regions with parameterized or problem-specific structure where generic synthesis stalls.
Why not just retrieve context with text embeddings? Lines of OpenQASM such as cx q[3],q[4] are nearly identical as text. Text similarity cannot tell a gate on a noisy link from one on a clean link. SpIDER found that even in ordinary software, dense retrieval misses structurally adjacent code. We include an embedding-retrieval condition at the same budget and expect it to perform near the random-region control.
Proposed Experiments
Circuits and devices. Circuits come from MQT Bench across GHZ, Grover, QFT, QAOA, and VQE families, from 10 to 60 qubits, including the instances beyond 48,000 tokens. Devices are noisy simulators driven by calibration snapshots of the five IBM machines used in QuEst, with a hardware subset for confirmation. The 120-program IBM Quantum Challenge set used by QDFO serves as a held-out family. QDFO reports no fidelity result, so this set is used only for generalization.
Metrics. We measure mirror-circuit success probability on simulators and hardware, true fidelity on circuits small enough to simulate exactly, two-qubit gate count, equivalence pass rate, and tokens per unit of fidelity gained.
Check 1: attribution validity. Before any rewriting, we test whether the scores reflect real noise. On a simulator, we make individual gates noise-free one at a time and measure the actual fidelity change. We then correlate that change with $a_v$. If the rank correlation is weak, the rest of the program is not supported by this estimator.
Check 2: fixed-budget advantage. We sweep the token budget $B$ from 1,000 to 6,000. At each budget we compare noise-attributed regions with structure-only, random, and shuffled-calibration regions. The core claim predicts an advantage that shrinks as $B$ grows, since at large budgets every policy covers most of the circuit. It should also grow with the spread of two-qubit error rates across the device, which we vary by using different calibration snapshots.
Check 3: drift. We train on calibrations from one set of days and test on later days. Selection is recomputed from fresh calibrations while the rewriter stays frozen. The comparison is a policy that keeps the stale selection. If fresh selection with a frozen rewriter recovers most of the gap, adapting to drift costs one estimator pass instead of a new architecture search.
Check 4: LLM versus classical resynthesis on identical regions. This comparison decides how the contribution is framed: as a better context policy for language models, or as a selection method worth using with any optimizer.
References
- Circuit Partitioning Using Large Language Models for Quantum Compilation and Simulations
- QuEst: Graph Transformer for Quantum Circuit Reliability Estimation
- Hardware-aware Circuit Cutting and Distributed Qubit Mapping for Connected Quantum Systems
- LEGO: An LLM-Enabled Hierarchical Optimizer for Tensor Computation Graphs with Structure-Aware Search and Compositional Synthesis
- SpIDER: Spatially Informed Dense Embedding Retrieval for Software Issue Localization
- Can Large Language Models Understand Intermediate Representations in Compilers?
- Quantum Circuit Transformations with a Multi-Level Intermediate Representation Compiler
- GAE: Graph-Augmented Evolution for Scientific Discovery via Reinforcement Optimization
- RepoDebug: Repository-Level Multi-Task and Multi-Language Debugging Evaluation of Large Language Models
- QuantumNAS: Noise-Adaptive Search for Robust Quantum Circuits
- Dataflow-Based Optimization for Quantum Intermediate Representation Programs