arXiv:2610.22367quant-phOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.22367

Discovering state-of-the-art quantum circuits with large language models

Andi Gu, Alek H. Kemeny, Susanne F. Yelin, Mikhail D. Lukin

Andi Gu, 1,2,3,∗^{1,2,3,*} Alek H. Kemeny, 4^{4} Susanne F. Yelin, 1,2^{1,2} and Mikhail D. Lukin 1,2,5^{1,2,5}

1^{1}Harvard Quantum Initiative for Science and Engineering, Cambridge, MA 02138, USA

2^{2}Department of Physics, Harvard University, Cambridge, MA 02138, USA

3^{3}Anthropic STEM Fellows Program

4^{4}Anthropic

5^{5}QuEra Computing, 1380 Soldiers Field Road, Boston, MA 02135, USA

Significant efforts are currently being directed toward the implementation of large-scale quantum information processors, but realizing useful quantum advantage also requires the development of efficient quantum algorithms. While for many practical problems the dominant resource costs are associated with a small set of computational primitives, optimizing them in the quantum setting presents unique challenges, including a reversibility constraint absent from ordinary classical computation. Here we introduce an evolutionary framework in which large language models (LLMs) propose circuit designs and an independent evaluator verifies and scores them. We apply this framework to tasks spanning numerical computation, chemistry, optimization, quantum simulation, and number theory. In seven of the eight tasks, the discovered circuits significantly reduce both Toffoli and qubit counts relative to the state of the art. In the eighth, the search discovers a new reversible architecture for prime-field modular inversion. By handling reversibility differently, the architecture makes divsteps—a classical algorithm previously impractical for reversible integer arithmetic—viable and substantially improves the Toffoli-qubit trade-off for modular inversion. These results open the door for evaluator-guided LLM co-design of new algorithmic structures for quantum computation.

Computational primitives based on classical function evaluation play a central role in a wide range of quantum algorithms. Such primitives include decoding routines for optimization [1], numerical functions for quantum simulation [2], arithmetic routines for number theory [3], and quantum read-only memory (QROM), which coherently loads classically specified data into quantum registers [4]. To operate on quantum data, these functions must be compiled into circuits that can be executed coherently on quantum hardware. This imposes two constraints absent from ordinary classical programs. First, because the input may be in superposition, the circuit cannot inspect an intermediate value and select an ordinary classical control-flow path. Data-dependent behavior is instead expressed through controlled operations within a fixed gate sequence, so every branch contributes to the circuit's cost even if it applies only to some inputs. Second, the computation must be reversible: intermediate information cannot simply be overwritten or discarded. Temporary values must eventually be uncomputed, returning their qubits to their initial state and preventing residual information from remaining entangled with the output. Until they are uncomputed, these values occupy additional qubits. At the same time, when bounded error is permitted, machinery needed only for rare or atypical inputs can sometimes be omitted, reducing resource requirements while keeping the failure probability controlled. Efficient coherent compilation is of major practical importance, and recent reductions in resource requirements have come from coordinated changes to arithmetic algorithms, data representations, and their reversible implementation [5, 6]. Such redesigns are difficult for general quantum circuits because directly testing correctness can require exponentially expensive classical simulation or fully operational large-scale quantum processors. Automated circuit optimizers therefore typically preserve correctness by restricting the search to predefined equivalence-preserving rewrites [7], limiting them to variations of a fixed design.

Here we introduce a framework that pairs large language model (LLM) proposals with an independent evaluator that verifies and scores each candidate. We focus on a class of quantum circuits that compute a classical function ff: for an arbitrary input ∣ψ⟩=∑x,yαx,y∣x⟩∣y⟩|\psi\rangle = \sum_{x,y} \alpha_{x,y} |x\rangle |y\rangle, the circuit must act as ∣ψ⟩⟼∑x,yαx,y∣x⟩∣y⊕f(x)⟩|\psi\rangle \longmapsto \sum_{x,y} \alpha_{x,y} |x\rangle |y \oplus f(x)\rangle, where ∣x⟩|x\rangle and ∣y⟩|y\rangle are computational-basis states of the input and output registers, respectively. By linearity, this coherent action is correct if the circuit performs the required map on every computational-basis input: ∣x⟩∣y⟩⟼∣x⟩∣y⊕f(x)⟩|x\rangle |y\rangle \longmapsto |x\rangle |y \oplus f(x)\rangle. This basis-state reduction makes candidate circuits amenable to programmatic evaluation, since every allowed operation maps a computational-basis state to another computational-basis state, possibly changing its phase, but never creating a superposition [8]. The action of a candidate on any chosen input can therefore be simulated by tracking a bit string and its phase, rather than 2n2^n amplitudes. Resource accounting is also simple: we use the Toffoli count TT and the peak qubit count QQ, and rank circuits by their product, the TQ-cost. Together, these properties let us build an efficient, programmatic evaluator that checks the correctness and resource cost of any candidate circuit design.

Each search begins from a hand-written task specification and a blank program; the specification states the required circuit behavior but provides no implementation guidance. The LLM proposes a candidate and iteratively revises it using evaluator feedback (Figure 1(a)). Previous work represents candidates as sequences of gates or

(a) Discovery pipeline

(b) Conditional routing

Figure

x↦{x+cy,b=0,x+cz,b=1x\mapsto\begin{cases}x+cy,&b=0,\\x+cz,&b=1\end{cases}

Naïve

Routed

T=3n2+17n−2T = 3n^{2} + 17n - 2

T=3n2+17n−22T = \frac{3n^{2} + 17n - 2}{2}

(c) Decoding computational history

Naïve

Uncompute

Branch decoding

(d) Approximation and rare events

Resource demand

FIG. 1 Overview of the circuit-discovery framework. (a) A hand-written task specification defines the circuit design task (for example, Reed–Solomon decoding) and is given to an LLM. The LLM proposes architecturally different approaches (algorithm families; here extended Euclidean, Berlekamp–Massey, and Peterson–Gorenstein–Zierler (PGZ) decoders), which are then developed and optimized in parallel. Strong candidates are periodically shared between families to allow for cross-pollination of useful ideas. (b) Conditional routing reduces the cost of coherent control flow: for instance, two controlled multiply-adds (MADDs) become inexpensive controlled swaps and one shared arithmetic block. (c) Branch decisions that a naïve reversible computation stores during the forward pass (red) can instead be decoded from the current state during uncomputation. (d) When an application permits bounded error, allowing rare failures on atypical, costly inputs reduces resource requirements.

predefined circuit blocks [9, 10], which can obscure the algorithmic structure of the circuit. Our framework instead lets the LLM propose and revise candidates through a high-level Python interface, where reusable functions and ordinary programming constructs make that structure explicit. This allows a single conceptual change to reorganize operations throughout the circuit, while the evaluator tests its consequences for correctness and resource cost. However, purely iterative refinement of a single candidate can remain tied to the architecture from which it began, resulting in convergence to local (but not necessarily global) optima. We therefore start with an ideation stage in which the LLM is prompted to propose several distinct algorithm families, each representing a different approach to the problem. Circuits within each family are optimized independently in parallel, allowing the search to explore different strategies rather than only variations of one design. Well-performing candidates are periodically shared between families so that an idea discovered in one approach can inform another.

Across eight diverse compilation tasks, the discovered circuits repeatedly exhibit three common principles of algorithm–circuit co-design. These principles address the features of coherent compilation described above: expressing data-dependent control flow, making intermediate computations reversible without retaining their entire history, and using a failure budget to remove circuit resources devoted to atypical cases (see Figure 1).

DESIGN PRINCIPLES

One recurring principle in the circuits discovered by the search is to replace conditional arithmetic with conditional routing. A naïve coherent translation of a casewise classical algorithm includes a separately controlled arithmetic block for every branch. The discovered circuits instead use a representation in which the branches differ primarily in which values occupy particular computational roles. Relatively cheap controlled swaps then route the appropriate values into those roles, one unconditional arithmetic path performs the expensive work, and further routing places the results in their required registers. In this sense, where a classical program routes execution to the selected operation, the coherent circuit routes the selected data through a shared operation. The idea resembles bucket-brigade quantum random-access memory (QRAM) [11].

For example, consider four n-qubit fixed-point registers c, x, y, and z, together with a control qubit b. Suppose that we wish to perform

x⟼{x+cyforb=0,x+czforb=1,(1)x\longmapsto\begin{cases}x+cy&for b=0,\\x+cz&for b=1,\end{cases} \tag{1}

while returning cc, yy, and zz unchanged. A naïve implementation uses two controlled multiply-adds. Conditional routing instead swaps yy and zz according to bb, applies one uncontrolled multiply-add, and undoes the swap. For the standard schoolbook construction [12], this reduces the Toffoli count from Tnaive(n)=3n2+17n−2T_{\mathrm{naive}}(n) = 3n^2 + 17n - 2 to Trouted(n)=(3n2+17n−2)/2T_{\mathrm{routed}}(n) = (3n^2 + 17n - 2)/2, as shown in Figure 1(b).

More generally, conditional routing requires canonicalizing branch-dependent states into a representation on which the same expensive computation applies. Schematically, when the branch can be expressed as Ub=Rb−1KRbU_b = R_b^{-1} K R_b, the circuit need only control the inexpensive routing transformation RbR_b; the expensive kernel KK appears once and need not be controlled. Finding such a decomposition typically takes more than recognizing identical arithmetic in two branches: it exploits an equivalence in the required output so that apparently different updates become instances of the same computation. The difficulty lies less in the routing circuit than in determining which branch-dependent differences matter and which can be absorbed into a shared representation.

Reversibility creates a second challenge: reversing a conditional update requires knowing which branch was taken during the forward computation. A naïve implementation records each decision in a history stack whose size grows with the number of updates. But the branch decisions need not always be stored explicitly: different branches may leave distinguishable patterns in registers that remain available during uncomputation. As illustrated in Figure 1(c), the circuit can recover the branch bit from such a pattern, use it to select the appropriate inverse update, and then clear the recovered bit, so the register contents serve as an inexpensive record of the branch decisions. For example, suppose we have a register g that begins at g0=0g_0 = 0. In round j, conditioned on some branch bit bjb_j, we add 2j2^j, so that

gj+1=gj+bj2j.(2)g_{j+1}=g_{j}+b_{j}2^{j}. \tag{2}

For arbitrary values of gjg_j, there is no way to tell from gj+1g_{j+1} which branch was taken. Globally, however, there is an important invariant: gj<2jg_j < 2^j, and therefore bit jj of gj+1g_{j+1} must equal bjb_j. During uncomputation, the circuit can simply read this bit to recover bjb_j. The computation's evolving state thus supplies the branch decisions in reverse order without a separate history stack. In general, finding such a decoder requires the forward algorithm, its data representation, and its uncomputation procedure to be designed together. Viewed locally, an update may be ambiguous, since either branch can appear to admit a valid predecessor. The ambiguity can disappear once the circuit is restricted to states reachable from the prescribed initialization, where a relation across the registers can distinguish histories that no single register can.

The third principle exploits the small but finite failure probability permitted by most quantum algorithms. Turning this failure budget into resource savings, however, is not automatic. One must first identify the rare inputs that determine worst-case resource requirements. Unlike a classical program, a quantum circuit must contain the gates and ancillas required by every supported path. A rare input can therefore determine the circuit's Toffoli count or peak qubit count. Yet identifying such inputs is not enough: the circuitry supporting them may not be separable from the computation on typical inputs. The co-design task is to reorganize the computation so that the additional resources required by rare inputs are localized—for example, to extra iterations, stack entries, or arithmetic lanes. Those components can then be omitted while confining failure to the low-probability inputs that require them (Figure 1(d)). In what follows we show how these design principles result in significantly improved algorithmic circuits across a wide variety of quantum tasks.