WorksPhysics and Astronomy
Multimodal Generative Quantum Circuit Optimization with Verifier-Guided Reinforcement Learning
Abstract
Quantum circuit optimization replaces a circuit with an equivalent one using fewer costly operations: two-qubit gates, which dominate error on noisy hardware, and non-Clifford gates, which dominate fault-tolerant overhead. We formulate this task as graph-conditioned sequence-to-sequence generation and introduce \method{} (Graph-Augmented Fusion Transformer for Quantum circuit optimization), a multimodal GNN-Transformer that jointly encodes a source circuit's gate-token sequence and simplified ZX diagram in a Transformer encoder and autoregressively generates an optimized circuit. The model is first pretrained by supervised learning on millions of verified triples of a random source circuit, its simplified ZX diagram, and a target circuit optimized by PyZX. It is then fine-tuned by reinforcement learning: a verifier checks whether each generated circuit is equivalent to the reference circuit, and a reward function scores its gate-count reduction relative to that reference. We compare Group Relative Policy Optimization (GRPO) with Maximum-Likelihood Reinforcement Learning (MaxRL), whose binary-reward objective we generalize to continuous non-negative rewards, and propose a Hybrid advantage estimator that combines the strengths of both. A size curriculum further extends training from short (20–100-gate) circuits up to 300 gates on 5–20 qubits. On held-out benchmarks, verifier-guided RL with curriculum training raises equivalence accuracy (pass@8) on 20–100-gate circuits from under supervised learning to while surpassing PyZX in two-qubit gate reduction and nearly matching its -gate counts, and scales optimization to 300-gate circuits while generalizing to deeper unseen circuits.
Keywords
quantum circuit optimization, quantum compilation, ZX-calculus, sequence-to-sequence learning, graph neural networks, reinforcement learning, GRPO, maximum-likelihood RL
Introduction
Quantum computers promise speedups for problems such as integer factoring [1], unstructured search [2], and the simulation of quantum many-body systems and molecules [3]. Over the past decade the hardware has moved from proof-of-principle devices to processors with tens to hundreds of qubits. The first logical-qubit experiments have demonstrated surface-code memories below the error-correction threshold [4] and programmable logical processors on neutral atoms [5]. At the same time, resource estimates for cryptographically relevant algorithms keep falling as algorithms and compilation improve [6, 7]. In both the noisy intermediate-scale quantum (NISQ) regime [8] and the emerging fault-tolerant regime, the gate count and gate composition of a compiled circuit largely determine whether execution is feasible in practice.
Turning an algorithm into operations on a device is the task of quantum compilation. A compiler translates a hardware-independent circuit into an executable one: it decomposes high-level operations into a native gate set, maps logical to physical qubits and inserts routing operations to respect connectivity [9, 10], and applies semantics-preserving optimizations such as peephole output. Production toolchains such as Qiskit [11], t|ket⟩ [12], and PyZX [13], together with formally verified optimizers such as VOQC [14], implement these stages as pipelines of passes. Their cost models depend on the regime. On NISQ hardware, two-qubit gates incur substantially higher error rates than single-qubit gates, so the two-qubit gate count largely determines circuit fidelity. Under fault tolerance, non-Clifford gates are intrinsically more resource-intensive than Clifford operations: the Eastin–Knill theorem precludes transversal in most codes [15], so gates generally require code switching [16] or magic state preparation techniques [17, 18, 19], making -count a dominant cost metric.
Within this compilation stack, circuit optimization seeks a circuit that implements the same unitary as the input, up to a global phase, while using fewer costly gates. This problem is computationally intractable: exact optimization is NP-hard in general, and even approximate optimization remains hard under natural cost metrics [20]. Moreover, circuit representations are highly non-unique: commuting gates can be reordered, identities can be inserted or cancelled anywhere, and a single unitary admits exponentially many implementations, so simplifications that are invisible locally may only emerge once distant gates are brought together. Every reduction in gate count directly lowers execution error on noisy hardware or resource overhead under fault tolerance, making circuit optimization a critical stage of quantum compilation.
Existing approaches to circuit optimization include rule-based rewriters and heuristic search methods [12, 14, 21, 22, 23, 24, 25, 26], ZX-calculus simplification [27, 28, 29, 30], reinforcement-learning methods that select sequential transformations [31, 32, 33, 34, 35, 36, 37], and generative models that synthesize an optimized circuit directly, among others. Generative models offer a key structural advantage: by synthesizing an optimized circuit end-to-end, they can directly capture global circuit structure. Transformers, in particular, process the entire input globally so that each output gate can depend on arbitrarily distant gates in the source. Diffusion and flow-based models synthesize circuits from target unitaries [38] or transport source circuits to optimized equivalents [39], while large language models have been fine-tuned to generate circuits [40]. However, purely generative approaches also face significant challenges: for autoregressive models, the accuracy of generating equivalent circuits drops rapidly as circuit length grows [41], and without an explicit correctness signal their output validity is difficult to guarantee.
In this work, we adopt an encoder–decoder Transformer framework for quantum circuit optimization. A circuit is naturally represented as a sequence of gate tokens (e.g., HAD_2, T_5, or CNOT_3_7) drawn from a finite vocabulary, similar to gate statements in Open-QASM [42]. Source and target circuits share this vocabulary, casting circuit optimization as a sequence-to-sequence (Seq2Seq) task. However, a plain Seq2Seq model is insufficient. First, a flat token sequence obscures the two-dimensional qubit connectivity of the source circuit. Second, autoregressive decoding suffers from error accumulation under supervised training alone [41].
We address both limitations with GraftQ and a post-training framework (Figure 1; headline results in Table 1) built on the following contributions:
| System | pass@8 | all | 2Q | better (2Q) | |
| PyZX reference [13] | 14.35 | 0.84 | 6.26 | ||
| GraftQ (SFT) | 67.7% | 14.39 | 0.84 | 6.26 | 0.1% |
| GraftQ (SFT + Hybrid RL) | 83.5% | 15.71 | 1.07 | 6.25 | 21.8% |
| GraftQ (+ Curriculum) | 94.1% | 15.81 | 1.07 | 6.24 | 23.6% |
Table 1. Table 1: Headline comparison on 9,000 held-out 20–100-gate circuits (5–20 qubits, , ). Gate reductions are relative to the source on the three-model common success set (; full breakdown in Table 5); better (2Q) is the fraction of each model’s solved circuits with strictly fewer 2Q gates than PyZX (§ 6.3).

Figure 1. GraftQ pipeline. Components introduced in this work are shaded lavender; standard steps and existing tools are shaded gray. (1) A random source circuit is simplified into a ZX diagram and extracted by PyZX to produce a reference circuit . (2) A GNN-Transformer takes both the source token sequence and the simplified ZX diagram as input and is pretrained to generate . (3) The pretrained policy is fine-tuned by RL: it samples candidate circuits per input, a random-state verifier tests whether each candidate is equivalent to , a reward function scores gate reduction relative to , and GRPO, continuous MaxRL, or the Hybrid advantage estimator updates the policy across a curriculum of increasing circuit sizes.
A multimodal GNN-Transformer (§ 3.2). Each source circuit is paired with its simplified ZX diagram, which captures the topological structure of the original circuit. A graph convolutional network embeds the nodes of the diagram, and its node embeddings are concatenated with the gate-token embeddings of the original circuit. A shared Transformer encoder then processes both modalities before an autoregressive decoder generates the optimized circuit.
RL with an automatic verifier (§ 3.4–§ 3.6). Circuit equivalence can be verified automatically, placing circuit optimization alongside mathematical reasoning and code generation, where verifiable rewards have enabled substantial gains through reinforcement learning [43, 44, 45]. Hence, we follow the pretrain-then-RL approach of modern language models [46] and fine-tune the pretrained model with a random-state verifier, which propagates a single Haar-random input state through each generated circuit and the reference circuit to test whether they are equivalent. The reward combines output-state fidelity (for incorrect candidates) with gate-count reduction relative to the reference (for verified candidates), strictly prioritizing equivalence over gate reduction.
Continuous MaxRL and a Hybrid advantage estimator (§ 3.6, Appendices B–C). We adapt GRPO [44] and MaxRL [47] to this graded reward, extending MaxRL from binary to continuous non-negative rewards. We further propose a Hybrid estimator that applies MaxRL weighting to groups containing incorrect candidates and GRPO normalization to all-correct groups, automatically shifting each input from learning equivalence to reducing gate count as accuracy improves.
Curriculum learning over circuit size (§ 4–§ 5). To further alleviate autoregressive drift, we train on millions of verified (source circuit, ZX diagram, PyZX reference) triples on 5–20 qubits with a two-stage curriculum over circuit size. Starting from circuits with 20–100 gates, the curriculum progressively extends training through 101–200 to 201–300 gates without degrading short-circuit accuracy, and we evaluate length generalization on unseen circuits with 301–400 gates.
Background and Related Work
Quantum circuits and their optimization
An -qubit pure state is a unit vector with , and a quantum gate acts on it by a unitary matrix [3]. A circuit is a sequence of gates, each acting on one or more qubits, whose combined action is the unitary . We work with the gate set
where is a -axis phase rotation and . This gate set covers both our source circuits and the circuits extracted by PyZX [13]. Up to global phase, , , and . Hadamard, , and CNOT generate the Clifford group, and adding the non-Clifford gate makes the set approximately universal (Clifford+) [17]. counts as non-Clifford every gate and every phase whose angle is an odd multiple of .
Two circuits are equivalent, written , when their unitaries differ by at most a global phase:
Let , , and denote the total, two-qubit, and non-Clifford gate counts, and let be a cost with non-negative weights. GraftQ targets
where is the set of finite circuits over on the same qubits. Optimizing individual gate counts in Clifford+ circuits is NP-hard [20]. Even checking a candidate is hard: deciding worst-case approximate equivalence in operator norm (up to global phase) is QMA-complete [48], and a dense comparison of unitaries needs memory. We therefore study a learned, amortized approach: a conditional generator proposes candidates, a verifier checks equivalence, and reinforcement learning rewards lower . Because the optimum of Eq. (3) is unknown, we measure progress against a PyZX reference using
where positive values mean the generated circuit uses fewer gates than the reference.
The ZX-calculus represents a circuit as a graph of spiders with phases, connected by plain or Hadamard edges [27, 30]. Graphical rewrite rules preserve semantics and can remove large numbers of spiders, revealing global structure that a flat gate sequence obscures. Extracting a simplified diagram back into a circuit, however, is efficient when the diagram has generalized flow [49] but #P-hard in general [50], and extraction can introduce additional CNOT gates [51]. Rather than relying solely on direct circuit extraction as the final output, GraftQ conditions on the simplified diagram alongside the source circuit.
Related work on circuit optimization
Rule-based optimizers apply gate cancellation, commutation, peephole rewrites, and template matching [12, 14, 21, 22], while search-based superoptimizers such as Quartz, QUESO, Quanto, and GUOQ combine synthesized rewrite rules with heuristic search to explore equivalent circuits [23, 24, 25, 26]. ZX-calculus methods [28, 29] are among the strongest -count optimizers.
Reinforcement-learning methods learn which circuit transformation to apply next. Fösel et al. apply deep RL to local circuit rewrites [31]. Quarl learns a GNN policy over Quartz rewrites [32]. Several works act on ZX diagrams: GNN policies trained with PPO [52] choose ZX rewrites [34, 35], and tree search with GNNs finds CNOT-reducing combinations [36]. Kremer et al. train RL agents for Clifford-circuit synthesis and transpilation [33], and AlphaTensor-Quantum reduces -count through tensor decompositions [37]. These methods preserve equivalence by construction, but are bounded by their action libraries and rewrite-trajectory length.
A third line of work generates optimized circuits directly. Charton et al. train Transformers to rewrite ZX diagrams [53]. Diffusion models synthesize circuits from a target unitary [38] or transport source circuits to optimized equivalents [39]. LLMs have been fine-tuned to write and optimize quantum programs [40, 54]. Closest to our setting, Saeedi et al. find that the equivalence accuracy of autoregressive circuit generation drops sharply as output length grows [41].
Specifically, autoregressive sequence-to-sequence (Seq2Seq) models map an input sequence to an output sequence
parameterized here by an encoder–decoder Transformer [55]. Tokenizing gates on explicit qubits casts circuit optimization into this framework, where each input circuit admits many equivalent target sequences. Standard maximum-likelihood training against a single reference circuit, however, optimizes token-level cross-entropy rather than unitary equivalence or gate cost, penalizes alternative lower-cost implementations, and relies solely on a one-dimensional input sequence. These limitations motivate conditioning the encoder on ZX graph structure and post-training the generator with verifier-guided reinforcement learning (§ 3).
Model and Training
GraftQ is a conditional generator . The input pairs the token sequence of a source circuit with a ZX diagram of that circuit. The output is the token sequence of a candidate optimized circuit . This section describes how circuits and diagrams are encoded (§ 3.1), the GNN-Transformer (§ 3.2), masked decoding (§ 3.3), the verifier and reward (§ 3.4), supervised pretraining (§ 3.5), and reinforcement learning with GRPO, MaxRL, and Hybrid advantages (§ 3.6).
Circuit and diagram representation
For the circuit modality, each token represents one gate acting on explicit qubit indices: single-qubit gates NAME_q, two-qubit gates NAME_c_t (control, then target), and phase rotations RZ(l/4)_q. Combining (with , written HAD, NOT) and (, reduced to lowest terms) across up to qubits, CNOT and CZ on ordered qubit pairs, and four framing symbols (<pad>, <unk>, <bos>, <eos>) yields tokens (retaining overlapping gate notations so both and PyZX outputs map directly without rewrites). Source and target circuits share this vocabulary and are wrapped as <bos><eos>; for instance, the three-qubit fragment CNOT CZ is tokenized as
<bos> HAD_0 CNOT_0_1 T_1 RZ(3/4)_2 CZ_1_2 <eos>.
Unlike subword-tokenized QASM text, this gate-level vocabulary keeps each gate and its qubits in a single symbol, sets sequence length to gate count plus two, and supports exact qubit-range masks (§ 3.3).
Each vertex of the simplified ZX diagram (§ 4) is represented by a -dimensional feature vector
concatenating a spider-type one-hot vector (distinguishing Z spiders from other vertices), a boundary one-hot vector (identifying input qubit , output qubit , or an internal spider), and the sine and cosine of the spider phase .
GNN-Transformer
Figure 2 illustrates the model architecture: an encoder–decoder Transformer whose encoder processes two input modalities, analogous to vision–language models that pair a visual encoder with a language model [56], except that the second modality here is a graph.

Figure 2. GNN-Transformer architecture. A GCN embeds the ZX diagram and an embedding layer maps the source gate tokens to vectors. The two sequences are concatenated and encoded by a Pre-LN Transformer encoder. A Pre-LN decoder cross-attends to the encoder memory and generates the optimized circuit one token at a time (dashed: autoregressive feedback), with a qubit-count mask restricting outputs to valid gates.
In the graph branch, graph-convolutional (GCN) layers [57], each followed by a ReLU activation, map the node features to the model dimension . Each layer adds self-loops and aggregates messages along the edge-indexed edges in the edge index (providing a topological prior while supplies exact gate and boundary-Hadamard semantics), combining each vertex’s spider type, boundary indicator, and phase with features from neighboring spiders. Ordering vertices by PyZX index, the resulting node embeddings are packed into a sequence .
The source tokens of length are embedded and scaled as , then concatenated with the graph embeddings along the sequence dimension:
with a padding mask over the combined sequence. is processed by a stack of Pre-LN Transformer encoder layers [55, 58] followed by a final LayerNorm, producing the encoder memory . Rotary position embeddings (RoPE) [59] are applied in every self-attention layer across the concatenated sequence, allowing gate tokens and ZX spiders to attend to one another from the first layer onward.
The decoder is a stack of Pre-LN Transformer layers, each applying causal self-attention with RoPE, cross-attention to , and a feed-forward network. A linear output head produces logits ; encoder, decoder, and output embeddings are untied. Architectural hyperparameters (layer counts, attention heads, hidden dimensions, and total parameter count) are listed in Table 6. Supervised training uses teacher forcing on the shifted target sequence, .
| parameter | value |
| 1024 | |
| encoder layers | 8 |
| decoder layers | 8 |
| attention heads | 16 |
| head dimension | 64 |
| FFN width | 2048 |
| FFN activation | ReLU |
| normalization position | Pre-LN |
| position encoding | RoPE (self-attention only) |
| dropout | 0 |
| GCN layers | 4 |
| GCN in-features | |
| GCN intermediate / out | 1024 |
| vocab size | 984 |
| max qubits | 20 |
| total parameters | ≈174M |
Table 6. Model architecture hyperparameters.
Decoding with validity masks
Because the vocabulary covers up to qubits, for an -qubit circuit () any token acting on a qubit index is invalid. For each we precompute the valid subset of tokens whose qubit indices are strictly less than (plus <eos>), and sample from the masked distribution
at temperature . Restricting support to (e.g., 95 active gate tokens at ) guarantees that every sampled sequence parses into a syntactically valid -qubit circuit. During RL rollouts we sample from the full valid support at without top- or nucleus truncation.
Verification by Haar-random state evolution
Constructing dense unitaries is infeasible at 20 qubits, so the verifier instead compares circuits by evolving a random input state. For each input circuit, it draws a Haar-random state , evolves it through both the reference and each candidate circuit using the state-vector simulator Qulacs [60], and computes the state fidelity
A candidate is marked correct if with ; unparseable sequences receive . Because each reference has already been verified against (§ 4), equivalence to implies equivalence to . Taking the squared modulus in Eq. (9) quotients out any global phase, matching Eq. (2). Simulating an -gate circuit requires time, compared with memory merely to store a dense unitary.
This test is grounded in the relation between average state fidelity and process fidelity [61, 62] (Appendix § 14). With and , the two circuits are equivalent up to global phase if and only if the process fidelity equals one. For a Haar-random state , is an unbiased estimator of the average state fidelity , which satisfies
For , the scaling factor lies in , so expected single-state infidelity closely tracks process infidelity at the cost of one state-vector simulation. Although bounding worst-case false acceptance statistically requires many independent Haar-random states (Appendix § 14), empirically we find that inequivalent candidates are consistently rejected already by a single Haar-random state: among the 32,000 candidates evaluated in § 6.1, the first random state () rejected all 11,296 inequivalent candidates.
To guide RL post-training, the reward function ranks every correct candidate above every incorrect one, and among correct candidates it ranks by gate reduction relative to the reference (Eq. (4)).
For a candidate sequence decoding to , let and
with non-negative weights emphasizing two-qubit and gates (Appendix § 11). The reward is
with (success bonus) and (failure scale). Correct candidates score in and incorrect ones in . The condition guarantees the lexicographic order, and failures still receive a dense fidelity signal. The reward is non-negative, which MaxRL requires (§ 3.6).
Supervised pretraining
The policy is first trained by maximum likelihood on (source, diagram, reference) triples:
averaged over non-padding tokens. Supervised pretraining enables the model to learn valid circuit syntax, align gate tokens with ZX spiders, and approximate the PyZX optimization pipeline end-to-end. Because Eq. (13) maximizes token-level likelihood against a single reference, however, it penalizes alternative equivalent circuits and provides no direct incentive for further gate reduction. Reinforcement learning fine-tuning overcomes both limitations.
Reinforcement learning with group-relative advantages
At each step we sample a batch of inputs , draw a group of candidates per input on a shared random state , and evaluate them via the verifier and Eq. (12) to obtain rewards . A critic-free advantage estimator maps each group of rewards to scalar weights , and we perform one on-policy update minimizing
We consider three advantage estimators (GRPO, MaxRL, and Hybrid), which compute from the group mean and sample standard deviation .
GRPO: ,
MaxRL: ,
Hybrid:
for small numerical guards . Algorithm 1 summarizes the procedure.
GRPO [44] normalizes centered rewards by the group standard deviation, making updates invariant to positive affine transformations of the reward. For a binary reward with pass probability
Algorithm 1 RL fine-tuning of GraftQ
Require: pretrained policy , data mixture , group size , estimator
, its expected gradient per input scales as , concentrating weight on inputs of intermediate difficulty while assigning weak updates when is small.
Continuous MaxRL extends Maximum-Likelihood RL [47], which maximizes rather than so that hard inputs receive inverse-probability weight (). For our graded reward, we replace with the expected reward while retaining Eq. (16), estimating the gradient of (Appendix B proves this extension and its scale invariance and shift sensitivity). Under Eq. (12), for a fixed input, in an all-failing group with , the failure scale cancels to give , driving the policy toward higher fidelity; in a mixed group on a hard input, rare correct candidates receive large positive advantages .
Hybrid (Eq. (17)) addresses a limitation of MaxRL on already-solved inputs: once all candidates in a group are correct, rewards are and Eq. (16) reduces to , where the bonus dilutes small differences in gate score () by roughly 20× compared with GRPO. Hybrid therefore applies MaxRL whenever a group contains any incorrect candidate and switches to GRPO when all candidates are correct (Appendix C): in an all-correct group, cancels out of , leaving an unattenuated advantage that directly optimizes gate count among valid candidates. Because all candidates pass with probability , this switch rarely triggers on hard inputs (, retaining MaxRL) and smoothly takes over as accuracy approaches one, without extra hyperparameters.
Training Data
GraftQ learns from triples : a random source circuit, a simplified ZX diagram of it, and an equivalent reference circuit extracted from that diagram. All triples are generated synthetically, so the corpus can grow to millions of examples and every reference is checked for equivalence before it is stored. Figure 1Figure 1 summarizes the generator.
Random source circuits
Each sample starts with a qubit count and a gate count , uniformly sampled from and (§ 4.3), respectively. The circuit is then built gate by gate. Each gate type is drawn independently from the fixed distribution in Table 2 and placed on a uniformly random qubit (single-qubit gates) or a uniformly random ordered pair of distinct qubits (CNOT, CZ). A phase gate takes uniformly from .
| gate | CNOT | CZ | ||||||
| probability | 0.1 | 0.1 | 0.1 | 0.1 | 0.2 | 0.1 | 0.2 | 0.1 |
Table 2. Gate distribution of the random source circuits.
ZX simplification and reference extraction
The reference is produced with PyZX [13] in five steps:
The source is converted to a ZX diagram .
Phase teleportation [29] moves non-Clifford phases so that they can fuse without altering the graph structure, giving .
is converted to graph-like form [28] and simplified with the causal-flow-preserving heuristic of Hollker [63] to reduce two-qubit gates while keeping the diagram directly extractable [49], giving (used as the input diagram in §3).
A circuit is extracted from and decomposed into basic gates.
It is post-processed by PyZX’s gate-level optimization, with and without SWAP-aware rules. Of the two results, the one with fewer two-qubit gates becomes .
Every extracted reference is verified against using the Haar-state test of § 3.4 with tolerance (discarding and regenerating any sample that fails, to guard against extraction bugs). PyZX expresses extracted phases in the basis (with -axis rotations conjugated by ), so every token in and belongs to the vocabulary of § 3.1. We retain even when it contains more gates than : supervised pretraining imitates the PyZX output directly, while subsequent RL fine-tuning rewards further gate reduction. Conditioning on alongside provides the model with both the explicit input gate sequence and the simplified ZX graph structure prior to circuit extraction.
Size buckets
For curriculum training (§ 5), the corpus is partitioned by the gate count of the source circuit into four buckets: , , , and gates. Each bucket maintains independent training, validation, and test splits (Table 3). Supervised pretraining uses the bucket, the two-stage RL curriculum (§ 5) progressively incorporates and , and is held out to evaluate length generalization to unseen longer circuits. For benchmark evaluation (§ 6), we draw a fixed subset of 9,000 circuits from each bucket’s test split, along with a qubit-stratified subset of 992 circuits (62 per qubit count across ) for high-budget () sampling experiments.
| source gates | train | valid | test |
| 20–100 | 7,000,000 | 50,000 | 100,000 |
| 101–200 | 2,013,419 | 10,040 | 9,959 |
| 201–300 | 2,013,082 | 9,978 | 10,033 |
| 301–400 | 2,012,564 | 9,898 | 9,940 |
Table 3. Data buckets (5–20 qubits): number of samples in each split.
Experimental Setup and Training Pipeline
Training proceeds in three stages (Figure 3). Hyperparameters and software/hardware details are listed in Appendix A.

Figure 3. Training pipeline. Stage 1 compares advantage estimators at fixed circuit size. Stage 2 initializes from the stage-1 Hybrid policy and progressively introduces larger circuits.
Stage 0: supervised pretraining. The 174M-parameter model of § 3.2 is pretrained with Eq. (13) to reproduce the PyZX reference on the 20–100-gate bucket conditioned on , using AdamW [64] with a global batch size of 256 (Table 7). Validation cross-entropy reaches 0.1303 (perplexity 1.14) at approximately 248,000 steps ( epochs), which initializes all RL runs.
| parameter | SFT | RL stage 1 | RL stage 2 |
| optimizer | AdamW | AdamW | AdamW |
| (0.9, 0.98) | (0.9, 0.98) | (0.9, 0.98) | |
| weight decay | 0.01 | 0 | 0 |
| peak LR | |||
| LR schedule | warmup+cosine | constant | constant |
| warmup steps | 3000 | – | – |
| gradient clip | 1.0 | 1.0 | 1.0 |
| global batch | 256 | 32 | 64 |
| group size | – | 32 | 32 |
| updates / batch | – | 1 (on-policy) | 1 (on-policy) |
| rollout | – | 1.0 | 1.0 |
| valid | – | 0.1 | 0.1 |
| valid interval | 2000 | 1024 | 1024 |
| valid samples | – | 1024 | 500 / bucket |
| steps (eval) | ≈248k (≈9 ep.) | 49,152 | 116.7k / 255.0k |
| precision | bf16 | bf16 | bf16 |
| KL penalty | – | none | none |
| fidelity tol. | – |
Table 7. Training hyperparameters.
Stage 1: comparing advantage estimators. Stage 1 fine-tunes the pretrained policy on 20–100-gate circuits to isolate the effect of the advantage estimator while holding all other settings fixed across GRPO, MaxRL, and Hybrid: identical initialization, training data, and reward (Eq. (12)); identical on-policy objective (Eq. (14)) with unit gradient-norm clipping; identical rollout sampling (, , full valid support); a constant learning rate of ; and identical rollout and validation seeds. Each step samples 32 inputs (1,024 candidates per step); checkpoints are selected by mean validation reward on 20–100-gate validation circuits, and we evaluate step 49,152 of each run.
Stage 2: curriculum over circuit size. Because a policy trained solely on 20–100-gate circuits generalizes poorly to 200- or 300-gate inputs [41], we initialize from the stage-1 Hybrid policy (step 49,152) and apply a two-stage size curriculum [65] using weighted mixtures of the size buckets (§ 4.3), assigning 70% weight to the newly introduced bucket while replaying shorter buckets to prevent forgetting:
Stage 2a (up to 200 gates, steps 0–116,736): 20–100 : 101–200 = 0.30 : 0.70.
Stage 2b (up to 300 gates, from step 116,736; evaluated at step 254,976): 20–100 : 101–200 : 201–300 = 0.15 : 0.15 : 0.70.
Each step samples a global batch of 64 inputs with rollouts per input (2,048 candidates per step), selecting checkpoints by mean validation reward across a fixed multi-bucket validation pool. The 301–400-gate bucket is never used in training and serves strictly to evaluate out-of-distribution length generalization.
Experimental Results
We evaluate all models on the held-out sets of 9,000 random circuits per size bucket (§ 4.3).
Metrics and verification reliability
Circuit accuracy (pass@K) is the fraction of test circuits with at least one valid candidate among samples [66], with pass@1 estimated via where is the number of valid samples. Among valid candidates for a given input, we select the lexicographic minimum under (ranking by or gives virtually identical results at ) and report gate reductions alongside PyZX’s . The better-than-reference (and worse-than-reference) rate is the fraction of a model’s solved circuits on which its selected circuit uses strictly fewer (or strictly more) gates than . To avoid selection bias across models with different solve rates, mean gate reductions are always computed on the common success set solved by all compared models in a table or plot.
Before presenting benchmark comparisons, we validate our single-state verifier (, ) in two ways. First, on 32,000 candidates sampled across SFT, GRPO, MaxRL, and Hybrid on 20–100-gate circuits (), we compare independent Haar-random state tests against exact process infidelity (Figure 4). Already at , the random-state test rejects all 11,296 inequivalent candidates (0 false acceptances): zero equivalent candidates fall in , matching the exact single-gate lower bound (Appendix § 14), and 89.4% have .
Figure 4. Validation of random-state verification on 32,000 candidates (5 ). (a) Fraction passing Haar-random state tests (solid) versus the upper bound (dashed); empirical acceptance equals the exact equivalence rate already at . (b) Exact process infidelity across all 11,296 inequivalent candidates: none lie in .
Second, we subject all 80,674 selected best candidates across every model–bucket evaluation reported below to deterministic certification against via symbolic ZX simplification of [67], supplemented by exact unitary comparison for all 24,910 candidates with (Appendix § 14). Every single candidate passes (100% certified, zero rejections).
Advantage estimators: GRPO, MaxRL, and Hybrid
Table 4 and Figure 5 first compare the three stage-1 estimators under identical initialization and compute (§ 5), confirming the analysis of § 3.6:
Figure 5. Stage-1 advantage-estimator comparison on 20–100-gate circuits (step 49,152). (a) Test pass@32 by qubit count. (b) Extra two-qubit gate reduction over PyZX on the common success set (). (c) Validation pass@32 during stage-1 training.
| System | pass@1 | pass@32 | all | 2Q | better | worse | |
| PyZX ref. | – | – | 14.19 | 0.79 | 6.21 | – | – |
| SFT (init.) | 60.8% | 71.6% | 14.24 | 0.79 | 6.21 | 0.1% | 0.3% |
| GRPO | 72.7% | 74.7% | 15.61 | 1.05 | 6.20 | 21.1% | 10.6% |
| MaxRL | 83.4% | 87.6% | 14.88 | 0.84 | 6.19 | 20.4% | 27.9% |
| Hybrid | 80.4% | 85.5% | 15.58 | 1.04 | 6.20 | 21.9% | 16.0% |
Table 4. Controlled stage-1 comparison on 9,000 held-out 20–100-gate circuits (, , step 49,152). Gate reductions are on the common success set (); better and worse (2Q) are relative to PyZX on each model’s solved set.
Correctness on hard inputs. MaxRL (87.6% pass@32) and Hybrid (85.5%) far outperform GRPO (74.7%, only +3.1 pp over SFT), with the largest gap on dense small-qubit circuits (59.8% and 60.3% vs. 39.9% at ; Figure 5(a)), where MaxRL’s inverse-mean weighting prioritizes low-pass-rate inputs.
Gate-cost optimization on solved inputs. MaxRL yields much smaller gate reductions than GRPO (0.84 vs. 1.05 2Q; 27.9% worse than PyZX) because the success bonus dilutes gate-cost differences in all-correct groups. Switching to GRPO normalization on all-correct groups allows Hybrid to match GRPO’s gate reduction (1.04 2Q, 21.9% better than PyZX; Figure 5(b)) while staying within 2.1 pp of MaxRL’s pass@32.
Diversity and training dynamics. The pass@32−pass@1 gap is only 2.0 pp for GRPO versus 4.2 pp for MaxRL and 5.1 pp for Hybrid, indicating narrower mode collapse under GRPO, while MaxRL and Hybrid improve validation accuracy steadily throughout training (Figure 5(c); Appendix § 15).
Hybrid thus provides the best trade-off between solve rate and gate reduction, motivating its selection as the base policy for Stage 2.
Main results
Table 5 and Figure 6 and Figure 7 summarize three central findings across the four size buckets.
Figure 6. Main evaluation on 20–100-gate circuits (5–20 qubits). (a) Test pass@8 by qubit count. (b) Mean two-qubit gates reduced on the common success set (). (c) Inference-time scaling of S1-Hybrid ( on 992 stratified circuits; best-of- 2Q reduction assigns zero reduction when no sample in is valid).
Figure 7. Per-qubit pass@8 of S1-Hybrid, S2a-Hybrid (trained up to 200 gates), and S2b-Hybrid (trained up to 300 gates) on (a) 20–100, (b) 101–200, (c) 201–300, and (d) unseen 301–400 gates.
| Bucket | System | pass@1 | pass@8 | gates reduced (common set) | better than ref. | |||
| all | 2Q | all | 2Q | |||||
| 20–100 | PyZX reference | – | – | 14.21 | 0.82 | 6.21 | – | – |
| GraftQ (SFT) | 60.8% | 67.7% | 14.25 | 0.82 | 6.21 | 5.0% | 0.1% | |
| GraftQ (S1-Hybrid) | 80.4% | 83.5% | 15.57 | 1.06 | 6.20 | 59.5% | 21.8% | |
| GraftQ (S2a-Hybrid) | 90.8% | 92.9% | 15.69 | 1.07 | 6.20 | 60.2% | 23.7% | |
| GraftQ (S2b-Hybrid) | 92.0% | 94.1% | 15.67 | 1.06 | 6.20 | 59.7% | 23.6% | |
| 101–200 | PyZX reference | – | – | 44.57 | 2.31 | 17.76 | – | – |
| GraftQ (S1-Hybrid) | 12.5% | 15.4% | 47.06 | 2.39 | 17.65 | 69.3% | 35.1% | |
| GraftQ (S2a-Hybrid) | 60.7% | 68.7% | 46.87 | 2.43 | 17.65 | 41.8% | 29.9% | |
| GraftQ (S2b-Hybrid) | 71.4% | 78.8% | 46.75 | 2.43 | 17.65 | 38.5% | 28.6% | |
| 201–300 | PyZX reference | – | – | 93.79 | 5.13 | 34.56 | – | – |
| GraftQ (S2a-Hybrid) | 6.8% | 10.2% | 88.20 | 3.43 | 34.26 | 19.1% | 25.0% | |
| GraftQ (S2b-Hybrid) | 38.8% | 50.7% | 87.90 | 3.34 | 34.25 | 9.2% | 20.2% | |
| 301–400 (unseen) | GraftQ (S2b-Hybrid) | 4.1% | 7.7% | 129.47 | 4.50 | 51.75 | – | – |
Table 5. Main results on held-out random circuits (9,000 circuits per bucket, 5–20 qubits, , ). S2a-Hybrid (step 116,736) is trained up to 200 gates and S2b-Hybrid (step 254,976) up to 300 gates (omitting policies with 0% pass@8); the unseen 301–400-gate bucket evaluates length generalization. Mean gate reductions are relative to on each trained bucket’s common success set (, 1,128, and 797) and on the 690 solved circuits for 301–400. Better (all) and better (2Q) are fractions of each model’s own solved circuits strictly beating .
First, verifier-guided RL moves the model from imitating PyZX to surpassing it in both reliability and gate count. Under supervised pretraining, the model largely copies its teacher, matching PyZX’s two-qubit gate count on nearly all solved circuits. RL post-training raises pass@8 on 20–100-gate circuits from 67.7% to 94.1%, with the largest gains on dense, small-qubit circuits where extraction is hardest (Figure 6(a)), and consistently reduces more total and two-qubit gates than PyZX across all qubit counts (Figure 6(b)). Across the three trained buckets in Table 5, the final curriculum policy (S2b-Hybrid) finds strictly fewer two-qubit gates than PyZX on 20%–29% of solved circuits while closely matching PyZX in count (§7); selecting the circuit with fewer two-qubit gates between and yields net full-test-set reductions of +0.47, +0.51, and +0.26 two-qubit gates per circuit over PyZX alone.
Second, the two-stage size curriculum overcomes the sharp length degradation of fixed-size RL while inducing positive backward transfer (Figure 7). Whereas S1-Hybrid trained solely on short circuits drops to 15.4% pass@8 on 101–200 gates and 0% beyond, progressive curriculum training scales pass@8 to 68.7% (S2a-Hybrid) and 78.8% (S2b-Hybrid) on 101–200 gates, reaches 50.7% on 201–300 gates, and achieves 7.7% pass@8 on unseen 301–400-gate circuits (Figure 7(b–Figure 7d)); 0% length-cap truncation or parse failures, with errors arising solely from inequivalence. Replaying shorter buckets not only prevents forgetting, but further improves pass@8 on 20–100 gates (83.5% → 92.9% → 94.1%) and 101–200 gates (68.7% → 78.8%) across Stages 2a and 2b (Figure 7(a,Figure 7b); validation trajectories in Figure 9(a,Figure 9b)) while preserving gate-reduction quality (Table 5).
Figure 9. Stage-2 curriculum dynamics and test-time scaling. (a) Per-bucket validation pass@32 across Stage 2a (steps 0–116,736) and Stage 2b (steps 116,736–262,144). (b) Mean validation reward, with red markers indicating S2a-Hybrid (116.7k) and S2b-Hybrid (255.0k). (c) Test pass@ () of S2b-Hybrid (step 254,976) on the 992-circuit stratified subsets of 201–300 (38.5% 56.3%) and unseen 301–400 (3.8% 9.2%) gates.
Third, increasing the test-time sampling budget from to 64 steadily improves both pass@ and best-of- two-qubit gate reduction without retraining (Figure 6(c)), with especially pronounced gains on longer circuits (e.g., lifting pass@ from 38.5% to 56.3% on 201–300 gates; Figure 9(c)).
Discussion and Conclusion
We formulated quantum circuit optimization as graph-conditioned sequence-to-sequence generation. GraftQ jointly encodes a source circuit’s gate-token sequence and simplified ZX diagram with a GNN-Transformer, and is pretrained on PyZX-optimized references before reinforcement learning post-training with a Haar-random state verifier and a gate-reduction reward. Extending MaxRL to continuous non-negative rewards and introducing the Hybrid advantage estimator combines MaxRL’s high solve rate on hard circuits with GRPO’s unattenuated gate-count optimization on solved circuits. Together with a two-stage size curriculum and symbolic ZX certification of all selected benchmark solutions, verifier-guided RL moves GraftQ well beyond supervised imitation in both equivalence reliability and two-qubit gate reduction.
On the 20–100- and 101–200-gate benchmarks, RL consistently reduces more two-qubit gates on average than PyZX while closely matching PyZX’s -gate counts (within 0.01–0.31 gates; fault-tolerant settings can further prioritize count via a larger ). This contrast reflects the reference pipeline (§ 4.2): phase teleportation [29] already fuses essentially all collapsible non-Clifford phases on random Clifford+ circuits, leaving little headroom in count, whereas causal-flow extraction introduces auxiliary two-qubit gates [51] that graph-conditioned autoregressive decoding learns to avoid. On the 201–300-gate bucket, mean gate reduction still trails PyZX because moderate single-sample accuracy () makes all-correct rollout groups rare (), keeping Hybrid primarily in its MaxRL correctness regime; following Hybrid training with a subsequent GRPO stage once accuracy is established offers a direct remedy.
For circuit scale, fixed-size policies fail on deeper inputs, especially at high per-qubit gate density (small , Figure 7), due to compounding autoregressive errors rather than decoding length caps [41]. Our size curriculum addresses this progressively: although our experiments stop training at 201–300 source gates (already generalizing to unseen 301–400-gate circuits), the curriculum itself can continue advancing to longer buckets to handle deeper circuits, complemented at inference time by larger sampling budgets () without retraining. Extending training and evaluation from synthetic random circuits and a single causal-flow ZX baseline to structured algorithmic benchmarks is a natural next step.
Finally, two directions will broaden practical deployment. First, state-vector verification scales exponentially with qubit count (reaching hundreds of milliseconds per candidate at ), limiting online RL training to roughly 20 qubits; scaling to wider registers motivates fast symbolic ZX rewriting or approximate tensor-network verifiers. Second, because hardware constraints enter our formulation only through the qubit-indexed gate vocabulary, validity mask, and gate-cost reward, adapting these components offers a direct path to larger qubit registers, native device gate sets, and connectivity-aware routing.
Code Availability
The inference and equivalence-verification code for GraftQ, together with the trained S2b-Hybrid model checkpoint, is publicly available at https://github.com/Xiao-diLi/GraftQ.
Acknowledgments
We thank Xue Chen, Xiaotian Nie, Hui Zhai, and Si Wei for helpful discussions.
References
Hyperparameters and Implementation Details
Table 6 lists the model architecture and Table 7 lists the training hyperparameters for all three stages.
Software and hardware. Our implementation uses PyTorch [68] and PyTorch Lightning, PyTorch Geometric [69] for GCN layers, a customized PyZX [13] incorporating the causal-flow-preserving simplification of Holker [63], and Qulacs [60] for state-vector simulation. Supervised pretraining runs on four NVIDIA A100 (48 GB) GPUs; each stage-1 RL runs use a single A100 (48 GB) GPU (≈ 85 GPU-hours); and stage-2 curriculum runs use four or eight NVIDIA A100 (48 GB) / A800 (80 GB) GPUs with a fixed global batch size of 64 inputs per step.
Reward, advantage, and decoding parameters. Reward (Eq. (12)): $b=2$, $s=0.2$, $(w_{\mathrm{all}},w_{2q},w_T)=(1,2,2)$, $\tau_F=10^{-4}$ (with a $10^{-6}$ denominator guard in Eq. (4) when ); assigning a larger weight does not push -gate reduction past PyZX, because PyZX’s phase teleportation already reduces count very effectively on these circuits; see §7; numerical guards (Eqs. (15) and (16)): , . Test decoding uses temperature without top- or top- truncation; RL rollouts and test decoding cap output length at 1.2× the longest reference in the batch, while training-time validation uses a 512-token cap. Each RL rollout batch performs a single on-policy optimizer step without a KL penalty (14).
MaxRL with Continuous Rewards
We extend Maximum-Likelihood Reinforcement Learning [47] to continuous non-negative rewards and prove three results (Theorems B.1 to B.3) used in § 3.6.
Throughout this appendix, fix an input and a shared Haar-random verifier state (Algorithm 1); the policy observes only , so its score function is independent of . Let denote the single-state reward ((12)) with conditional expectation , where denotes expectation under for fixed .
Continuous MaxRL gradient
Proposition B.1. The gradient of with respect to satisfies
where is the reward-tilted distribution. Conditioned on , the group rewards are i.i.d. with mean ; replacing with the group sample mean yields the self-normalized advantage , for which is an asymptotically unbiased estimator of with finite-group bias .
Proof. For fixed , does not depend on , so the log-derivative identity gives . The reward-tilted rewrite follows from . Since , . Replacing by the i.i.d. group mean introduces an ratio-estimation bias that vanishes as , and taking expectation over completes the result. □
Comparison with binary MaxRL and concurrent extensions. For a binary indicator , , and the objective reduces to . Our formula gives , matching the MaxRL gradient of Tajwar et al. [47] for fixed . A concurrent extension, ArgMaxRL [70], instead decomposes graded rewards into threshold events to target best-of- performance; both reduce to MaxRL for binary rewards.
Latent-success lifting
Proposition B.2. For fixed , let be an upper bound on and define a latent Bernoulli variable . Then
Applying binary MaxRL to the lifted samples gives the per- objective
which converges to (up to an additive constant ) as and satisfies .
Proof. Since , . Truncating at yields the finite- MaxRL objective of Tajwar et al. [47], whose gradient is as . One can substitute the conditional expectations under into the numerator and denominator of the lifted advantage (or taking ) recovers the continuous-reward estimator. □
Sensitivity to reward offset
Proposition B.3. For a shifted reward with constant , , and for each
As the gradient approaches (standard expected-reward RL). For any , the per- weight becomes rather than , strictly attenuating the MaxRL emphasis on hard inputs.
Proof. . By the score-function identity, , so
The coefficient shrinks the MaxRL gradient toward the standard RL gradient, which corresponds to (where ). □
Implication for reward design. Theorem B.3 shows why the reward Eq. (12) assigns failures a small positive value rather than zero or a large negative value. If failures score zero, a group of all-failures gives and the policy receives no gradient. If failures score a large constant, MaxRL degrades toward standard RL. The failure scale provides a fidelity-proportional gradient on hard inputs without washing out the MaxRL weighting. GRPO is insensitive to additive shifts (the group mean cancels), so this constraint applies only to MaxRL and Hybrid.
Hybrid Advantage Estimator: Analysis {#sec:C}
Fix an input and shared verifier state with pass probability , and let denote the event that all sampled candidates pass on , which occurs with probability . Conditioned on , the candidates are drawn i.i.d. from the conditional valid policy . Because on , the bonus cancels in . Moreover, , and the constant cancels against the zero-sum weights . As grows, concentrates around the conditional mean and standard deviation , so the single-group GRPO gradient converges in conditional expectation to the normalized gate-reduction gradient (with the threshold zeroing out updates once gate scores saturate).
Across both branches of Eq. (17), total expectation decomposes the single-group Hybrid gradient as
When an input is not yet reliably solved (; e.g., gives ), and the first term matches the unconditional continuous MaxRL gradient of Appendix B up to , prioritizing equivalence. As (), the second term dominates and updates transition smoothly to GRPO gate-count optimization without additional schedule hyperparameters.
Theoretical Basis of Random-State Verification
This appendix gives the theoretical basis of the verifier of § 3.4. Throughout, is the number of qubits, , and . For a state , writing , we define
and we compare the two circuits through the process fidelity
Since , with equality if and only if all eigenvalues of coincide, the two circuits are equivalent up to a global phase exactly when .
Single-state fidelity estimates average state fidelity
The verifier draws from the Haar measure. The second moment of this measure is , where swaps the two tensor factors [71]. With , the average fidelity is
Substituting gives
For any candidate fixed prior to drawing , the fidelity on one Haar-random state is therefore an unbiased estimate of the average state fidelity , and its infidelity is an unbiased estimate of , which equals the process infidelity up to the factor for . Errors in the two quantities are tied directly: a candidate is close to the reference on average over input states if and only if its process fidelity is close to one.
Statistical guarantee of multi-state re-verification
Consider a multi-state test that draws independent Haar-random test states and accepts a fixed candidate only if it passes on all states. We bound the probability of accepting a fixed candidate whose average infidelity is non-negligible. Diagonalize with eigenvalues , . By unitary invariance of the Haar measure, the weights in the eigenbasis are uniformly distributed on the simplex, . With ,
The Dirichlet moments for give . For and , each fourth moment appearing in is at most , so
Since , the Paley–Zygmund inequality gives, for ,
A single random-state test accepts a candidate when . If , each test therefore rejects with probability at least . Across independent random states, all of which must pass,
This worst-case bound holds for any fixed candidate unitarily satisfying at every , so states suffice to drive the bound below (e.g., for and for ). By Eq. (26), any fixed candidate whose process infidelity is at least is rejected by independent random states with probability at least .
Infidelity of discrete Clifford+T errors
To contextualize the empirical process-infidelity distribution observed across the 32,000 candidates in § 6.1, we distinguish single-gate edits from multi-gate errors over :
Exact lower bound for single-gate edits. Suppose differs from by inserting, deleting, or substituting a single gate at an arbitrary position in the circuit, and for inequivalent . Writing and , we have , , and . Both the shared suffix and, by cyclic invariance of the trace, the shared prefix cancel in , regardless of circuit depth, entanglement, or whether commutes with the edited gate. Because any pair acts on at most four qubits and identity factors on untouched qubits cancel, finite enumeration gives the exact minimum non-zero process infidelity
attained by an uncancelled ( or ) phase difference on one qubit (followed by 0.2714, 0.5000 for a single edit, 0.7500 for an inserted/deleted CNOT or CZ, and 1.0 for , , or ).
Multi-gate errors and empirical distribution. Because Clifford+T generates a dense subgroup of , is not a universal lower bound when multiple gates differ: for instance, reversing two non-commuting rotations on one qubit
yields ; an -qubit controlled- discrepancy yields ( at , falling below only for ); and long Solovay–Kitaev sequences can approach zero arbitrarily closely. Conversely, when an early erroneous token causes an autoregressive policy to generate a divergent continuation (), multiple gates differ without symmetric cancellation, explaining why no inequivalent candidate in § 6.1 falls below ( have ).
Use in training and evaluation
Training and fast decoding use a single random input state per group () with ; all candidates in a group share this state, evaluating candidates on a common input while reusing a single evolution of , and each candidate fixed prior to drawing retains as its marginal expected fidelity. For final evaluation (§ 6.1), all 80,674 selected best candidates across all reported model–bucket evaluations are deterministically certified against via exact unitary comparison for (; 24,910 candidates) and symbolic ZX-calculus equivalence verification (pyzx.Circuit.verify_equality) across all .
Additional Experimental Results
Figure 8 to Figure 10 present supplementary training trajectories, test-time scaling curves on longer buckets, and per-qubit gate-reduction breakdowns complementing § 6.
Figure 8. Stage-0 and stage-1 training trajectories. (a) Stage-0 SFT validation cross-entropy loss, marking the step-248,000 checkpoint used to initialize RL. (b) Stage-1 mean rollout reward (exponential moving average, ). (c) Stage-1 pre-clip gradient norm (EMA, ).
Figure 10. Stage-1 per-qubit gate reductions relative to on the common success set (, 20–100-gate test split, , ). (a) Total gates reduced. (b) Two-qubit gates reduced. (c) Non-Clifford gates reduced.
Figure 8 shows the stage-0 supervised validation loss alongside stage-1 rollout rewards and pre-clip gradient norms; across GRPO, MaxRL, and Hybrid, pre-clip gradient norms remain within a comparable bounded range (15–35) prior to unit norm clipping (which effectively normalizes step sizes across estimators). Figure 9(a,Figure 9b) plots validation accuracy and reward across the full 262,144-step stage-2 curriculum, showing the immediate inflection on 201–300 and unseen 301–400 gates at the Stage-2a→2b transition (step 116,736), while Figure 9(c) reports budget scaling of S2b-Hybrid on the 992-circuit stratified subsets of 201–300 and 301–400 gates. Finally, Figure 10 gives the per-qubit breakdown () of total, two-qubit, and -gate reductions across all stage-1 policies on the common success set of Table 4.
References
- [1]Peter W. Shor. 1997. Polynomial-Time Algorithms for Prime Factorization and Discrete Logarithms on a Quantum Computer. SIAM J. Comput. 26, 5 (1997), 1484–1509. https://doi.org/10.1137/S0097539795293172
- [2]Lov K. Grover. 1996. A fast quantum mechanical algorithm for database search. In Proceedings of the Twenty-Eighth Annual ACM Symposium on Theory of Computing (STOC ’96). ACM, New York, NY, USA, 212–219. https://doi.org/10.1145/237814.237866
- [3]Michael A. Nielsen and Isaac L. Chuang. 2010. Quantum Computation and Quantum Information (10th anniversary ed.). Cambridge University Press, Cambridge, UK. https://doi.org/10.1017/CBO9780511976667
- [4]Google Quantum AI and Collaborators. 2025. Quantum error correction below the surface code threshold. Nature 638, 8052 (2025), 920–926. https://doi.org/10.1038/s41586-024-08449-y
- [5]Dolev Bluvstein, Simon J. Evered, Alexandra A. Geim, Sophie H. Li, Hengyun Zhou, Tom Manovitz, Sepehr Ebadi, Madelyn Cain, Marcin Kalinowski, Dominik Hangleiter, J. Pablo Bonilla Ataides, Nishad Maskara, Iris Cong, Xun Gao, Pedro Sales Rodriguez, Thomas Karolyshyn, Giulia Semeghini, Michael J. Gullans, Markus Greiner, Vladan Vuletić, and Mikhail D. Lukin. 2024. Logical quantum processor based on reconfigurable atom arrays. Nature 626, 7997 (2024), 58–65. https://doi.org/10.1038/s41586-023-06927-3
- [6]Craig Gidney and Martin Ekerå. 2021. How to factor 2048 bit RSA integers in 8 hours using 20 million noisy qubits. Quantum 5 (2021), 433. https://doi.org/10.22331/q-2021-04-15-433
- [7]Craig Gidney. 2025. How to factor 2048 bit RSA integers with less than a million noisy qubits. arXiv:2505.15917 [quant-ph]. https://arxiv.org/abs/2505.15917
- [8]John Preskill. 2018. Quantum Computing in the NISQ era and beyond. Quantum 2 (2018), 79. https://doi.org/10.22331/q-2018-08-06-79
- [9]Gushu Li, Yunfan Yao, and Yuan Xie. 2019. Tackling the Qubit Mapping Problem for NISQ-Era Quantum Devices. In Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS ’19). ACM, New York, NY, USA, 1001–1014. https://doi.org/10.1145/3297859.3304023
- [10]Alwin Zulehner, Alexandru Paler, and Robert Wille. 2019. An Efficient Methodology for Mapping Quantum Circuits to the IBM QX Architectures. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 38, 7 (2019), 1226–1236. https://doi.org/10.1109/TCAD.2018.2846658
- [11]Ali Javad-Abadi, Matthew Treinish, Kevin Krishulic, Christopher J. Wood, Jake Lishman, Julien Gacon, Simon Martiel, Paul D. Nation, Lev S. Bishop, Andrew W. Cross, Blake R. Johnson, and Jay M. Gambetta. 2024. Quantum computing with Qiskit. arXiv:2405.08810 [quant-ph]. https://arxiv.org/abs/2405.08810
- [12]Seyon Sivarajah, Silas Dilles, Alexander Cowtan, Will Simmons, Alec Edgington, and Ross Duncan. 2021. 1 ket>: a retargetable compiler for NISQ devices. Quantum Science and Technology 6, 1 (2021), 014003. https://doi.org/10.1088/2058-9565/ab8e92
- [13]Aleks Kissinger and John van de Wetering. 2020. PyZX: Large Scale Automated Diagrammatic Reasoning. Electronic Proceedings in Theoretical Computer Science 318 (2020), 229–241. https://doi.org/10.4204/EPTCS.318.14
- [14]Kesha Hietala, Robert Rand, Shih-Hun Hung, Xiaodi Wu, and Michael Hicks. 2021. A Verified Optimizer for Quantum Circuits. Proceedings of the ACM on Programming Languages 5, POPL (2021), 1–29. https://doi.org/10.1145/3434318
- [15]Bryan Eastin and Emanuel Knill. 2009. Restrictions on Transversal Encoded Quantum Gate Sets. Physical Review Letters 102 (2009), 110502. https://doi.org/10.1103/PhysRevLett.102.110502
- [16]Jonas T. Anderson, Guillaume Duclos-Cianci, and David Poulin. 2014. Fault-Tolerant Conversion between the Steane and Reed-Muller Quantum Codes. Physical Review Letters 113 (2014), 080501. https://doi.org/10.1103/PhysRevLett.113.080501
- [17]Sergey Bravyi and Alexei Kitaev. 2005. Universal quantum computation with ideal Clifford gates and noisy ancillas. Physical Review A 71, 2 (2005), 022316. https://doi.org/10.1103/PhysRevA.71.022316
- [18]Daniel Litinski. 2019. Magic State Distillation: Not as Costly as You Think. Quantum 3 (2019), 205. https://doi.org/10.22331/q-2019-12-02-205
- [19]Craig Gidney, Noah Shutty, and Cody Jones. 2024. Magic State Cultivation: Growing T States as Cheap as CNOT Gates. arXiv:2409.17595 [quant-ph] https://arxiv.org/abs/2409.17595
- [20]John van de Wetering and Matt Amy. 2024. Optimising quantum circuits is generally hard. arXiv:2310.05958 [quant-ph] https://arxiv.org/abs/2310.05958
- [21]Matthew Amy, Dmitri Maslov, and Michele Mosca. 2014. Polynomial-Time T-Depth Optimization of Clifford+T Circuits Via Matroid Partitioning. IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 33, 10 (2014), 1476–1489. https://doi.org/10.1109/TCAD.2014.2341953
- [22]Yunseong Nam, Neil J. Ross, and Dmitri Maslov. 2018. Automated optimization of large quantum circuits with continuous parameters. npj Quantum Information 4, 1 (2018), 23. https://doi.org/10.1038/s41534-018-0072-4
- [23]Mingxuan Xu, Zikun Li, Oded Padon, Sina Lin, Jessica Pointing, Auguste Hirth, Henry Ma, Jens Palsberg, Alex Aiken, Umut A. Acar, and Zhaohua Jia. 2022. Quartz: Superoptimization of Quantum Circuits. In Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI ’22). ACM, New York, NY, USA, 625–640. https://doi.org/10.1145/3519939.3513433
- [24]Amanda Xu, Abtin Molavi, Lauren Pick, Swamit Tannu, and Aws Albarghouthi. 2023. Synthesizing Quantum-Circuit Optimizers. Proceedings of the ACM on Programming Languages 7, PLDI (2023), 835–859. https://doi.org/10.1145/3591254
- [25]Jessica Pointing, Oded Padon, Zhhiao Jia, Henry Ma, Auguste Hirth, Jens Palsberg, and Alex Aiken. 2024. Quanto: optimizing quantum circuits with automatic generation of circuit identities. Quantum Science and Technology 9, 4 (2024), 045009. https://doi.org/10.1088/2058-9565/ad5b16
- [26]Amanda Xu, Abtin Molavi, Swamit Tannu, and Aws Albarghouthi. 2025. Optimizing Quantum Circuits, Fast and Slow. In Proceedings of the 30th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 1 (ASPLOS ’25). ACM, New York, NY, USA, 777–793. https://doi.org/10.1145/3669940.3707240
- [27]Bob Coecke and Ross Duncan. 2011. Interacting quantum observables: categorical algebra and diagrammatics. New Journal of Physics 13, 4 (2011), 043016. https://doi.org/10.1088/1367-2630/13/4/043016
- [28]Ross Duncan, Aleks Kissinger, Simon Perdrix, and John van de Wetering. 2020. Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus. Quantum 4 (2020), 279. https://doi.org/10.22331/q-2020-06-04-279
- [29]Aleks Kissinger and John van de Wetering. 2020. Reducing the number of non-Clifford gates in quantum circuits. Physical Review A 102, 2 (2020), 022406. https://doi.org/10.1103/PhysRevA.102.022406
- [30]John van de Wetering. 2020. ZX-calculus for the working quantum computer scientist. arXiv:2012.13966 [quant-ph] https://arxiv.org/abs/2012.13966
- [31]Thomas Fösel, Murphy Yuezhen Niu, Florian Marquardt, and Li Li. 2021. Quantum circuit optimization with deep reinforcement learning. arXiv:2103.07585 [quant-ph] https://arxiv.org/abs/2103.07585
- [32]Zikun Li, Jinjun Peng, Yixuan Mei, Sina Lin, Yi Wu, Oded Padon, and Zhihao Jia. 2024. Quarl: A Learning-Based Quantum Circuit Optimizer. Proceedings of the ACM on Programming Languages 8, OOPSLA1 (2024), 555–582. https://doi.org/10.1145/3649831
- [33]David Kremer, Victor Villar, Hanhee Paik, Ivan Duran, Ismael Faro, and Juan Cruz-Benito. 2024. Practical and efficient quantum circuit synthesis and transpiling with Reinforcement Learning. arXiv:2405.13196 [quant-ph] https://arxiv.org/abs/2405.13196
- [34]Maximilian Nägele and Florian Marquardt. 2024. Optimizing ZX-diagrams with deep reinforcement learning. Machine Learning: Science and Technology 5, 3 (2024), 035077. https://doi.org/10.1088/2632-2153/ad76f7
- [35]Jordi Riu, Jan Nogué, Gerard Vilaplana, Artur Garcia-Saez, and Marta P. Estarellas. 2025. Reinforcement Learning Based Quantum Circuit Optimization via ZX-Calculus. Quantum 9 (2025), 1758. https://doi.org/10.22331/q-2025-05-28-1758
- [36]Alexander Mattick, Maninarman Periyasamy, Christian Ufrecht, Abhishek Y. Dubey, Christopher Mutschler, Axel Plinge, and Daniel D. Scherer. 2025. Optimizing Quantum Circuits via ZX Diagrams using Reinforcement Learning and Graph Neural Networks. arXiv:2504.03429 [cs.LG] https://arxiv.org/abs/2504.03429
- [37]Francisco J. R. Ruiz, Tuomas Laakkonen, Johannes Bausch, Matej Balog, Mohammadamin Barekatain, Francisco J. H. Heras, Alexander Novikov, Nathan Fitzpatrick, Bernardino Romera-Paredes, John van de Wetering, Alhussein Fawzi, Konstantinos Meichanetzidis, and Pushmeet Kohli. 2025. Quantum circuit optimization with AlphaTensor. Nature Machine Intelligence 7, 3 (2025), 374–385. https://doi.org/10.1038/s42256-025-01001-1
- [38]Florian Furrütter, Gorka Muñoz-Gil, and Hans J. Briegel. 2024. Quantum circuit synthesis with diffusion models. Nature Machine Intelligence 6, 5 (2024), 515–524. https://doi.org/10.1038/s42256-024-00831-9
- [39]Lino S. Hofstetter, Lia Yeh, and Prakash Murali. 2026. Bridge of Ψ’s: Quantum Circuit Optimization with Schrödinger Bridges. arXiv:2609.25947 [quant-ph] https://arxiv.org/abs/2609.25947
- [40]Linus Jern, Valter Uotila, Cong Yu, and Bo Zhao. 2025. Agent-Q: Fine-Tuning Large Language Models for Quantum Circuit Generation and Optimization. In 2025 IEEE International Conference on Quantum Computing and Engineering (QCE). IEEE, 1621–1632. https://doi.org/10.1109/QCE65121.2025.00179
- [41]Mehdi Saeedi, Eddie Richter, and Paul Hartke. 2026. When Close Enough Is Not Enough: Autoregressive Drift in Quantum Circuit Synthesis. arXiv:2607.12780 [quant-ph] https://arxiv.org/abs/2607.12780
- [42]Andrew W. Cross, Lev S. Bishop, John A. Smolin, and Jay M. Gambetta. 2017. Open Quantum Assembly Language. arXiv:1707.03429 [quant-ph] https://arxiv.org/abs/1707.03429
- [43]Hung Le, Yue Wang, Akhilesh Deepak Gotmare, Silvio Savarese, and Steven Chu Hong Hoi. 2022. CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learning. In Advances in Neural Information Processing Systems, Vol. 35. 21314–21328. https://doi.org/10.52202/068431-1549
- [44]Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchen Zheng, Y. K. Li, Y. Wu, and Daya Guo. 2024. DeepSeek-Math: Pushing the Limits of Mathematical Reasoning in Open Language Models. arXiv:2402.03300 [cs.CL] https://arxiv.org/abs/2402.03300
- [45]Daya Guo, Dejian Yang, Haowei Zhang, Junxiao Song, Peiyu Wang, Qihao Zhu, Runxin Xu, Ruoyu Zhang, et al. 2025. DeepSeek-R1 incentivizes reasoning in LLMs through reinforcement learning. Nature 645, 8081 (2025), 633–638. https://doi.org/10.1038/s41586-025-09422-9
- [46]Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, John Schulman, Jacob Hilton, Fraser Kelton, Luke Miller, Maddie Simens, Amanda Askell, Peter Welinder, Paul F. Christiano, Jan Leike, and Ryan Lowe. 2022. Training language models to follow instructions with human feedback. In Advances in Neural Information Processing Systems, Vol. 35. 27730–27744. https://doi.org/10.52202/068431-2011
- [47]Fahim Tajwar, Guanning Zeng, Yueer Zhou, Yuda Song, Daman Arora, Yiding Jiang, Jeff Schneider, Ruslan Salakhutdinov, Haiwen Feng, and Andrea Zanette. 2026. Maximum Likelihood Reinforcement Learning. In Proceedings of the 43rd International Conference on Machine Learning (ICML) (Proceedings of Machine Learning Research, Vol. 306). PMLR, 118190–118245. arXiv:2602.02710 [cs.LG] https://proceedings.mlr.press/v306/tajwar26a.htmlarxiv.org/abs/2602.02710
- [48]Dominik Janzing, Pawel Wocjan, and Thomas Beth. 2005. “Non-Identity-Check” is OMA-complete. International Journal of Quantum Information 3, 3 (2005), 463–473. https://doi.org/10.1142/S0219749905001067
- [49]Miriam Backens, Hector Miller-Bakewell, Giovanni de Felice, Leo Lobski, and John van de Wetering. 2021. There and back again: A circuit extraction tale. Quantum 5 (2021), 421. https://doi.org/10.22331/q-2021-03-25-421
- [50]Niel de Beaudrap, Aleks Kissinger, and John van de Wetering. 2022. Circuit Extraction for ZX-Diagrams Can Be #P-Hard. In 49th International Colloquium on Automata, Languages, and Programming (ICALP 2022) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 229), Mikołaj Bojańczyk, Emanuela Merelli, and David P. Woodruff (Eds.). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 119:1–119:19. https://doi.org/10.4230/LIPIcs.ICALP.2022.119
- [51]Korbinian Staudacher, Tobias Guggemos, Sophia Grundner-Culemann, and Wolfgang Gehrke. 2023. Reducing 2-Qubit Gate Count for ZX-Calculus based Quantum Circuit Optimization. Electronic Proceedings in Theoretical Computer Science 394 (2023), 29–45. https://doi.org/10.4204/EPTCS.394.3 Proceedings of Quantum Physics and Logic (QPL 2022).
- [52]John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov. 2017. Proximal Policy Optimization Algorithms. arXiv:1707.06347 [cs.LG] https://arxiv.org/abs/1707.06347
- [53]François Chardon, Alexandre Krajenbrink, Konstantinos Meichanetzidis, and Richie Yeung. 2023. Teaching small transformers to rewrite ZX diagrams. In The 3rd Workshop on Mathematical Reasoning and AI (MATH-AI) at NeurIPS 2023. https://openreview.net/forum?id=btQ7Bt1NLF
- [54]Nicolas Dupuis, Luca Buratti, Sanjay Vishwakarma, Aitana Viudes Forrat, David Kremer, Ismael Faro, Ruchir Puri, and Juan Cruz-Benito. 2024. Qiskit Code Assistant: Training LLMs for Generating Quantum Computing Code. In 2024 IEEE LLM Aided Design Workshop (LAD). IEEE, 1–4. https://doi.org/10.1109/LAD62341.2024.10691762
- [55]Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention Is All You Need. In Advances in Neural Information Processing Systems, Vol. 30. 5998–6008. https://proceedings.neurips.cc/paper/2017/hash/3f5ee243547dee91fbd053c1ba37c6-Abstract.htmlarxiv.org/abs/1706.03762
- [56]Jean-Baptiste Alayrac, Jeff Donahue, Pauline Luc, Antoine Miech, Iain Barr, Yana Hasson, Karel Lenc, Arthur Mensch, Katherine Millican, Malcolm Reynolds, Roman Ring, Eliza Rutherford, Serkan Cabi, Tengda Han, Zheitao Gong, Sina Samangooei, Marianne Monteiro, Jacob L. Menick, Sebastian Borgeaud, Andy Brock, Aida Nematzadeh, Sahand Sharifzadeh, Mikolaj Binkowski, Ricardo Barreira, Oriol Vinyals, Andrew Zisserman, and Karén Simonyan. 2022. Flamingo: a Visual Language Model for Few-Shot Learning. In Advances in Neural Information Processing Systems, Vol. 35. 23716–23736. https://doi.org/10.52202/068431-1723
- [57]Thomas N. Kipf and Max Welling. 2017. Semi-Supervised Classification with Graph Convolutional Networks. In International Conference on Learning Representations (ICLR). arXiv:1609.02907 [cs.LG] https://arxiv.org/abs/1609.02907
- [58]Ruibin Xiong, Yunchang Li, Weiran Zhang, Di He, Kaixuan Sheng, Chen Xing, Huishuai Zhang, Yanyan Lan, Liwei Wang, and Tie-Yan Liu. 2020. On Layer Normalization in the Transformer Architecture. In Proceedings of the 37th International Conference on Machine Learning (ICML) (Proceedings of Machine Learning Research, Vol. 119). PMLR, 10524–10533. https://proceedings.mlr.press/v119/xiong20b.htmlarxiv.org/abs/2002.04745
- [59]Jianlin Su, Murtadha Ahmed, Yu Lu, Shengfeng Pan, Wen Bo, and Yunfeng Liu. 2024. RoFormer: Enhanced Transformer with Rotary Position Embedding. Neurocomputing 568 (2024), 127063. https://doi.org/10.1016/j.neucom.2023.127063
- [60]Yasunari Suzuki, Yoshiaki Kawase, Yuya Masumura, Yuria Hiraga, Masahiro Nakadai, Jiebao Chen, Ken M. Nakanishi, Kosuke Mitarai, Ryosuke Imai, Shiro Tamiya, Takahiro Yamamoto, Tennin Yan, Toru Kawakubo, Yuya O. Nakagawa, Yohei Ibe, Youyuan Zhang, Hirotsugu Yamashita, Hikaru Yoshimura, Akihiro Hayashi, and Keisuke Fujii. 2021. Qulacs: a fast and versatile quantum circuit simulator for research purpose. Quantum 5 (2021), 559. https://doi.org/10.22331/q-2021-10-06-559
- [61]Michał Horodecki, Paweł Horodecki, and Ryszard Horodecki. 1999. General teleportation channel, singlet fraction, and quasidistillation. Physical Review A 60, 3 (1999), 1888–1898. https://doi.org/10.1103/PhysRevA.60.1888
- [62]Michael A. Nielsen. 2002. A simple formula for the average gate fidelity of a quantum dynamical operation. Physics Letters A 303, 4 (2002), 249–252. https://doi.org/10.1016/S0375-9601(02)01272-0
- [63]Calum Holker. 2023. Causal Flow Preserving Optimisation of Quantum Circuits in the ZX-calculus. arXiv:2312.02793 [quant-ph] https://arxiv.org/abs/2312.02793
- [64]Ilya Loshchilov and Frank Hutter. 2019. Decoupled Weight Decay Regularization. In International Conference on Learning Representations (ICLR). arXiv:1711.05101 [cs.LG] https://arxiv.org/abs/1711.05101
- [65]Yoshua Bengio, Jérôme Louradour, Ronan Collobert, and Jason Weston. 2009. Curriculum learning. In Proceedings of the 26th Annual International Conference on Machine Learning (ICML ’09). ACM, New York, NY, USA, 41–48. https://doi.org/10.1145/1553374.1553380
- [66]Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Kaplan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, et al. 2021. Evaluating Large Language Models Trained on Code. arXiv:2107.03374 [cs.LG] https://arxiv.org/abs/2107.03374
- [67]Tom Peham, Lukas Burgholzer, and Robert Wille. 2022. Equivalence Checking of Quantum Circuits with the ZX-Calculus. IEEE Journal on Emerging and Selected Topics in Circuits and Systems 12, 3 (2022), 662–675. https://doi.org/10.1109/JETCAS.2022.3204204
- [68]Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Riedel, Martin Raison, Alykhane Tejani, Sachan Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. 2019. PyTorch: An Imperative Style, High-Performance Deep Learning Library. In Advances in Neural Information Processing Systems, Vol. 32. 8024–8035. https://proceedings.neurips.cc/paper/2019/hash/bdcca28f8eef792f2bfa9f701277740-Abstr act.htmlarxiv.org/abs/1912.01703
- [69]Matthias Fey and Jan Eric Lenssen. 2019. Fast Graph Representation Learning with PyTorch Geometric. In ICLR Workshop on Representation Learning on Graphs and Manifolds (RLGM). arXiv:1903.02428 [cs.LG] https://arxiv.org/abs/1903.02428
- [70]doubleAI. 2026. ArgMaxRL: Generalizing MaxRL to Continuous Rewards. Blog post. https://www.doubleai.com/research/argmaxrl-generalizing-maxrl-to-continuous-rewards Accessed 2026-11-11.
- [71]Antonio Anna Mele. 2024. Introduction to Haar Measure Tools in Quantum Information: A Beginner’s Tutorial. Quantum 8 (2024), 1340. https://doi.org/10.22331/q-2024-05-08-1340






