Abstract
As quantum computing hardware advances, the demand for scalable, precise, and fully automated verification techniques for quantum circuits grows. This paper introduces a novel automata-based framework tailored for the verification of quantum circuits. In our approach, the problem is framed as a triple {P} C {S}, and the question is whether, given a set P of quantum states on the input of a circuit C, the set of quantum states on the output is equal to (or included in) a set S. Our framework leverages tree automata to compactly represent sets of quantum states and we develop transformers to implement the semantics of quantum gates over this representation. We implemented the proposed approach in a prototype tool and evaluated its performance against various benchmarks from the literature. The evaluation shows that our approach is quite scalable; for example, we managed to verify a large circuit with 40 qubits and 141,527 gates, or catch bugs injected into a circuit with 320 qubits and 1,758 gates, where all tools we compared with failed. Additionally, our work bridges quantum program verification and automata, opening new possibilities to exploit the richness of automata theory in quantum computing.
1. Introduction
Quantum computing holds the potential to solve complex problems that classical computers struggle to address. Since its inception, quantum algorithms have showcased capabilities beyond classical limits, exemplified by Shor’s factoring algorithm and Grover’s search algorithm—both of which can solve important computational problems provably faster than classical methods.16,20 For many years, the lack of hardware posed a barrier to implementing these algorithms, but recent advancements—including Google’s 2019 demonstration of a quantum computational advantage on a programmable superconducting processor—have marked significant milestones, though their results remain the subject of ongoing debate.3
As quantum computing moves toward practical applications, programming languages and systems for quantum computers are under active development to meet growing demands. Efficient algorithms have begun to emerge in fields such as optimization, machine learning (ML), and quantum chemistry, creating a pressing need for reliable verification methods to ensure circuit correctness in these applications.19 Verifying quantum circuits, however, presents unique challenges due to the exponential size of the computational space and the probabilistic nature of quantum operations. Traditional verification techniques are often unsuitable for quantum circuits, especially as they scale.
Currently, available automated analysis tools are limited in scalability, and many are inflexible in checking user-specified properties,2,7,12 or imprecise and unable to catch bugs.25 Scalable and flexible automated analysis tools for quantum circuits are indeed missing. In this paper, we introduce a novel approach to quantum circuit verification based on automata, a technique well-established in classical verification but largely unexplored in quantum contexts.5
In particular, we propose a new paradigm for analyzing and finding bugs in quantum circuits. In our approach, the problem is given by a Hoare triple , where is a quantum circuit and and are sets of quantum states. The verification question that we address is whether the set of output quantum states obtained by running on all states from is equal to (or included in) the set .
We create a framework for analyzing the considered class of properties based on (finite) tree automata (TAs).13 Languages of TAs are sets of trees; in our case, we consider TAs whose languages contain perfect binary trees with the height being the number of qubits in the circuit. Each branch (a path from a root to a leaf) in such a tree corresponds to one computational basis state (for example, or for a four-qubit circuit), and the corresponding leaf represents the complex amplitude of the state (we use an algebraic encoding of complex numbers by tuples of integers to have a precise representation and avoid possible inaccuracies when dealing with floating-point numbers; this encoding is sufficient for a wide variety of quantum gates, including the Clifford+ universal set for quantum computing). Sets of such trees can be, in many cases, encoded compactly using TAs (for example, storing the output of Bernstein-Vazirani’s algorithm4 over qubits requires a vector of complex numbers), but can be encoded by a linear-sized TA. For each quantum gate, we construct a transformation that converts the input states TA to a TA representing the gate’s output states, in a similar way as classical program transformations are represented in.14
Testing equivalence and inclusion between the TA representing the set of outputs of a circuit and the postcondition (from ) can then be done by standard TA language inclusion/equivalence testing algorithms.13,18 If the test fails, the framework generates a witness for diagnosis.
One application of our framework is as a quick underapproximation of a quantum circuit non-equivalence test. Our approach can switch to a lightweight specification when equivalence checkers fail due to insufficient resources and still find bugs in the design. Quantum circuit (non-)equivalence testing is an essential part of the quantum computing toolkit. Its prominent use is in verifying results of circuit optimization, which is a necessary part of quantum circuit compilation to achieve the expected fidelity of quantum algorithms running on real-world quantum computers, which are heavily affected by noise and decoherence. Already in the world of classical programs, optimizer bugs are being found on a regular basis in compilers used daily by tens of thousands of programmers. In the world of quantum, optimization is much harder than in the classical setting, with many opportunities to introduce subtle and hard-to-discover bugs into the optimized circuits. It is therefore essential to be able to check that an output of an optimizer is functionally equivalent to its input.
Testing quantum circuit (non-)equivalence is, however, a challenging task (QMA-complete).17 Due to its complexity, approaches that can quickly establish circuit non-equivalence are highly desirable to be used, for example, as a preliminary check before a more heavyweight procedure (see Burgholzer and Wille7 or Chen et al.8) is used. One currently employed fast non-equivalence check is to use random stimuli generation.6 Finding subtle bugs by random testing is, however, challenging—with no guarantees due to the immense (in general uncountable) underlying state space.
Our approach can be used as follows: We start with a TA encoding the set of possible input states (created by the user or automatically) and run our analysis of the circuit over it, obtaining a TA representing the set of all outputs. Then, we take the optimized circuit, run it over the same TA with inputs and obtain a TA . Finally, we check whether . If the equality does not hold, we can conclude that the circuits are not functionally equivalent (if the equality holds, there can, however, still be some bug that does not manifest in the set of output states).
We implemented our technique in a prototype called AutoQ and evaluated it over a wide range of quantum circuits, including some prominent quantum algorithms, randomly generated circuits, reversible circuits from RevLib,23 and benchmarks from the tool Feynman.2 The results show that our approach is quite scalable. We did not find any tool with the same functionality with ours and hence pick the closest state-of-the art tools—a circuit simulator SliQSim21 and circuit equivalence checkers Feynman2 (based on path-sum), Qcec7 (combining ZX-calculus, decision diagrams, and random stimuli generation), and SliQEC22—as the baseline tools to compare with. In the first experiments, we evaluated AutoQ’s capability in verification against pre- and post-conditions. We managed to verify the functional correctness (with regard to one input state) of a circuit implementing Grover’s search algorithm with 40 qubits and 141,527 gates. We then evaluated AutoQ on circuits with injected bugs. The results confirm our claim—AutoQ was able to find injected bugs in various huge-scale circuits, including one with 320 qubits and 1,758 gates, which other tools failed to find.
In addition to the practical utility, our work also bridges the gap between quantum and classical verification, particularly automata-based approaches such as regular model checking.5 As far as we know, our approach to the verification of quantum circuits is the first one based on automata. The enabling techniques and concepts involved in this work are, for example, the use of TAs to represent sets of quantum states and express the pre- and post-conditions, the compactness of the TA structure enabling efficient gate operations, and our TA transformation algorithms enabling the execution of quantum gates over TAs. We believe the connection of automata theory with the quantum world we establish can start new fruitful collaborations between the two rich fields.
Overview.
We use a concrete example to demonstrate how to use our approach. Assume we want to design a circuit constructing the Bell state, that is, a 2-qubit circuit converting a basis state to a maximally entangled state . We first prepare TAs corresponding to the precondition (Figure 1a) and postcondition (Figure 1b). Both TAs use as the root state and accept only one tree. One can see the correspondence between quantum states and TAs by traversing their structure. The precise definition will be given in Sections 2 and 3. Our approach will then use the transformers from Sections 4 to 6 to construct a TA recognizing the quantum states after executing the EPR circuit (Figure 1c) from the precondition TA (Figure 1a). We will then use TA language inclusion/equivalence tool VATA18 to check against the postcondition TA. If the circuit is buggy, our approach will return a witness quantum state that is reachable from the precondition but not allowed by the postcondition. From our experience of preparing benchmark examples, in many cases, this approach helps us finding bugs in incorrect designs.

2. Preliminaries
By default, we work with vectors and matrices over complex numbers . In particular, we use to denote the set of all complex matrices. Given a matrix , its transpose is the matrix obtained by flipping over its diagonal. A matrix is called a row vector and a matrix is called a column vector. To save vertical space, we often write a column vector using its row transpose . We use to denote the identity matrix of any dimension (which should be clear from the context). The conjugate of a complex number is the complex number , and the conjugate transpose of a matrix is the matrix where is the conjugate of . For example:
(1)The inverse of a matrix is denoted as . A square matrix is unitary if . The Kronecker product of and is the matrix ; For instance,
(2)2.1 Quantum circuits.
Quantum states. In a quantum system with qubits, the qubits can be entangled, and the system’s quantum state can be a quantum superposition of computational basis states . For instance, given a system with three qubits , , and , the computational basis state denotes a state where qubit is set to 0 and qubits and are set to 1. The superposition is then denoted in the Dirac notation as a formal sum , where are complex amplitudesa satisfying the property that . Intuitively, is the probability that when we measure the state in the computational basis, we obtain the state ; these probabilities need to sum up to 1 for all computational basis states. We note that the quantum state can alternatively be represented by a -dimensional column vectorb or by a pseudo-Boolean function , where for all . In the following, we will work mainly with the function representation, which we will see as a mapping from the domain of assignments to Boolean variables (corresponding to qubits) to . For instance, the quantum state can be represented by the vector or the function .
Quantum gates.
Operations in quantum circuits are represented using quantum gates. A -qubit quantum gate (that is, a quantum gate with inputs and outputs) can be described using a unitary matrix. When computing the effect of a -qubit quantum gate on the qubits of an -qubit quantum state represented using a -dimensional vector , we proceed as follows. First, we compute an auxiliary matrix where denotes the -dimensional identity matrix. Note that if is unitary, then is also unitary. Then, the new quantum state is computed as . For instance, let and be the Pauli- gate applied to the qubit .
(3)(4)
Representation of complex numbers.
To achieve accuracy with no loss of precision, in this paper, when working with , we consider only a subset of complex numbers that can be expressed by the following algebraic encoding proposed in Zulehner and Wille26 (and also used in Tsai et al.21):
(5)where and , the unit vector that makes an angle of with the positive real axis in the complex plane. A complex number is then represented by a five-tuple . Although the considered set of complex numbers is only a small subset of (it is countable, while the set is uncountable), the subset is already sufficient to describe a set of quantum gates that can implement universal quantum computation (cf. Section 4 for more details). The algebraic representation also allows efficient encoding of some operations. For example, because , the multiplication of by can be carried out by a simple right circular shift of the first four entries and then taking the opposite number for the first entry, namely , which represents the complex number . In the rest of the paper, we use and to denote the tuples for zero and one—that is, and , respectively. Using such an encoding, we represent quantum states by functions of the form .
Qubit measurement.
After executing a quantum circuit, one can measure the final quantum state in the computational basis. The probability that the qubit of a quantum state is measured as the basis state can be computed from the amplitude: When collapses to after the measurement, amplitudes of states with become 0 and amplitudes of states with are normalized using .
2.2 Tree automata.
Binary trees.
We use a ranked alphabet with binary symbols , , … and constant symbols , , …. A binary tree is a ground term over . For instance, , shown below, represents a binary tree. The set of nodes of a binary tree , denoted as , is defined inductively as a set of words over such that for every constant symbol , we define , and for every binary symbol
Tree automata.
We focus on tree automata on binary trees and refer the interested reader to Comon13 for a general definition. A (nondeterministic finite) tree automaton (TA) is a tuple
Run and language.
A run of
Assume a TA
Among others,
In
3. Encoding Sets of Quantum States with Tree Automata
Observe that we can use (perfect) binary trees to encode functions
encodes the function
Here we consider the set of
For the case when
We denote the resulting TA by
Formally a TA
4. Quantum Gates Encoding
With TAs used to concisely represent sets of quantum states, the next task is to capture the effects of applying quantum gates on this representation. When quantum states are represented as vectors, gates are represented as matrices and gate operations are matrix multiplications. When states are represented as binary trees, we need a new representation for quantum gates and their operations. Inspired by the work of Tsai et al.,21 we introduce symbolic update formulae, which describe how a gate transforms a tree representing a quantum state. Later, we will lift the tree update operation to a set of trees encoded in a TA.
We use the algebraic representation of quantum states from Equation 5 also for their symbolic handling. For instance, consider a system with qubits
for
Instead of executing the quantum gate by performing a matrix-vector multiplication, we will capture its semantics symbolically by directly manipulating the tree function
In the previous,
Equipped with the operators, we can now proceed to express the semantics of
When we view
On the other hand, the last two summands in the right-hand side of Equation 8, that is,
The tree view of
Finally, by summing
Observe that the sum effectively swaps the left and right subtrees of each
For multi-qubit gates, the update formulae get more complicated, since they involve more than one qubit. Consider, for example, the “controlled-
The sum consists of the following two summands:
The summand
says that when the control qubit is 0, the values of all qubits stay the same.R x c ¯ ( T ) The summand
handles the case whenR x c ( R x t ¯ ( P x t ( T ) ) + R x t ( P x t ¯ ( T ) ) ) is 1. In such a case, we apply thex c gate onX (observe that the inner term is the update formula ofx t in Equation 13).X t
One can obtain symbolic update formulae for other quantum gates in a similar way. In Table 1 we give the formulae for the gates supported by our framework.
Gate | Update |
---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
For a gate
The symbolic update formulae in Table 1 are correct (with regard to the standard semantics of quantum gates.
A note on expressivity.
The expressivity of our framework is affected by the following factors:
Algebraic complex number representation
: This representation can arbitrarily closely approximate any complex number: when( a , b , c , d , k ) , the quintupleb = d = 0 represents the number( a , 0 , c , 0 , k ) Then any complex number can be approximated arbitrarily closely by picking suitable1 2 k ( a + i c ) ,a , andc .k Supported quantum gates: We covered all standard quantum gates supported in modern quantum computers except parameterized rotation gate. From Solovay-Kitaev theorem,15 gates performing rotations by
can be approximated with an error rateπ 2 k withϵ -many gates that we support.O ( log 3 . 97 ( 1 ϵ ) ) Tree automata structure: We use non-deterministic transitions of tree automata to represent a set of trees compactly. Nevertheless, we can currently encode only a finite set of states. Hence, we cannot express, for example, all quantum states where the amplitudes of
and| 10 ⟩ are the same. In Chen et al.,10 we extend the work to allow using variables as leave symbols and this set becomes expressible.| 01 ⟩
In the next two sections, we discuss how to lift the tree update operation to a set of trees encoded in a TA. Our framework allows different instantiations. We will introduce two in this paper, namely the (i) permutation-based (Section 5) and (ii) composition-based (Section 6) approach. The former is simple, efficient, and works for all but the
5. Permutation-Based Encoding of Quantum Gates
Let us first look at the simplest gate
The update formulae of gates
The cases of multi-qubit gates
We first construct the TA of the inner term, the shaded area, which are TAs for
n | #q | #G | AutoQ-Hybrid | AutoQ-Composition | SliQSim | Feynman | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
before | after | analysis | = | before | after | analysis | = | time | verdict | time | ||||||||
BV | 95 | 96 | 241 | 193 | (193) | 193 | (193) | 6.0s | 0.0s | 193 | (193) | 193 | (193) | 7.1s | 0.0s | 0.0s | equal | 0.5s |
96 | 97 | 243 | 195 | (195) | 195 | (195) | 5.9s | 0.0s | 195 | (195) | 195 | (195) | 7.1s | 0.0s | 0.0s | equal | 0.5s | |
97 | 98 | 246 | 197 | (197) | 197 | (197) | 6.3s | 0.0s | 197 | (197) | 197 | (197) | 7.4s | 0.0s | 0.0s | equal | 0.6s | |
98 | 99 | 248 | 199 | (199) | 199 | (199) | 6.5s | 0.0s | 199 | (199) | 199 | (199) | 7.7s | 0.0s | 0.0s | equal | 0.6s | |
99 | 100 | 251 | 201 | (201) | 201 | (201) | 6.7s | 0.0s | 201 | (201) | 201 | (201) | 7.8s | 0.0s | 0.0s | equal | 0.6s | |
Grover-Sing | 12 | 24 | 5,215 | 49 | (49) | 71 | (71) | 11s | 0.0s | 49 | (49) | 71 | (71) | 49s | 0.0s | 2.8s | timeout | |
14 | 28 | 12,217 | 57 | (57) | 83 | (83) | 31s | 0.0s | 57 | (57) | 83 | (83) | 2m26s | 0.0s | 18s | timeout | ||
16 | 32 | 28,159 | 65 | (65) | 95 | (95) | 1m29s | 0.0s | 65 | (65) | 95 | (95) | 6m59s | 0.0s | 1m41s | timeout | ||
18 | 36 | 63,537 | 73 | (73) | 107 | (107) | 4m1s | 0.0s | timeout | 9m27s | timeout | |||||||
20 | 40 | 141,527 | 81 | (81) | 119 | (119) | 10m56s | 0.0s | timeout | timeout | timeout | |||||||
MCToffoli | 8 | 16 | 15 | 33 | (42) | 104 | (149) | 0.0s | 0.0s | 33 | (42) | 404 | (915) | 2.8s | 0.0s | 1.6s | equal | 0.0s |
10 | 20 | 19 | 41 | (52) | 150 | (216) | 0.0s | 0.0s | 41 | (52) | 1,560 | (3,607) | 27s | 0.0s | 6.1s | equal | 0.1s | |
12 | 24 | 23 | 49 | (62) | 204 | (295) | 0.0s | 0.0s | 49 | (62) | 6,172 | (14,363) | 6m48s | 0.1s | 25s | equal | 0.1s | |
14 | 28 | 27 | 57 | (72) | 266 | (386) | 0.1s | 0.0s | timeout | 1m40s | equal | 0.1s | ||||||
16 | 32 | 31 | 65 | (82) | 336 | (489) | 0.2s | 0.0s | timeout | timeout | equal | 0.2s | ||||||
Grover-All | 6 | 18 | 357 | 37 | (43) | 252 | (315) | 3.3s | 0.0s | 37 | (43) | 510 | (573) | 12s | 0.0s | 1.7s | timeout | |
7 | 21 | 552 | 43 | (50) | 481 | (608) | 10s | 0.0s | 43 | (50) | 1,123 | (1,250) | 42s | 0.0s | 5.4s | timeout | ||
8 | 24 | 939 | 49 | (57) | 934 | (1,189) | 39s | 0.1s | 49 | (57) | 2,472 | (2,727) | 2m40s | 0.0s | 26s | timeout | ||
9 | 27 | 1,492 | 55 | (64) | 1,835 | (2,346) | 2m17s | 0.4s | 55 | (64) | 5,421 | (5,932) | 10m13s | 0.1s | 2m5s | timeout | ||
10 | 30 | 2,433 | 61 | (71) | 3,632 | (4,655) | 9m48s | 2.1s | timeout | 11m31s | timeout |
6. Composition-Based Encoding of Quantum Gates
In the composition-based approach, we develop TA operations for all operations in the symbolic update formulae from Table 1—projection
7. Experimental Evaluation
We implemented the proposed TA-based algorithm as a prototype tool named AutoQ in C++. We provide two settings: Hybrid, which uses the permutation-based approach (Section 5) to handle supported gates and switches to the composition-based approach for the other gates, and Composition, which handles all gates using the composition-based approach (Section 6). Further details are available in the original paper.11 We evaluated AutoQ in two use cases.
7.1 Circuit verification.
In the first experiment, we compared how fast AutoQ computes the set of output quantum states and checks whether the set satisfies a given post-condition. We compared against the simulator SliQSim21 in the setting when we ran it over all quantum states encoded in the pre-condition of the quantum algorithm and accumulated the times. We also include the time taken by Feynman2 to check the equivalence of the circuits with themselves. Although checking equivalence of quantum circuits is a harder problem than what we are solving (so the results cannot be used for direct comparison with AutoQ), we include these results in order to give an idea about the hardness of the circuits for path-sum-based approaches.
We ran this experiment on a benchmark composed of well-known quantum circuits, where the semantics was known to us so that we could construct TAs with pre- and post-conditions. These were the following: BV, MCToffoli, Grover-Sing, and Grover-All. We give the results in Table 2. Both BV and Grover-Sing work with only one input state, which should be most favorable for simulators. Surprisingly, for the case of Grover-Sing, AutoQ outperforms SliQSim on large cases (out of curiosity, we tried to run SliQSim on Grover-Sing (
7.2 Finding bugs.
In the second experiment, we compared AutoQ with the equivalence checkers Feynman,2 Qcec,7 and SliQEC,8 and evaluated the ability of the tools to determine that two quantum circuits are non-equivalent (this is to simulate the use case of verifying the output of an optimizer). We took circuits from the benchmarks FeynmanBench, Random, and RevLib, and for each circuit, we created a copy and injected an artificial bug (one additional randomly selected gate at a random location). Then we ran the tools and let them check circuit equivalence; for AutoQ, we let it compute two TAs representing sets of output states for both circuits for the given set of input states and then checked their language equivalence with Vata.18
Our strategy for finding bugs with AutoQ (we used the Hybrid setting) was the following: We started with a TA representing a single basis state, that is, a TA with no top-down nondeterminism, and gradually added more non-deterministic transitions (in each iteration one randomly chosen transition) into the TA, making it represent a larger set of states, running the analysis for each of the TAs, until we found the bug. This proved to be a successful strategy, since running the analysis with an input TA representing, for example, all possible basis states, might be too challenging (generally speaking, the larger is the TA representing the set of states, the slower is the analysis).
The results that we obtained show that our approach to hunting for bugs in quantum circuits is beneficial, particularly for larger circuits where equivalence checkers do not scale. For such cases, AutoQ can still find bugs using a weaker specification. For instance, AutoQ was able to find bugs in some large-scale instances from RevLib with hundreds of qubits where both Feynman and Qcec fail (see11 for more details).
8. Conclusion
We presented a foundational framework for automata-based verification of quantum circuits, demonstrating its effectiveness through empirical studies. We believe that applying automata to quantum verification establishes a valuable bridge between quantum and classical verification approaches, with the potential to adapt many classical verification techniques to quantum settings, for instance, by replacing constant tree leaf values with symbolic variables10 and tracking the symbolic values in a similar way as in symbolic execution. This allows the verification of properties such as whether the probability of finding a solution exceeds 90% or increases over time. We also extended the model’s applicability from quantum circuit to quantum program verification9 based on a classical deductive program verification approach.
Note that TAs allow representation of infinite languages, yet we only use them for finite ones, which might seem like the model is overly expressive. We, however, stick to TAs for the following two reasons: (i) there is an existing rich toolbox for TA manipulation and minimization, for example, Comon13 and Lengál18, and (ii) we want to have a robust formal model for extending our framework to parameterized verification, that is, proving that an
There remain considerable opportunities for further advancements in this area, including but not limited to: (i) automated loop invariant synthesis procedures for quantum program verification and more fine-grained analyses such as probabilistic reachability; (ii) developing abstractions and refinement scheme suited to quantum verification; (iii) verification of quantum circuits simulating physical phenomena, for example, those implementing Hamiltonian simulation; and (iv) integrating automata with other quantum verification frameworks like Quantum Hoare Logic24 and methods for equivalence checking to enable a more automated, systematic verification pipeline across diverse verification paradigms. These directions highlight the vast potential for refining and expanding automata-based quantum verification, promising a pathway to more robust, scalable, and versatile tools for analyzing complex quantum systems.
Acknowledgments
This material is based on a work supported by the Czech Ministry of Education, Youth and Sports project LL1908 of the ERC.CZ programme; the Czech Science Foundation project 23-07565S; the FIT BUT internal project FIT-S-23-8151; National Science and Technology Council, R.O.C., projects NSTC 111-2119-M-001-004, NSTC-112-2222-E-001-002-MY3, NSTC-113-2119-M-001-009, and NSTC-113-2222-E-027-007, ASOFR (Air Force Office of Scientific Research) project FA2386-23-1-4107, Foxconn research project 05T-1120327-1C, Academia Sinica Grand Challenge Seeding Project AS-GCS-113-M06, Academia Sinica Investigator Project Grant AS-IV-114-M07.
Join the Discussion (0)
Become a Member or Sign In to Post a Comment