Partial Equivalence Checking of Quantum Circuits
Abstract
Equivalence checking of quantum circuits is an essential element in quantum program compilation, in which a quantum program can be synthesized into different quantum circuits that may vary in the number of qubits, initialization requirements, and output states. Verifying the equivalences among the implementation variants requires proper generality. Although different notions of quantum circuit equivalence have been defined, prior methods cannot check observational equivalence between two quantum circuits whose qubits are partially initialized, which is referred to as partial equivalence. In this work, we prove a necessary and sufficient condition for two circuits to be partially equivalent. Based on the condition, we devise algorithms for checking quantum circuits whose partial equivalence cannot be verified by prior approaches. Experiment results confirm the generality and demonstrate the efficiency and effectiveness of our method. Our result may unleash the optimization power of quantum program compilation to take more aggressive steps.
Index Terms:
Quantum circuit, quantum computing, quantum measurement, equivalence checkingI Introduction
Equivalence checking plays an important role in the design flow of modern integrated circuits. It ensures the transformations done in the corresponding synthesis steps do not introduce errors. Many scalable techniques, such as random simulation, satisfiability solving, decision diagrams, and structural similarity detection, have been developed and widely applied in classical circuit verification [1, 2, 3, 4, 5, 6, 7]. Due to the rapid progress of hardware and software developments in quantum computation, quantum circuit verification, especially equivalence checking, arises as an important issue in quantum program compilation. Although practical quantum circuits remain relatively small until now, it remains challenging to their equivalence checking due to extraordinary quantum properties. Moreover, as quantum computing technology evolves, the size of quantum circuits will continue growing. Efficient equivalence checking tools for quantum circuits are essential.
Many approaches to equivalence checking of quantum circuits have been proposed [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]. Among them, decision diagrams are a widely adopted data structure for quantum state and operator representation and manipulation [8, 9, 10, 13, 19]. Also, techniques, such as miter construction [8, 10, 12, 13, 18] or tensor network computation [11], have been applied. Some of them focus on the equivalence of reversible circuits, which realize permutation functions, whereas others address the equivalence of more general quantum circuits. For the latter, most of them require total equivalence, namely, the identity of the output states (modulo a global phase difference) between the two circuits under verification. However, since measurement is the only way to extract information from a quantum system, total quantum state equivalence may be unnecessary and only observational equivalence matters. That is, two circuits exhibit the same probability for every possible measurement outcome under a fixed measurement basis. Furthermore, not all qubits of a circuit need to be measured and there can be a set of initial states to be verified not just a particular single initial state. To accommodate such different design constraints, we relax the notion of quantum circuit equivalence and define a generalization, called partial equivalence. That is, two circuits are partially equivalent if, given any valid initial input state, they exhibit the same probability for each measurement outcome. Therefore, two partially equivalent circuits do not exhibit statistical differences by observed measurements. Essentially, the generality of partial equivalence allows more flexibility for quantum circuit synthesis. Fig. 1 shows an example where and are partially equivalent, but not totally equivalent.
Apart from its application in quantum circuit synthesis, partial equivalence checking has its natural application in quantum program compilation. As the quantum computing technology evolves, many quantum programming languages have been developed, e.g., [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]. Although nowadays most quantum programming languages are abstracted at the gate level, high-level languages will get their increasing presence in the future. Their compilation may require making trade-offs between ancilla bits and quantum gates. To verify the correctness of different compilation choices may require the defined partial equivalence.
Equivalence based on measurement results is not new, nor is the relaxation requiring only some of the input qubits to be data qubits and some of the output qubits to be measured qubits. In fact, partial equivalence can be seen as the case that all principal output qubits in Definition 3 of [32] are to be measured. However, there are no corresponding checking methods so far, and none of the prior work [18, 19, 32, 33, 34] can fully resolve the partial equivalence checking problem. In particular, equivalence up to a relative phase discussed in [18] can only cover the case that all output qubits are measured; the method considering measurement-based equivalence in [19] is used for reversible circuits only; the initial state is given and fixed in [32] and [33]; sequential circuit verification in [34] is limited to the assumption that the number of measured output qubits cannot be smaller than the number of data input qubits. In this work, we are not constrained by these limitations. Our methods can be applied to general cases of checking partial equivalence relations. Moreover, they are compatible with the state-of-the-art SliQEC [8] system, which uses Boolean functions represented by decision diagrams to store and manipulate matrices.
The main results of this work include:
-
1.
We characterize partial equivalence (in Section III), which subsumes prior notions of quantum circuit equivalence.
-
2.
We prove a necessary and sufficient condition for two circuits to be partially equivalent (in Section IV).
-
3.
We develop algorithms for partial equivalence checking under general and special settings (in Section V).
-
4.
We conduct experiments to demonstrate the feasibility and effectiveness of our algorithms and the practical applicability of partial equivalence (in Section VI).
II Preliminaries
We briefly provide some background and define notations.
II-A Boolean Function and Decision Diagram
For Boolean connectives, we denote conjunction by “” (sometimes omitted in a Boolean expression for brevity), disjunction by “,” exclusive-or by “,” and negation by an overline. Given a Boolean function , the positive cofactor of on , denoted , is
(1) |
Similarly, the negative cofactor of on , denoted , is
(2) |
The reduced ordered binary decision diagram (ROBDD), referred to as BDD in the sequel, is a canonical form for Boolean function representation [35]. There are efficient BDD packages for Boolean function manipulation. A BDD is a directed acyclic graph consisting of non-terminal nodes and terminal-0 and terminal-1 nodes. Each non-terminal node is associated with a decision variable and has two children and pointed to by the 0-branch and 1-branch of , respectively. Each node in a BDD corresponds to a Boolean function. Let be the functions of node with decision variable and its two children , respectively. Then and , and the Shannon expansion holds. Fig. 2 shows a BDD of function .
II-B Quantum States and Quantum Circuits
For a quantum system, at the input end, a qubit is called a data qubit if it is associated with the input data and a non-data qubit otherwise. At the output end, a qubit is called a measured qubit if it is to be measured and a non-measured qubit otherwise. In an -qubit quantum system, a quantum state can be represented by a vector , where each is a complex number and the norm of satisfies . We use to represent the vector , to represent the vector , and so on. For state , we let the binary number of integer be expressed by qubits with being the most significant bit. In the sequel, we assume that non-data qubits are fixed to the initial state and refer to them as ancilla qubits. This assumption is general in that any other initial state can be transformed from .
If we measure all the qubits of under the computational basis, there will be a probability for the system to get into state . Also, if we measure only the first (more significant) qubits, for , of , the probability of obtaining a state , for , of the measured qubits equals
(3) |
where .
The evolution of the state of a closed quantum system can be described by quantum gates. For an -qubit quantum system, a quantum gate can be defined by a unitary matrix of complex numbers. A unitary matrix is a matrix satisfying , where is the conjugate transpose of and is the identity matrix. Thus, is also the inverse of . A quantum circuit is made up of a series of quantum gates . Let their corresponding unitary matrices be and let be the initial state. Then the final output state of the circuit is derived by the product
(4) |
Therefore, we can view the whole circuit as a quantum gate with the unitary matrix
(5) |
Particularly, when an -qubit quantum circuit with unitary matrix yields a permutation of the computational basis , it is referred to as a reversible circuit [36, 37, 38, 39].
Because only the global unitary operator of a quantum circuit matters in our discussion, for simplicity we abstract away gate implementation details and denote an -qubit quantum circuit as a 4-tuple for , where
-
•
is the number of data qubits, specifically, ,
-
•
is the number of measured qubits, specifically, ,
-
•
is the number of non-data qubits, and
-
•
is the global unitary operator of of size .
Note that above we make the data qubits and measured qubits follow the same order. This arrangement is without loss of generality as the qubits can be reordered by swap gates.
Given a quantum circuit with the data qubits prepared at initial state , we denote the probability of collapsing to state upon a measurement on the measured qubits under the computational basis as , which can be calculated by
(6) |
where and denotes the entry of .
II-C Algebraic and Implicit Representation of Matrices
Following [41], we represent a complex number algebraically by
(7) |
where and . In [8], the bit-slicing technique [40] is applied to represent a complex matrix by one integer-type variable for the -coefficient and -variable BDDs for the -, -, -, -coefficients, assuming an integer is encoded with a bit-vector of size . Let the BDDs of the bit of the -coefficient Boolean matrices be , respectively, for . In the sequel, we do not distinguish among and simply use to refer to every individual of these BDDs. Essentially, such a function of variables implicitly represents a Boolean matrix, whose rows and columns are indexed by the output qubits and input qubits, respectively, in our context. For qubit , two variables and are introduced to encode its corresponding output qubit and input qubit, respectively, for the Boolean matrix. The variables and are referred to as the row-variables and column-variables, respectively. Effectively, is a function over variables . That is, the entry of the Boolean matrix corresponds to the Boolean value of for and being substituted with the -bit binary numbers of and , respectively. In addition to the implicit matrix representation using Boolean functions, the multiplication of matrices can be done effectively through Boolean function manipulations as shown in [8].
III Partial Equivalence Problem
In this section, we formally define partial equivalence between two quantum circuits, and compare it to other equivalence notions in the literature.
III-A Problem Statement
The partial equivalence relation is formally defined as follows.
Definition 1 (Partial Equivalence).
Two circuits and are partially equivalent, denoted by , if
(8) |
holds for any state vector of size and any .
Note that, without loss of generality, we assume two circuits have the same number of ancilla qubits because we can always add dummy ancilla qubits to the one with fewer ancilla qubits. The partial equivalence checking problem can be stated as follows.
Problem 1 (Partial Equivalence Checking).
Given two circuits and , we are asked to check whether and are partially equivalent.
Partial equivalence can be applied to check the conformance between two quantum circuits that compute the same function but may produce different output states.
We remark that, in prior work [32], the notion of m-equivalence and q-equivalence are defined. For m-equivalent circuits, it requires that all qubits have fixed initial states, and it allows that we only measure on part of the qubits. Two circuits are m-equivalent if they have the same probability distribution of measurement outcomes. That is, m-equivalence is a special case of partial equivalence when we set for the circuits under verification. On the other hand, for q-equivalence, ancilla qubits are allowed. Besides, the output qubits are divided into two groups, the main output qubits and the garbage qubits. It is required that if we measure the garbage qubits, the quantum states of the main output qubits cannot be affected by the measurement outcomes of the garbage qubits. Two circuits are q-equivalent if the output states of the main output qubits between the two circuits are the same for any input state.
To demonstrate the usefulness of partial equivalence, we take the period-finding quantum algorithm [42] as an example. In Fig. 3 (a), the circuit computes the function
(9) |
In Fig. 3 (b), the circuit computes the function
(10) |
It can be seen that the and have the same period 4 (for mapping and mapping ). For the circuit in Fig. 3 (c), let the first register as the data qubits and the second register as the ancilla qubits. Let (resp. ) be the circuit of Fig. 3 (c) with the oracle blocks being substituted with function (resp. ). Then and are partially equivalent under despite the fact that neither of total equivalence and q-equivalence holds and m-equivalence is not applicable them. The fact that and are not totally equivalent is immediate. Also, we verify that the q-equivalence [32] does not hold because the output state of the register is affected by the register; the m-equivalence is not applicable because only the register is taken as the ancilla qubits. To the best of our knowledge, no previous tools can check this equivalence.
We observe that when the two circuits under verification have no ancilla qubits, the computation of their partial equivalence checking can be simplified. It motivates the consideration of the following special case.
Problem 2 (Zero-Ancilla Partial Equivalence Checking).
Given two circuits and , we are asked to check whether and are partially equivalent.
For instance, consider the aforementioned and circuits. If we properly add some quantum gates to the beginning of the second register of (e.g., achieving the mapping for and for ), then and can remain partially equivalent even if all qubits are taken as data qubits. In this case both circuits have no ancilla qubits (i.e., ).
III-B Comparison of Different Equivalences
There have been several quantum circuit equivalences being studied. We compare them with the partial equivalence.
Besides the previously mentioned m-equivalence and q-equivalence, the most common definition of quantum circuit equivalence is total equivalence, which requires that two circuits produce the same state vector (up to a global-phase difference) for any input state [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]. That is, the output states of the two circuits should be numerically identical except for a scalar multiplication factor.
Another well-known equivalence is functional equivalence of reversible circuits. In reversible circuits, they may also include ancilla qubits, and some qubits may be discarded in the end (i.e., we do not care about their measurement results). Some may even include don’t-care conditions, which means that we do not care about all of or part of the measurement results under some input states [36].
Though partial equivalence looks similar to functional equivalence of reversible circuits and m-equivalence, we note that partial equivalence is much more complex, because measurement is a non-linear operation and does not have superposition property. That is, even if we know
(11) |
for , we cannot infer
(12) |
Therefore, even with a brute-force search to enumerate the probability distribution under for all , the partial equivalence relation is still not guaranteed. Some other approaches to checking partial equivalence are essential.
We briefly summarize the main differences between the equivalence types mentioned above in Table I. We further illustrate the relations between partial equivalence and other equivalences in Fig. 4. Note that partial equivalence subsumes total equivalence, functional equivalence of reversible circuits, and q-equivalence as these equivalences are special cases of partial equivalence. Specifically, it is evident that totally equivalent circuits must be partially equivalent. For reversible circuits, it can be derived from definition that is either 0 or 1 for all , so Eq. (12) holds. Therefore, functionally equivalent reversible circuits without don’t care conditions must be partially equivalent. As for m-equivalence, it can be clearly seen that we can apply partial equivalence to m-equivalence by setting . For q-equivalence, as the states of main output qubits between two circuits are identical, we must get the same probability distribution of the two circuits if we measure on the main output qubits. Thus, q-equivalent circuits must be partially equivalent.
equivalence type | equivalence form | inputs | outputs | special restrictions | ||
---|---|---|---|---|---|---|
partial equivalence | measurement probability | allow ancilla | allow garbage | - | ||
total equivalence | numerical quantum state | usually no ancilla | usually no garbage | - | ||
|
Boolean values | allow ancilla | allow garbage | restricted on reversible circuits | ||
m-equivalence | measurement probability | no ancilla | allow garbage | - | ||
q-equivalence | numerical quantum state | allow ancilla | allow garbage | main output independent of garbage output |
IV Necessary and Sufficient Conditions of Partial Equivalence
In this section, we derive a necessary and sufficient condition for partial equivalence, which can be directly used to solve Problem 1 if the matrices of both circuits are explicitly given. For the special case with no ancilla qubits, we show that a simpler necessary and sufficient condition exists.
We define the following notation to locate some sub-matrices.
Definition 2.
Given a circuit , let represents the entry of and , then of size is defined to be
(13) |
where , . An example for is illustrated as follows. In addition, we use to represent the unit vector of length and the position ( starts from 0) being 1.
We remark that the definition of is critical in deriving the necessary and sufficient condition for the partial equivalence. We will show this point in the following section.
IV-A Property of Partial Equivalence
To solve Problem 1, we first derive the condition when holds.
Theorem 1 (Partial Equivalence).
Given two circuits and , then if and only if
(14) |
holds for all and .
Proof.
Let the input state vector . The matrix and will respectively be applied on . Let’s consider the output . Let and denotes the entry of , then
(15) |
where denotes the real part of the complex number . Similarly, we get
(16) |
If , then must hold for all , so must hold for all and . We also need the above equality hold for any . Thus,
∎
As mentioned before, brute-force search does not work for partial equivalence. Therefore, Theorem 1 provides the first way to formally verify the partial equivalence relation.
From Theorem 1, we can see that whether only depends on the ’s of two matrices, and is not related to other entries.
IV-B Property of Zero-Ancilla Partial Equivalence
For the case that both circuits have no ancilla qubits, we provide another necessary and sufficient condition for partial equivalence as follows.
Theorem 2 (Zero-Ancilla Partial Equivalence).
Given and , then if and only if is in the following form.
(17) |
where each is a square matrix, and the other entries in not labeled are 0.
Proof.
Firstly we show a transformed problem. By definition, if and only if for any and . Let , , and then we have . Because and are both reversible matrices, and can be any vector of size (and satisfying ). Thus, if and only if for any and any , where is the circuit with unitary matrix , and is the identity circuit that directly sends the input to the output.
We will use the transformed problem in the following proof.
(i) the “only if ” part:
If , must hold for any and any . We firstly consider . We can easily find that
(18) |
Let and denotes the entry of . To make , should be 0 for all .
Following the same method, now we generally consider , where . Let , then
That is, must be in form Eq. (17).
(ii) the “if ” part:
If is in form Eq. (17), we firstly note that:
(19) |
Because is a unitary matrix, must be identity for all . Thus, each must be a unitary matrix.
Now for any , let , where each is of length . That is, we equally divide into groups. Then
(20) |
Because is unitary, it is true that
(21) |
Because , holds for all and . Therefore, . ∎
V Algorithms for Partial Equivalence Checking
In this section, we present algorithms to solve Problems 1 and 2 based on the theorems established in Section IV. We emphasize that these algorithms can be realized by using the bit-sliced algebraic representation of matrices [8].
V-A Partial Equivalence Checking Algorithm
If and are given in their explicit numerical form, we can easily extract ’s and enumerate all triples to check whether by Theorem 1, with steps of complex number multiplications. However, as and may be in an implicit form, we give another approach by using matrix entry manipulation and matrix multiplication, as shown in Algorithm 1.
To better illustrate steps 5 and 6, we note that after step 6, each for different and should be separated into different columns, and all entries not storing values of are 0. An example of with after this step is shown as follows.
To see the correctness of Algorithm 1, we first consider the case . It can be easily checked that after step 8, the entry of will store the value of , while the other entries are 0. Note that in step 2 we have added some ancilla qubits and now . Therefore, we can easily check whether holds to determine whether .
For the case , the entry of still stores the value of , but only for those with . For , the value of does not exist, but we can see that the entry of will always be 0 because the entries in the column of are all 0’s after step 6. That is, though we do not clear these entries in step 8, they are automatically set to 0. Therefore, we can still determine whether by checking whether .
We further point out that this can be done quite easily using bit-sliced algebraic representation of a matrix [8], as shown in Algorithm 2. As introduced before, a matrix is represented by multiple BDDs, but here we use single and as representatives for all BDDs in and respectively for convenience. In steps 5, 7, 10, 13, we mean to do the same operation on each BDD, and in step 15, we need all corresponding BDDs of the two circuits to be the same.
We use steps 4 to 10 in Algorithm 2 to replace steps 5 and 6 in Algorithm 1. In steps 4 to 5, we divide the columns of into parts. For each part, we use cofactor operation to copy the leftmost columns to the other columns. In steps 6 to 9, we remove unwanted entries to ensure that each column only contains different ’s. The remaining steps have similar functions as in Algorithm 1 but are rewritten in Boolean form.
We can see that with the help of BDD, the operations can be simplified and are more efficient. To be precise, two applications of inverse circuit operations are required, and only Boolean AND, OR, and cofactor operations are needed, which is linear to and . As BDDs often give a good data compression, there may be a significant speedup for Algorithm 2.
V-B Zero-Ancilla Partial Equivalence Checking Algorithm
Similarly, we can directly use Theorem 2 to solve Problem 2 if and are explicitly given. Here we emphasize that it is also easy to check this property using bit-sliced algebraic representation of the matrix. The checking procedure is shown in Algorithm 3. Again, we mean to do the same operation on each BDD in step 5, and we require all BDDs to be constant in step 6.
VI Experimental Evaluation
We implemented Algorithms 2 and 3 in C/C++ under the framework of SliQEC [8], and adopted CUDD [43] package for BDD manipulation. All experiments were conducted on a server with Intel Xeon Silver 4210 CPU at 2.20 GHz and 128 GB RAM. The reported runtime refers to CPU time in seconds. The time-out (TO) limit is set to 600 seconds.
We conducted experiments of partial equivalence checking on benchmarks of period-finding instances, randomly generated instances, Grover search instances, and reversible circuit instances. We also experimented total equivalence checking on randomly generated instances. The results are discussed as follows.
VI-A Checking Period-Finding Algorithm
We used the tool proposed in [39] to implement the reversible circuits realizing for and for , which have the same period with input state . We then substituted the reversible circuits into the oracle used in the period finding algorithm. We let the first register consist of 3 qubits, and used one extra ancilla qubit to implement quantum Fourier transform. We then used Algorithm 2 to test the equivalence relation. As mentioned above, this type of equivalence cannot be verified by previous tools, and Algorithm 2 is the only way to check their equivalence relation. We have tested the pairs for all and . The parameters are set to and .
The results are shown in Table II. All test cases yield correct answers. As these test cases are relatively small, we can see that the runtime is roughly proportional to the gate count. On the other hand, the memory usages are roughly the same because all test cases have similar numbers of qubits.
|
|
time (s) |
|
||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
3 | 5 | 115 | 87 | 0.180 | 12.874 | ||||||
3 | 7 | 108 | 136 | 0.354 | 13.914 | ||||||
3 | 11 | 227 | 325 | 0.794 | 14.496 | ||||||
3 | 13 | 353 | 248 | 0.796 | 13.959 | ||||||
5 | 7 | 143 | 164 | 0.441 | 13.922 | ||||||
5 | 11 | 381 | 388 | 1.083 | 14.512 | ||||||
5 | 13 | 353 | 507 | 0.806 | 13.173 | ||||||
7 | 11 | 395 | 437 | 1.263 | 14.520 | ||||||
7 | 13 | 479 | 241 | 1.136 | 14.787 | ||||||
11 | 13 | 430 | 416 | 1.302 | 14.787 |
VI-B Checking Random Benchmarks
To further test the scalability of our algorithms, we generated some benchmarks with Clifford+T gates (H, S, T, CNOT gates) and 2-control Toffoli gates. The numbers of data qubits of the benchmarks range from . The number of measured qubits was fixed to , and the gate number was set to about . For each , 20 groups of circuits were generated, and each group includes two conditions: ancilla qubits existing or non-existing. We used the latter condition to test Algorithm 3, and both conditions to test Algorithm 2.
The structure of the benchmarks is shown in Fig. 5. Let the partially equivalent circuit pair be and , both with data qubits and measured qubits. The circuits are divided into five parts: H (H gates), T (totally equivalent), P (partially equivalent), A (arbitrary) and C (CNOT gates). If and are in the condition without ancilla qubits, only the first four parts are contained. Otherwise, they both contain all five parts.
In part H, an H gate is firstly applied to each data qubit to impose superposition. In part T, we generate a random sub-circuit with qubits and gates to apply on both circuits, but all the Toffoli gates in are decomposed in the way proposed in [44]. In part P, we divide the data qubits into several groups, where each group may contain one or two adjacent qubits. For each group, we apply and on and , respectively, where and are pre-generated subcircuits satisfying when all qubits are set to data qubits and measured qubits. and are exhaustively searched with up to five gates in total. In part A, different random sub-circuits with qubits and gates are applied on and . These gates trivially do not affect the measurement results of the measured qubits. In part C, we use the ancilla qubits as the control bits to control the upper qubits. As ancilla qubits are initially set to 0, these CNOT gates do not affect the circuit.
Although the circuit generation is simple, there are no known circuit simplification methods exploiting partial equivalence. The generated circuits are used to test our algorithms. Furthermore, to validate the correctness of the benchmarks, we use the same generating method to generate some test cases with . For each test case, we use Qiskit [27] to randomly set an initial state and get the final state vector numerically. We calculate for all possible outputs and make sure that and have the same probability distribution under this random initial state.
Without ancilla qubits | With ancilla qubits | |||||||||||||
#Gates in | #Gates in | Algorithm 3 | Algorithm 2 | #Gates in | #Gates in | Algorithm 2 | ||||||||
time(s) |
|
#TO | time(s) |
|
#TO | time(s) |
|
#TO | ||||||
5 | 2 | 26.05 | 78.95 | 0.017 | 12.942 | 0 | 0.064 | 12.954 | 0 | 27.05 | 79.95 | 0.067 | 12.954 | 0 |
10 | 5 | 51.05 | 157.00 | 0.050 | 12.942 | 0 | 1.880 | 25.077 | 0 | 52.65 | 158.60 | 1.951 | 24.766 | 0 |
15 | 7 | 76.00 | 240.70 | 0.135 | 13.855 | 0 | 72.416 | 165.957 | 1 | 77.95 | 243.05 | 72.576 | 168.987 | 1 |
20 | 10 | 102.65 | 308.75 | 0.364 | 14.180 | 0 | 117.528 | 170.217 | 14 | 105.85 | 312.00 | 129.006 | 167.451 | 13 |
25 | 12 | 128.90 | 372.70 | 0.723 | 14.577 | 0 | - | - | - | 132.55 | 376.15 | - | - | - |
30 | 15 | 155.45 | 439.05 | 1.276 | 15.798 | 0 | - | - | - | 160.00 | 443.40 | - | - | - |
35 | 17 | 180.65 | 543.15 | 2.491 | 17.633 | 0 | - | - | - | 185.50 | 548.25 | - | - | - |
40 | 20 | 204.80 | 587.75 | 3.554 | 18.930 | 0 | - | - | - | 210.85 | 594.00 | - | - | - |
50 | 25 | 257.00 | 710.25 | 8.827 | 35.281 | 0 | - | - | - | 264.65 | 717.75 | - | - | - |
60 | 30 | 309.65 | 862.90 | 18.673 | 45.444 | 0 | - | - | - | 318.25 | 872.50 | - | - | - |
70 | 35 | 361.45 | 1037.45 | 55.950 | 78.525 | 0 | - | - | - | 372.10 | 1048.00 | - | - | - |
80 | 40 | 414.55 | 1157.00 | 105.611 | 122.198 | 3 | - | - | - | 426.00 | 1169.25 | - | - | - |
90 | 45 | 461.65 | 1328.75 | 229.473 | 144.761 | 6 | - | - | - | 475.80 | 1342.00 | - | - | - |
100 | 50 | 517.35 | 1464.15 | 297.401 | 160.311 | 11 | - | - | - | 532.70 | 1480.05 | - | - | - |
Without ancilla qubits (Algorithm 3) | |||||||
#Gates in | #Gates in | time (s) | memory (MB) | ||||
hwb4_52 | hwb4_49 | 4 | 4 | 11 | 17 | 0.0128 | 12.6730 |
hwb6_58 | hwb6_56 | 6 | 6 | 42 | 126 | 0.0214 | 12.9434 |
graycode6_47 | graycode6_48 | 6 | 6 | 5 | 5 | 0.0132 | 12.9434 |
ham3_103 | ham3_102 | 3 | 3 | 4 | 5 | 0.0128 | 12.6730 |
urf1_150 | urf1_149 | 9 | 9 | 1517 | 11554 | 5.5048 | 15.4092 |
urf2_153 | urf2_152 | 8 | 8 | 638 | 5030 | 1.1813 | 13.9059 |
urf3_156 | urf3_155 | 10 | 10 | 2732 | 26468 | 25.6478 | 17.7562 |
urf5_159 | urf5_158 | 9 | 9 | 499 | 10276 | 3.5319 | 15.4010 |
urf6_281 | urf6_160 | 15 | 15 | 5102 | 10740 | 188.8090 | 112.1649 |
alu-v1_28 | alu-v1_29 | 5 | 1 | 8 | 8 | 0.0101 | 12.9393 |
alu-v2_33 | alu-v2_30 | 5 | 1 | 7 | 18 | 0.0130 | 13.0048 |
alu-v3_34 | alu-v3_35 | 5 | 1 | 8 | 8 | 0.0110 | 12.9393 |
alu-v4_36 | alu-v4_37 | 5 | 1 | 8 | 8 | 0.0127 | 12.9393 |
With ancilla qubits (Algorithm 2) | |||||||
#Gates in | #Gates in | time (s) | memory (MB) | ||||
hwb5_53 | hwb5_300 | 5 | 5 | 55 | 101 | 3.8765 | 31.1869 |
alu-v0_26 | alu-bdd_288 | 5 | 1 | 7 | 10 | 0.0146 | 12.9434 |
ham7_104 | ham7_299 | 7 | 7 | 23 | 76 | 0.7321 | 16.2570 |
ham15_107 | ham15_298 | 15 | 15 | 132 | 184 | 89.9754 | 203.5876 |
nestedif2_16_396 | nestedif2_16_468 | 34 | 32 | 256 | 266 | 3.6910 | 37.0237 |
The experimental results are shown in Table IV. The runtime and memory usage shown are averaged over the 20 test cases excluding those timed out. As seen, Algorithm 3 can easily scale up to tens of qubits. However, for , Algorithm 2 can hardly finish the computation within the time limit. It may be because, for Algorithm 3, keeps representing a unitary matrix of a quantum circuit almost during the whole process, which may be more “regular” for BDDs to represent. Moreover, due to the structure of , some gates may be canceled out and the BDDs are more likely to be maintained as an identity matrix, as mentioned in [8]. In contrast, the entries of the final matrix in Algorithm 2 contain the values of , which can be arbitrary real numbers. Besides, we fix to in our benchmarks, and the second step in Algorithm 2 may further increase the number of qubits. Thus, the runtime and memory usage of Algorithm 2 grow more rapidly than those of Algorithm 3.
VI-C Checking Reversible Circuits
As mentioned, functionally equivalent reversible circuits without don’t-care conditions must be partially equivalent. For those with ancilla inputs, Algorithm 2 is needed. On the other hand, Algorithm 3 is sufficient if no ancilla inputs exist. We used some test cases from RevLib [45] and used Algorithms 2 and 3 to test their partial equivalence to justify this point. The experimental results are shown in Table IV. It is justified that all functionally equivalent reversible circuits are indeed partially equivalent. The runtime and memory usage mainly grow proportional to the gate-count increase.
VI-D Checking Grover’s Algorithm
If reversible circuits are used as part of a quantum circuit, the entire quantum circuit may not be a reversible circuit anymore, and its verification becomes more complex. We took Grover’s algorithm as an example for case study. In the experiment, we created a reversible circuit as the oracle function in Grover’s algorithm. We also used the way proposed in [38] to implement the same function with one ancilla qubit. Then, Algorithm 2 was applied to check the equivalence of the two circuit. The data qubit number and measured qubit number range from .
The experimental results are shown in Table V. The runtime and memory usage grow as increases. It is reasonable because the circuit size is larger. We note that quantum circuits of Grover’s algorithm with the same oracle function but implemented by different reversible circuits are q-equivalent. In this experiment, we show that they are also partially equivalent. Apart from equivalent test cases, we also try to remove one gate from the second circuit to make them not partially equivalent. The runtime and memory usage for non-equivalent test cases are still close to equivalent test cases.
|
|
time (s) |
|
||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
6 | 6 | 35 | 37 | 0.257 | 13.201 | ||||||
10 | 10 | 59 | 61 | 1.537 | 38.687 | ||||||
14 | 14 | 83 | 85 | 9.613 | 153.371 | ||||||
18 | 18 | 107 | 109 | 22.831 | 179.745 | ||||||
22 | 22 | 131 | 133 | 49.149 | 192.492 | ||||||
26 | 26 | 155 | 157 | 135.116 | 232.116 |
#Gates in | #Gates in | Algorithm 3 | SliQEC | ||||||
time (s) | memory (MB) | #TO | time (s) | memory (MB) | #TO | ||||
10 | 10 | 40.00 | 118.40 | 0.038 | 12.955 | 0 | 0.028 | 13.000 | 0 |
20 | 20 | 80.00 | 237.50 | 0.182 | 14.245 | 0 | 0.194 | 14.237 | 0 |
30 | 30 | 120.00 | 377.60 | 0.685 | 15.699 | 0 | 0.640 | 15.285 | 0 |
40 | 40 | 160.00 | 496.00 | 1.802 | 19.232 | 0 | 1.749 | 17.815 | 0 |
50 | 50 | 200.00 | 649.40 | 3.612 | 28.114 | 0 | 4.722 | 28.233 | 0 |
60 | 60 | 240.00 | 751.00 | 7.246 | 38.732 | 0 | 9.889 | 42.336 | 0 |
70 | 70 | 280.00 | 887.60 | 12.165 | 45.731 | 0 | 10.086 | 38.610 | 0 |
80 | 80 | 320.00 | 993.40 | 20.001 | 58.224 | 0 | 22.079 | 56.422 | 0 |
90 | 90 | 360.00 | 1071.20 | 24.703 | 69.052 | 0 | 25.826 | 68.746 | 0 |
100 | 100 | 400.00 | 1230.20 | 48.089 | 85.605 | 0 | 58.483 | 79.486 | 0 |
VI-E Checking Total Equivalent Circuits
Because totally equivalent circuits must be partially equivalent, under these circumstances we use totally equivalent circuits as the benchmarks to test Algorithm 3 and compare it against SliQEC [8]. Because Algorithm 3 is extended from SliQEC, we expect that they would perform similarly. We generated some benchmarks with qubit number , and set all qubits to be measured qubits for partial equivalence checking. The generating method is similar to how we generate partially equivalent pairs, except that only part H and part T are included to make them totally equivalent. The results shown in Table VI confirm the expectation that Algorithm 3 and SliQEC behave similarly in both runtime and memory usage on these instances.
VII Conclusions
In this work, we defined partial equivalence, which is concerned with observational equivalence with respect to partial measurement and a set of initial input states. We obtained the necessary and sufficient conditions of partial equivalence, and exploited them to develop partial equivalence checking algorithms. Experimental results demonstrate the usefulness and strengths of our methods. For future work, it may be interesting to explore partial equivalence in applications such as quantum circuit synthesis and quantum program compilation.
Acknowledgments
This work was supported in part by the Ministry of Science and Technology of Taiwan under grants MOST 110-2224-E-002-011 and MOST 111-2119-M-002-012, and MediaTek Research. TFC was supported by the TSMC Scholarship.
References
- [1] A. Kuehlmann and F. Krohm, “Equivalence checking using cuts and heaps,” in Proc. Design Automation Conference, 1997, pp. 263–268.
- [2] A. Mishchenko, S. Chatterjee, R. Brayton, and N. Een, “Improvements to combinational equivalence checking,” in Proc. Int. Conf. on Computer-Aided Design, 2006, pp. 836–843.
- [3] S.-Y. Huang and K.-T. T. Cheng, Formal Equivalence Checking and Design Debugging. Springer, 2012.
- [4] C. Van Eijk, “Sequential equivalence checking based on structural similarities,” IEEE Trans. on Computer-Aided Design of Integrated Circuits and Systems, vol. 19, no. 7, pp. 814–819, 2000.
- [5] K. L. McMillan, “Interpolation and SAT-based model checking,” in Proc. Int. Conf. on Computer Aided Verification, 2003, pp. 1–13.
- [6] A. R. Bradley, “SAT-based model checking without unrolling,” in Proc. Int. Conf. on Verification, Model Checking, and Abstract Interpretation, 2011, pp. 70–87.
- [7] N. Een, A. Mishchenko, and R. Brayton, “Efficient implementation of property directed reachability,” in Proc. Int. Conf. on Formal Methods in Computer-Aided Design, 2011, pp. 125–134.
- [8] C.-Y. Wei, Y.-H. Tsai, C.-S. Jhang, and J.-H. R. Jiang, “Accurate BDD-based unitary operator manipulation for scalable and robust quantum circuit verification,” in Proc. Design Automation Conference, 2022.
- [9] P. Niemann, R. Wille, and R. Drechsler, “Equivalence checking in multi-level quantum systems,” in Proc. Int’l Conf. of Reversible Comput., 2014, pp. 201–215.
- [10] L. Burgholzer and R. Wille, “Advanced equivalence checking for quantum circuits,” IEEE Trans. on Comput.-Aided Design Integr. Circuits Syst, vol. 40, no. 9, pp. 1810–1824, 2021.
- [11] X. Hong, M. Ying, X. Z. Y. Feng, and S. Li, “Approximate equivalence checking of noisy quantum circuits,” in Proc. Design Automation Conf., 2021, pp. 637–642.
- [12] S. Yamashita and I. L. Markov, “Fast equivalence-checking for quantum circuits,” in Proc. Int. Symp. on Nanoscale Architectures, 2010, pp. 23–28.
- [13] L. Burgholzer and R. Wille, “Improved DD-based equivalence checking of quantum circuits,” in Proc. Asia and South Pacific Design Automation Conf., 2020, pp. 127–132.
- [14] ——, “The power of simulation for equivalence checking in quantum computing,” in Proc. Design Automation Conf., 2020, pp. 1–6.
- [15] ——, “Handling non-unitaries in quantum circuit equivalence checking,” in Proc. Design Automation Conference, 2022.
- [16] E. Ardeshir-Larijani, S. J. Gay, and R. Nagarajan, “Verification of concurrent quantum protocols by equivalence checking,” in Proc. Int. Conf. on Tools and Algorithms for the Construction and Analysis of Systems, 2014, pp. 500–514.
- [17] M. Amy, “Towards large-scale functional verification of universal quantum circuits,” in Electronic Proc. in Theoretical Computer Science, vol. 287, 2019, pp. 1–21.
- [18] G. F. Viamontes, I. L. Markov, and J. P. Hayes, “Checking equivalence of quantum circuits and states,” in Proc. Int. Conf. on Computer-Aided Design, 2007, pp. 69–74.
- [19] S. A. Wang, C. Y. Lu, I. M. Tsai, and S. Y. Kuo, “An XQDD-based verification method for quantum circuits,” IEICE Trans. on Fundamentals of Electron., Commun. and Computer Sci., vol. E91-A, no. 2, pp. 584–594, 2008.
- [20] E. Knill, “Conventions for quantum pseudocode,” Los Alamos National Lab, Tech. Rep., 1996, [Online]. Available: https://www.osti.gov/biblio/366453.
- [21] B. Ömer, “A procedural formalism for quantum computing,” Master’s thesis, Dep. Theoretical Phys., Technical Univ. of Vienna, 1998.
- [22] A. van Tonder, “A lambda calculus for quantum computation,” SIAM Journal on Computing, vol. 33, pp. 1109–1135, 2004.
- [23] P. Selinger, “Towards a quantum programming language,” Mathematical Structures in Computer Science, vol. 14, no. 4, pp. 527–586, 2004.
- [24] S. Bettelli, L. Serafini, , and T. Calarco, “Toward an architecture for quantum programming,” Eur. Phys. J. D, vol. 25, pp. 181–200, 2003.
- [25] A. W. Cross, L. S. Bishop, J. A. Smolin, and J. M. Gambetta, “Open quantum assembly language,” 2017, [Online]. Available: https://arxiv.org/abs/1707.03429.
- [26] A. J. Abhari et al., “Scaffold: Quantum programming language,” Dept. of Computer Science, Princeton Univ., Tech. Rep. TR934-12, 2012.
- [27] H. Abraham et al., “Qiskit: An open-source framework for quantum computing,” 2019, doi: 10.5281/zenodo.2562111.
- [28] B. Bichsel, M. Baader, T. Gehr, and M. Vechev, “Silq: A high-level quantum language with safe uncomputation and intuitive semantics,” in Proc. Int. Conf. on Programming Language Design and Implementation, London, UK, 2020, pp. 286–300.
- [29] K. M. Svore et al., “Q#: Enabling scalable quantum computing and development with a high-level dsl,” in Proc. Real World Domain Specific Languages Workshop, 2018, pp. 1–10.
- [30] A. S. Green, P. L. Lumsdaine, N. J. Ross, P. Selinger, and B. Valiron, “Quipper: a scalable quantum programming language,” in Proc. Int. Conf. on Programming Language Design and Implementation, 2013, pp. 333–342.
- [31] S. Liu et al., “: A quantum programming environment,” in Proc. Symp. on Real-Time and Hybrid Systems, 2018, pp. 133–164.
- [32] X. Hong, Y. Feng, S. Li, and M. Ying, “Equivalence checking of dynamic quantum circuits,” 2021, [Online]. Available: arXiv:2106.01658v1.
- [33] Q. S. Wang, J. Y. Liu, and M. S. Ying, “Equivalence checking of quantum finite-state machines,” J. Comput. Syst. Sci., vol. 116, pp. 1–21, 2021.
- [34] Q. Wang, R. Li, and M. Ying, “Equivalence checking of sequential quantum circuits,” IEEE Trans. on Comput.-Aided Design of Integr. Circuits and Syst., 2021.
- [35] R. E. Bryant, “Graph-based algorithms for Boolean function manipulation,” IEEE Trans. on Computers, vol. 35, no. 8, pp. 677–691, 1986.
- [36] R. Wille, D. Große, D. M. Miller, and R. Drechsler, “Equivalence checking of reversible circuits,” in Proc. Int. Symp. on Multiple-Valued Logic, 2009, pp. 324–330.
- [37] L. G. Amaru, “Improvements to the equivalence checking of reversible circuits,” in New Data Structures and Algorithms for Logic Synthesis and Verification. Springer, 2017, ch. 6.
- [38] D. M. Miller, R. Wille, and R. Drechsler, “Reducing reversible circuit cost by adding lines,” in Proc. Int. Symp. on Multi-Valued Logic, 2010, pp. 217–222.
- [39] H. Lee, K. C. Jung, D. Han, and P. Kim, “An algorithm for reversible logic circuit synthesis based on tensor decomposition,” 2021, [Online]. Available: arxiv.org/abs/2107.04298.
- [40] Y.-H. Tsai, J.-H. R. Jiang, and C.-S. Jhang, “Bit-slicing the Hilbert space: Scaling up accurate quantum circuit simulation,” in Proc. Design Automation Conference, 2021, pp. 439–444.
- [41] Z. Alwin, N. Philipp, D. Rolf, and W. Robert, “Accuracy and compactness in decision diagrams for quantum computation,” in Proc. Design, Automation Test in Europe Conference and Exhibition, 2019, pp. 280–283.
- [42] P. W. Shor, “Algorithms for quantum computation: discrete logarithms and factoring,” in Proc. IEEE Symposium on Foundations of Computer Science, 1994, pp. 124–134.
- [43] F. Somenzi, “CUDD: CU decision diagram package (release 2.4.2),” 2012.
- [44] D. Maslov, “Advantages of using relative-phase Toffoli gates with an application to multiple control Toffoli optimization,” Phys. Rev. A, vol. 93, no. 022311, 2016.
- [45] R. Wille, D. Große, L. Teuber, G. W. Dueck, and R. Drechsler, “Revlib: An online resource for reversible functions and reversible circuits,” in Proc. Int. Symp. on Multi-Valued Logic, 2008, pp. 220–225.