Analysis of Quantum Circuits Via Abstract Stabilizer Simulation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Abstraqt: Analysis of Quantum Circuits via Abstract

Stabilizer Simulation
Benjamin Bichsel, Maximilian Baader, Anouk Paradis, and Martin Vechev

ETH Zurich, Switzerland

Stabilizer simulation can efficiently simulate an important class of quantum cir-


cuits consisting exclusively of Clifford gates. However, all existing extensions of this
simulation to arbitrary quantum circuits including non-Clifford gates suffer from an
exponential runtime.
arXiv:2304.00921v1 [quant-ph] 3 Apr 2023

In this work, we address this challenge by presenting a novel approach for efficient
stabilizer simulation on arbitrary quantum circuits, at the cost of lost precision. Our
key idea is to compress an exponential sum representation of the quantum state into
a single abstract summand covering (at least) all occurring summands. This allows
us to introduce an abstract stabilizer simulator that efficiently manipulates abstract
summands by over-abstracting the effect of circuit operations including Clifford gates,
non-Clifford gates, and (internal) measurements.
We implemented our abstract simulator in a tool called Abstraqt and experi-
mentally demonstrate that Abstraqt can establish circuit properties intractable for
existing techniques.

1 Introduction
Stabilizer simulation [1] is a promising technique for efficient classical simulation of quantum cir-
cuits consisting exclusively of Clifford gates. Unfortunately, generalizing stabilizer simulation to
arbitrary circuits including non-Clifford gates requires exponential time [2, 3, 4, 5, 6, 7]. Specifi-
cally, the first such generalization by Aaronson and Gottesman [2, §VII-C] tracks the quantum state
ρ at any point in the quantum circuit as a sum whose number of summands m grows exponentially
with the number of non-Clifford gates:
m n
I+(−1)bij Qj
X Y
ρ= ci P i 2 . (1)
i=1 j=1

Here, while ci , Pi , bij , and Qj can be represented efficiently (see §2), the overall representation is
inefficient due to exponentially large m.

Abstraction. The key idea of this work is to avoid tracking the exact state ρ of a quantum system
and instead only track key aspects of ρ, by over-approximating the set of possible summands.
To this end, we rely on the established framework of abstract interpretation [8, 9], which is
traditionally used to analyze classical programs [10, 11] or neural networks [12] by describing sets
of possible states without explicitly enumerating all of them. Here, we use abstract interpretation
to describe sets of possible summands.

Merging Summands. This allows us to curb the exponential blow-up of stabilizer simulation
by merging multiple summands in Eq. (1) into a single summand which over-approximates all
covered summands, at the cost of lost precision. The key technical challenge addressed by our
work is designing a suitable abstract domain to describe sets of summands, accompanied by the
corresponding abstract transformers to over-approximate the actions performed by the original
exponential stabilizer simulation on individual summands.

1
As a result, our approach is both efficient and exact on Clifford circuits, as these circuits
never require merging summands. On non-Clifford circuits, merging summands trades precision
for efficiency. Moreover, our approach naturally allows us to merge the possible outcomes of a
measurement into a single abstract state, preventing an exponential path explosion when simulating
multiple internal measurements.

Main Contributions. Our main contributions are:

• An abstract domain (§4) to over-approximate a quantum state represented by Eq. (1).


• Abstract transformers (§5) to simulate quantum circuits, including gate applications and
measurements.
• An efficient implementation1 of our approach in a tool called Abstraqt (§6), together with
an evaluation showing that Abstraqt can establish circuit properties that are intractable
for existing tools (§7).

Outlook. This work trades precision for efficiency by over-abstracting the very first stabilizer
simulation generalized to non-Clifford gates by Aaronson and Gottesman [2, §VII-C], see Eq. (1).
As discussed in §7.4, we believe that our encouraging results pave the way to introduce analogous
abstraction to various follow-up works which improve upon this simulation [4, 5, 6, 7]. As these
more recent works scale better than [2, §VII-C], we expect that a successful application of abstract
interpretation to them will yield even more favorable trade-offs between precision and efficiency.

2 Background
We first introduce the necessary mathematical concepts.

Basic Notation. We use Zn := Z/(nZ), define B := Z2 , and write 2S for the power set of the
n
set S. We represent an n-qubit quantum state either using vectors ψ ∈ C2 or density matrices
2n ×2n
ρ ∈ C . We denote the embedding of a k-qubit gate U ∈ U(2 ) as an n-qubit gate by
k

U(i) := I2i ⊗ U ⊗ I2n−i−k , where Il denotes the l × l identity matrix.

Stabilizer Simulation. The key idea of stabilizer simulation [1, 2] is representing quantum
states ρ = ψψ † implicitly, by stabilizers Q which stabilize the state ψ, that is Qψ = ψ.QAs shown
n I+Q
in [2], appropriately selecting n stabilizers Qj then specifies a unique n-qubit state ρ = j=1 2 j .
In stabilizer simulation, all Qj are Pauli elements from Pn of the form iv · P (0) ⊗ · · · ⊗ P (n−1) ,
where P (j) ∈ {X, Y, Z, I2 } and v ∈ Z4 . This directly implies that all stabilizers for some state
ψ commute, that is Qi Qj = Qj Qi , as elements from the Pauli group Pn either commute or anti-
commute. These elements can be represented efficiently in memory by storing v and P (0) , . . . , P (n−1) .
In App. B, we list states stabilized by Pauli matrices (Tab. 6) and the results of multiplying Pauli
matrices (Tab. 7). Further, for this work we use the functions bare b : Pn → Pn and prefactor
f : Pn → Z4 which extract the Pauli matrices without the prefactor and the prefactor, respectively:

f(iv P (0) ⊗ · · · ⊗ P (n−1) ) = v, (2)


v (0) (n−1) (0) (n−1)
b(i P ⊗···⊗P )=P ⊗···⊗P . (3)

Applying gate U to state ρ can be reduced to conjugating the stabilizers Qj with U :


n n
I+U Qj U †
Q  [13, Sec. 10.5]
I+Qj
U ρU † = U U†
Q
2 = 2 . (4)
j=1 j=1

While Eq. (4) holds for any gate U , stabilizer simulation can only exploit it if U Qj U † ∈ Pn .
Clifford gates such as S, H, CN OT , I, X, Y, and Z satisfy this for any Qj ∈ Pn .

1 Our implementation is available at https://github.com/eth-sri/abstraqt.

2
Table 1: Transformers for the interval abstraction.

Function Abstract Transformer Efficient Closed form


+ [l1 , u1 ] +] [l2 , u2 ] = [l0 , u0 ] l0 = l1 + l2 and u0 = u1 + u2
· [l1 , u1 ] ·] [l2 , u2 ] = [l0 , u0 ] l0 = min(l1 l2 , l1 u2 , u1 l2 , u1 u2 ), analogously for u0
exp exp] ([l, u]) = [l0 , u0 ] l0 = exp(l) and u0 = exp(u)
cos cos] ([l, u]) = [l0 , u0 ] exists, several case distinctions necessary
∪ [l1 , u1 ] t [l2 , u2 ] = [l0 , u0 ] l0 = min(l1 , l2 ) and u0 = max(u1 , u2 )

To also support the application of non-Clifford gates such as T gates, we follow [2, Sec. VII.C]
and represent ρ more generally as
m n
P Q I+(−1)bij Qj
ρ= ci Pi 2 ,
i=1 j=1

for ci ∈ C, Pi ∈ Pn , bij ∈ B, and Qj ∈ Pn . Here, applying U to ρ amounts to replacing Pi by


U Pi U † and Qj by U Qj U † , which we can exploit P if both U Pi U and U Qj U lie in Pn .
† †

Otherwise, we decompose U to the sum p dp Rp , where dp ∈ C and Rp ∈ b(Pn ) are bare


2

Pauli elements, which have a prefactor of i0 = 1. Then,


n † [2] P n
I+(−1)bij Qj I+(−1)bijq Qj
P  P  P
U ρU † =
Q Q
dp Rp ci Pi 2 dq R q = cpiq P piq 2 , (5)
p i j=1 q piq j=1

for cpiq = dp ci d∗q ∈ C, Ppiq = Rp Pi Rq ∈ Pn , and bijq = bij + Qj  Rq ∈ B. Here, d∗q denotes the
complex conjugate of dq , + denotes addition modulo 2, and Qj  Rq is the commutator defined as 0
if Qj and Rq commute and 1 otherwise. Note that ·  · : Pn × Pn → B has the highest precedence.
Overall, the decomposition of a k-qubit non-Clifford gate results in at most 4k summands,
thus blowing up the number of summands in our representation by at most 4k · 4k = 16k . In
practice, the blow-up is typically smaller, e.g., decomposing a T gate only requires 2 summands,
while decomposing a CCN OT gate requires 8 summands.

Measurement. Measuring in bare Pauli basis P ∈ b(Pn ) yields one of two possible quantum
states. They can be computed by applying the two projections P+ := I+P 2 and P− = 2 , resulting
I−P

in states ρ+ = P+ ρP+ and ρ− = P− ρP− , respectively. For example, collapsing the i qubit to |0i
th

or |1i corresponds to measuring in Pauli basis Z(i) . The probability of outcome ρ+ is tr (ρ+ ), and
analogously for ρ− . We discuss in §5 how measurements are performed in [2, Sec. VII.C].

Abstract Interpretation. Abstract interpretation [8] is a framework for formalizing approxi-


mate but sound calculation. An abstraction consists of ordered sets (2X , ⊆) and (X , ≤), where X
and X are called concrete set and abstract set respectively together with a concretization function
γ : X → 2X which indicates which concrete elements x = γ(x) ⊆ X are represented by the abstract
element x. Additionally, ⊥ ∈ X refers to ∅ = γ(⊥) ⊆ X and > ∈ X refers to X = γ(>).
An abstract transformer f ] : X → X of a function f : X → X satisfies γ ◦ f ] (x) ⊇ f ◦ γ(x) for
all x ∈ X , where f was lifted to operate on subsets of X . This ensures that f ] (over-)approximates
f , a property referred to as soundness of f ] . Abstract transformers can analogously be defined for
functions f : X n → X . Further, we introduce join t : X ×X → X , satisfying γ(x)∪γ(y) ⊆ γ(xty).
Throughout this work, we distinguish abstract objects x ∈ X and concrete objects x ∈ X by
stylizing them in bold or non-bold respectively.
As an example, a common abstraction is the interval abstraction with X = R. The abstract
set is the set of intervals X = {(l, u) | l, u ∈ R ∪ {±∞}}, where x = (l, u) is to be understood as
a tuple and not as an open interval. The concretization function γ : X → X maps these tuples
to sets: γ(x) = [l, u] = {y ∈ R | l ≤ y ≤ u}. Further, > = (−∞, ∞) and ⊥ = (l, u) for l > u.
Common abstract transformers for the interval abstraction are shown in Tab. 1.
The transformers in Tab. 1 are precise, meaning that for f : R → R, we have that f ] ((l, u)) =
(minl≤v≤u f (v), maxl≤v≤u f (v)) and analogously for f : Rn → R. An abstract transformer for

2 This decomposition always exists and is unique, as bare Pauli elements span (more than) U (2n ).

3
|0i H T • |−i
|0i H •

I Z(0) I Z(1) I X(0) I X(1) I X(0) I X(1) I X(0) X(1) I X(0) 0 with prob.
e[0,0]+i[0,0] {I} 2 2 e[0,0]+i[0,0] {I} 2 2 4 ? c{I, Z(0) } 2 2 4 ? c{I, Z(0) } 2 2 p ∈ [0, 0]

I X(0) I X(1) I X(0) I X(1) I X(0) I X(1) I X(0) I X(1)


c1 {I} 2 2 + c2 {Z(0) } 2 2 + c3 {Z(0) } 2 2 + c4 {I} 2 2

Figure 1: Overview of Abstraqt, where we define c and c1 –c4 in §3.

a composition of functions f ◦ g is the composition of the abstract transformer. Although this


is sound, it is not necessarily precise: let g : R → R2 with g(x) = ( xx ) and f : R2 → R with
f (x, y) = x · y, then f ◦ g(x) = x2 , but f ] ◦ g ] ((−2, 2)) = (−4, 4) whereas a precise transformer
would map (−2, 2) to (0, 4).

Notational Convention. In slight abuse of notation, throughout this work we may write
the concretization of abstract elements instead of the abstract element itself. For example, for
(0, 1) ∈ R , we write [0, 1] := {v ∈ R | 0 ≤ v ≤ 1} to indicate that it represents an interval.
Where clear from context, we omit ] and write f for f ] . For example, we write [l1 , u1 ] + [l2 , u2 ] for
[l1 , u1 ] +] [l2 , u2 ].

3 Overview
In this section, we showcase Abstraqt by applying it to the example circuit in Fig. 1. Overall,
Abstraqt proceeds analogously to [2, §VII-C], but operates on abstract summands representing
many concrete summands.

Example Circuit. We first discuss the circuit in Fig. 1. Both qubits are initialized to |0i.
The circuit then applies a succession of gates. The abstract representation of the state after the
application of each gate is shown in the gray boxes below the circuit. On the final state, the circuit
I−X
collapses the upper qubit to |−i by applying the projection M− = 2 (0) . Precise circuit simulation
shows that the probability of obtaining |−i is 0, in this case. In the following, we demonstrate how
Abstraqt computes an over-approximation of this probability.

Initial State. The density matrix for the initial state |0i ⊗ |0i can be represented as (see [2]):
I+(−1)0 Z(0) I+(−1)0 Z(1)
ρA = 1I 2 2 .

To translate this to an abstract density matrix, we simply replace some elements by abstract
representations. This gives the following initial abstract state:
I+(−1){0} Z(0) I+(−1){0} Z(1)
ρA = e[0,0]+[0,0]i {I} 2 2 . (6)

Here we abstract booleans as sets, for instance {0}. For conciseness, in Fig. 1 we write x y,
x y, and x y for x + (−1){0} y, x + (−1){1} y, and x + (−1){0,1} y. Further, we represent abstract
complex numbers in polar form with logarithmic length, using real intervals: 1 is represented as
π
e[0,0]+[0,0]i , while the set of complex numbers {1, i} would be over-approximated as e[0,0]+[0, 2 ]i .
Finally, we abstract Pauli elements as sets, such as {I} in Fig. 1 and Eq. (6). In §4, we will clarify
how we store these sets efficiently, for example representing {I} as i{0} · {I} ⊗{I} and {i · I, i · Z (0) }
as i{1} · {I, Z} ⊗{I}.
We now explain how each operation in the circuit modifies this abstract state.

4
Clifford Gate Application. First, the circuit applies one Hadamard gate H to each qubit.
This corresponds to the unitary operator H(0) H(1) , yielding updated abstract density matrix ρB =
(H(0) H(1) )ρA (H(0) H(1) )† . Just as for concrete density matrices (see §2), this amounts to replacing
{I} by (H(0) H(1) ){I}(H(0) H(1) )† = {I},
Z(0) by (H(0) H(1) )Z(0) (H(0) H(1) )† = X(0) , and
Z(1) by (H(0) H(1) )Z(1) (H(0) H(1) )† = X(1) .
I+(−1){0} X(0) I+(−1){0} X(1)
We hence get ρB = e[0,0]+[0,0]i {I} 2 2 .

Non Clifford Gate Application. Next, the circuit applies gate T on the upper qubit. To this
end, we again follow the simulation described in §2. We first decompose T into Pauli elements:
T(0) = d1 I + d2 Z(0) , where d1 ≈ e−0.1+0.4i and d2 ≈ e−1.0−1.2i . Replacing T with its decomposition,
we can then write ρT = T ρB T † , using Eq. (5), as:
 I+(−1){0} X(0) I+(−1){0} X(1)
 †
ρT = d1 I + d2 Z(0) e[0,0]+[0,0]i {I} 2 2 d1 I + d2 Z(0) .

Analogously to §2, we can rewrite this to:


I+(−1){0} X(0) I+(−1){0} X(1)
c1 {I} 2 2
I+(−1){1} X(0) I+(−1){0} X(1)
+c2 {Z(0) } 2 2
I+(−1){0} X(0) I+(−1){0} X(1)
+c3 {Z(0) } 2 2
I+(−1){1} X(0) I+(−1){0} X(1)
+c4 {I} 2 2 ,

where

c1 = d1 e[0,0]+[0,0]i d∗1 ≈ e[−0.2,−0.2]+[0,0]i ,


c2 = d1 e[0,0]+[0,0]i d∗2 ≈ e[−1.1,−1.1]+[1.6,1.6]i ,
c3 = d2 e[0,0]+[0,0]i d∗1 ≈ e[−1.1,−1.1]+[−1.6,−1.6]i ,
c4 = d2 e[0,0]+[0,0]i d∗2 ≈ e[−2.0,−2.0]+[0,0]i .

Merging Summands. Unfortunately, simply applying T gates as shown above may thus increase
the number of summands in the abstract density matrix by a factor of 4. To counteract this,
our key idea is to merge summands, by allowing a single abstract summand to represent multiple
concrete ones, resulting in reduced computation overhead at the cost of lost precision. Our abstract
representation allows for a straightforward merge: we take the union of sets and join intervals.
Specifically, for complex numbers, we join the intervals in their representation, obtaining:

c := c1 t c2 t c3 t c4 = e[−2.0,−0.2]+[−1.6,1.6]i .

Finally, we introduce the symbol ? to denote how many concrete summands an abstract summand
represents. Altogether, merging the summands in ρT yields:
I+(−1){0,1} X(0) I+(−1){0} X(1)
ρC = 4 ? e[−2.0,−0.2]+[−1.6,1.6]i {I, Z(0) } 2 2 .

Note that for an abstract element x, r ? x is not equivalent to r · x. For example, 2 ? {0, 1} =
{0, 1} + {0, 1} = {0, 1, 2}, while 2 · {0, 1} = {0, 2}.

Measurement. After the T gate, the circuit applies two additional CN OT gates, resulting in
the updated density matrix:
I+(−1){0,1} X(0) X(1) I+(−1){0} X(0)
ρD = 4 ? e[−2.0,−0.2]+[−1.6,1.6]i {I, Z(0) } 2 2 .

5
I−X
Finally, the circuit applies the projection M− = 2 (0) . To update the density matrix accordingly,
we closely follow [2], which showed that measurement can be reduced to simple state updates
through a case distinction on M− and the state ρ. If (i) the measurement Pauli (here −X(0) ) com-
mutes with the product Paulis (here (−1){0,1} X(0) X(1) and (−1){0} X(1) ) and (ii) the measurement
Pauli cannot be written as a product of the product Paulis, the density matrix after measurement
is 0. We will explain in §5.2 how our abstract domain allows both of these checks to be performed
efficiently.
Here, both conditions are satisfied, and we hence get the final state ρM 1 = 0. We can then com-
pute the probability of such an outcome by p = tr (ρM 1 ) = 0. Thus, our abstract representation
was able to provide a fully precise result.

Imprecise Measurement. Suppose now that instead of the measurement in Fig. 1, we had
I+Z
collapsed the lower qubit to |0i by applying projection M0 = 2 (1) .
To derive the resulting state, we again follow [2] closely. We note that the measurement Pauli
+Z(1) (i) anticommutes with the first product Pauli (−1){0,1} X(0) X(1) and commutes with the
second one (−1){0} X(1) and (ii) commutes with the initial Paulis {I, Z(1) }. In this case, we get
that the density matrix is unchanged, thus ρM 2 = ρD . To compute the trace of this matrix, we
follow the procedure outlined in §5.4. We omit intermediate steps here and get: 3

p = tr (ρM 2 ) = 4 Re(c) ≈ [0, 1.7].

Thus, our abstraction here is highly imprecise and does not yield any information on the measure-
ment result (we already knew that the probability must lie in [0, 1]).

4 Abstract Domains
In the following, we formalize all abstract domains (Tab. 2) underlying our abstract representation
of density matrices ρ along with key abstract transformers operating on them (Tab. 3). We
note that all abstract transformers introduced here naturally also support (partially) concrete
arguments.

Example Elements. Tab. 2 provides example elements of each abstract domain and exem-
plifies the respective concretization functions γ : X → 2X . While Tab. 2 correctly distinguishes
abstract elements from their concretization, in the following, when describing operators we write
concretizations instead of abstract elements (as announced in §2).

Booleans and Z4 . Abstract booleans b ∈ B = 2B are subsets of B, as exemplified in Tab. 2.


The addition of two abstract booleans naturally lifts boolean addition to sets and is clearly sound:

b + c = {b + c | b ∈ b, c ∈ c}. (7)

We define multiplication of abstract booleans analogously. Further, we define the join of two
abstract booleans as their set union.
Analogously to booleans, our abstract domain Z4 consists of subsets of Z4 , where addition,
subtraction, multiplication, and joins works analogously to abstract booleans. Further, we can
straight-forwardly embed abstract booleans into Z4 by mapping 0 to 0 and 1 to 1.

Real Numbers. We abstract real numbers by intervals [a, a] ⊆ R ∪ {±∞}, and denote the set
of such intervals by R. Interval addition, interval multiplication, and the cosine and exponential
transformer on intervals are defined in their standard way, see §2.

3 We used the precise interval bounds for c here, not the rounded values provided earlier.

6
Table 2: Example elements on abstract domains.

Dom. Example element Concretization


B {0, 1} {0, 1}
Z4 {0, 3} {0, 3}
R (0, 1) [0, 1] = {r | 0 ≤ r ≤ 1}
C (0, 1, π, 2π) e[0,1]+[π,2π]i ={er+ϕi | 0 ≤ r ≤ 1, π ≤ ϕ ≤ 2π} 
{0,3} b (1) (2) b ∈ {0, 3},
P2 ({0, 3}, {Z, Y}, {X}) i · {Z, Y} ⊗ {X} = i · P ⊗ P
P (1) ∈ {Z, Y}, P (2) ∈ {X}

Table 3: Summary of abstract transformers.

Transformers Domains Definition


b + c ∈ B, b · c ∈ B b, c ∈ B Lifting to sets, Eq. (7)
btc∈B b, c ∈ B b∪c
b + c ∈ Z4 , b − c ∈ Z4 , b · c ∈ Z4 b, c ∈ Z4 Lifting to sets
b t c ∈ Z4 b, c ∈ Z4 b∪c
b ∈ Z4 b∈B Embedding
c·d∈C c, d ∈ C Eq. (8)
ctd∈C c, d ∈ C Eq. (9)
Re(c) ∈ R c ∈ Cn Eq. (10)
ib ∈ C b∈B Eq. (11)
P Q ∈ Pn P, Q ∈ P n Eq. (12)
f(P Q) ∈ Z4 P , Q ∈ Pn Eq. (13)

U(i) P U(i) ∈ Pn U ∈ U (2k ), P ∈ P n Eq. (14)
P Q∈B P , Q ∈ Pn Eq. (15)
P t Q ∈ Pn P, Q ∈ P n Eq. (16)
(−1)b · P b ∈ B, P ∈ P n Eq. (17)

Complex Numbers. We parametrize complex numbers c ∈ C in polar coordinates (with mag-


nitude in log-space), as c = er+ϕi for r, ϕ ∈ R. For example, we parametrize 0 as e−∞+0i .
Based on this parametrization, we abstract complex numbers using two real intervals for r and
ϕ respectively, as exemplified in Tab. 2. Formally, we interpret c ∈ C as the set of all possible
outcomes when instantiating both intervals:
γ(c) = e[r,r]+[ϕ,ϕ]i = er+ϕi r ∈ [r, r], ϕ ∈ [ϕ, ϕ] .


We can compute the multiplication and join of two abstract complex numbers c = e[r,r]+[ϕ,ϕ]i
0 0 0 0
and c0 = e[r ,r ]+[ϕ ,ϕ ]i as
0 0 0 0
c · c0 = e[r+r ,r+r ]+[ϕ+ϕ ,ϕ+ϕ ]i and (8)
0 [min(r,r 0 ),max(r,r 0 )]+[min(ϕ,ϕ0 ),max(ϕ,ϕ0 )]i
ctc =e . (9)
Again, simple arithmetic shows that Eqs. (8)–(9) are sound.
We compute the real part of an abstract complex number c = e[r,r]+[ϕ,ϕ]i as

Re(c) = exp([r, r]) · cos [ϕ, ϕ] , (10)
where we rely on interval transformers to evaluate the right-hand side. The soundness of Eq. (10)
follows from the standard formula to extract the real part from a complex number in polar coor-
dinates. We will later use Eq. (10) to compute tr (ρ). To this end, we also need the transformer
G
ib = {ib } ∈ C. (11)
b∈b

Pauli Elements. Recall that a Pauli element P ∈ Pn has the form P = iv · P (0) ⊗ · · · ⊗ P (n−1) ,
for v in Z4 and P (k) ∈ {I, X, Y, Z}. We therefore parametrize P as a prefactor v (in logi space)
and n bare Paulis P (k) .

7
Accordingly, we parametrize abstract Pauli elements P ∈ P n as iv · P (0) ⊗ · · · ⊗ P (n−1) , where
v ∈ Z4 is a set of possible prefactors and P (k) ⊆ {X, Y, Z, I2 } are sets of possible Pauli matrices.
Formally, we interpret P as the set of all possible outcomes when instantiating all sets:
 
n−1
γ(P ) = iv · ⊗ P (i) v ∈ v, P (i) ∈ P (i) .
i=0

We define the product of two abstract Pauli elements as:


n−1  
P Q = if(P Q) ⊗ b P (i) Q(i) . (12)
i=0

To this end, we evaluate the prefactor induced by multiplying Paulis as


n
X
f(P Q) = f(P ) + f(Q) + f(P (i) Q(i) ), (13)
i=1

where we can evaluate the summands in the right-hand side of Eq. (13) by precomputing them
for all possible sets of Pauli matrices
  and Q . Then, we compute the sum using Eq. (7).
P (i) (i)

Analogously, we can evaluate b P (i) Q(i) by precomputation. The soundness of Eq. (12) follows
from applying the multiplication component-wise, and then separating out prefactors from bare
Paulis.
We also define the conjugation of an abstract Pauli element P with k-qubit gate U padded to
n qubits as:
 
† †
U(i) P U(i) = U(i) iv · P (0:i) ⊗ P (i:i+k) ⊗ P (i+k:n) U(i)
(i:i+k)
U †)
= iv+f(U P · P (0:i) ⊗ b(U P (i:i+k) U † ) ⊗ P (i+k:n) , (14)

where P (i:j) denotes P (i) ⊗ · · · ⊗ P (j−1) . Because k is typically small, and all possible gates U
are known in advance, we can efficiently precompute f(U P (i:i+k) U † ) and b(U P (i:i+k) U † ). We
note that this only works if the result of conjugation is indeed an (abstract) Pauli element—if not,
this operation throws an error. The soundness from Eq. (14) follows from applying U to qubits i
through i + k, and then separating out prefactors from bare Paulis.
We define the commutator P  Q of two abstract Pauli elements P and Q as
n
 n−1   n−1  X
(i) (i)
v
i · ⊗ P w
 i · ⊗ Q = P (i)  Q(i) . (15)
i=0 i=0
i=1

Here, we evaluate the sum using Eq. (7), and efficiently evaluate P (i)  Q(i) ∈ B by precomputing:
n o
P (i)  Q(i) = P (i)  Q(i) P (i) ∈ P (i) , Q(i) ∈ Q(i) .

The soundness of Eq. (15) can be derived from the corresponding concrete equation, which can be
verified through standard linear algebra manipulations.
We define the join of abstract Pauli elements as
 n−1   n−1  n−1  
iv ⊗ P (i) t iw ⊗ Q(i) = ivtw ⊗ P (i) ∪ Q(i) , (16)
i=0 i=0 i=0

where P (i) ∪ Q(i) ⊆ {I, X, Y, Z}. Clearly, this join is sound.


Finally, we define an abstract transformer for modifying the sign of an abstract Pauli element
P by:
 n−1  n−1
(−1)b · iv · ⊗ P (i) = iv+2·b · ⊗ P (i) (17)
i=0 i=0

The soundness of Eq. (17) follows directly from (−1)v = i2v .

8
Abstract Density Matrices. The concrete and abstract domains introduced previously allow
us to represent an abstract density matrix ρ ∈ D as
n
I+(−1)bj Qj
Y
ρ=r?c·P · 2 . (18)
j=1

where r ∈ N, c ∈ C, P ∈ P n , bj ∈ B, and Qj ∈ Pn . Note that Qj are concrete Pauli elements, while


P is abstract. Here, the integerPcounter r records how many concrete summands were abstracted.
r
Specifically, r ? x is defined as i=1 x. Overall, we interpret ρ as:
 
X r n 
I+(−1)bij Qj
Y
γ(ρ) = c i Pi 2 c i ∈ γ(c), Pi ∈ γ(P ), bij ∈ γ(b j ) ,
 
i=1 j=1

relying on the previously discussed interpretations of C, Pn , and B.

5 Abstract Transformers
We now formalize the abstract transformers used by Abstraqt to simulate quantum circuits. The
soundness of all transformers is straightforward, except for the trace transformer (§5.4) which we
discuss in App. A.

Initialization. We start from initial state ⊗ni=1 |0i, which corresponds to density matrix
n n
I+Z(j) I+(−1){0} Z(j)
Y Y
ρ= 2 = 1 ? e[0,0]+i[0,0] · i{0} {I} 2 ,
j=1 j=1

as established in [2, Sec. III]. We note that we can prepare other starting states by applying
appropriate gates to the starting state ⊗ni=1 |0i.

5.1 Gate Application


Analogously to the concrete case discussed in §2, applying a unitary gate U to ρ yields:
n
† 0
Y I+(−1)bj Q0j
U ρU = r ? cP 2 , (19)
j=1

for P 0 = U P U † and Q0j = U Qj U † .


If either U P U † 6⊆ Pn or U Qj U † 6⊆ Pn , Eq. (19) still holds, but we cannot represent the resulting
matricesPefficiently. In this case, again analogously to §2, we instead decompose the offending gate
as U = p dp Rp , with Rp ∈ Pn and obtain
n
I+(−1)bjq Qj
X Y
U ρU † = r ? cpq Ppq 2 , (20)
pq j=1

for cpq = dp cd∗q , P 0pq = Rp P Rq , and bjq = bj + Qj  Rq .


Overall, we can evaluate Eqs. (19)–(20) by relying on the abstract transformers from §4.

Compression. To prevent an exponential blow-up of the number of summands and to adhere


to the abstract domain of ρ which does not include a sum, we compress all summands to a single
one. Two summands can be joined as follows:
   
n n n
b1j b2j
Q Q I+(−1)bj Qj
Y I+(−1)
Y I+(−1)
Y
j j
r1 ? c1 P 1
2 t r2 ? c2 P 2

2 = r ? cP 2 ,
j=1 j=1 j=1

where r = r1 + r2 , c = c1 t c2 , bj = b1j t b2j , and P = P 1 t P 2 . The key observation here is that


the concrete Qj are independent of the summand, and thus need not be joined.
We note that we could also only merge some summands and leave the others precise—investigating
the effect of more flexible merging strategies could be interesting future research.

9
5.2 Measurement
We now describe how to perform Pauli measurements, by extending the (concrete) stabilizer sim-
ulation to abstract density matrices. The correctness of the concrete simulation was previously
established in [2, Sec. VII.C]—the correctness of the abstraction is immediate.

Simulating Measurement. Applying a Pauli measurement in basis R ∈ b(Pn ) has a proba-


bilistic outcome and transforms ρ to ρ+ = I+R I+R
2 ρ 2 with probability tr(ρ+ ) or ρ− = I−R I−R
2 ρ 2
with probability tr(ρ− ). We describe how to compute ρ+ . Computing ρ− works analogously by
using −R instead of R.
In the following, we will consider a concrete state ρ as defined in §2 and an abstract state ρ as
defined in Eq. (18):
m n n
I+(−1)bij Qj I+(−1)bj Qj
X Y Y
ρ= ci Pi 2 and ρ = r ? cP 2 . (21)
i=1 j=1 j=1

Concrete simulation of measurement distinguishes two cases: either (i) R commutes with all
Qj or (ii) R anti-commutes with at least one Qj . Note that as the Qj are concrete in an abstract
state ρ, those two cases translate directly to the abstract setting. We now describe both cases for
concrete and abstract simulation.

Background: Concrete Case (i). In this case, we assume R commutes with all Qj . Focusing
on a single summand ρi of ρ, measurement maps it to (see [2]):
n
I+(−1)bij Qj
Y
ρi,+ = ci I+R I+R
2 Pi 2 2 . (22)
j=1

Let us first introduce the notation {(−1)bij Qj } R, denoting that R can be written as a prod-
uct of selected Pauli elements from {(−1)bij Qj }. Symmetrically, we write {(−1)bij Qj } 6 R if R
Qn I+(−1)bij Qj
cannot be written as such a product. As shown in [2], if {(−1)bij Qj } R then I+R2 j=1 2
Qn I+(−1)bij Qj I+R Qn I+(−1)bij Qj
is equal to j=1 2 and if {(−1)bij
Qj } 6 R then 2 j=1 2 is null. Further,
using that R2 = I, we get from Eq. (22) that if Pi commutes with R, ρi,+ is equal to ρi , otherwise,
Pi anti-commutes with R and ρi,+ is null. Putting it all together, we finally get:
 n
I+(−1)bij Qj
m m 
if {(−1)bij Qj } R and R  Pi = 0,
Q
X X ci Pi 2
ρ+ = ρi,+ = j=1 (23)
0 if {(−1)bij Qj } 6 R or R  Pi = 1.

i=1 i=1

Abstract Case (i). Let us first define u and 6 u for a concrete R, concrete Qj and abstract
bj . We say {(−1)bj Qj } u R if for all j, for all bj ∈ γ(bj ), we have {(−1)bj Qj } R. Similarly,
we say {(−1)bj Qj } 6 u R if for all j, for all bj ∈ γ(bj ), we have {(−1)bj Qj } 6 R. Note that u
and 6 u are under-approximations, and there can exist some R and {(−1)bj Qj } such that neither
apply. Using those two abstract relations, we get the abstract transformer:
 n
I+(−1)bj Qj
if {(−1)bj Qj } u R and R  P = {0},
Q


 cP 2

 j=1
ρ+ = r ? 0 if {(−1)bj Qj } 6 u R or R  P = {1}, (24)
 n bj
I+(−1) Q
otherwise.
 Q j
(c t {0}) P


2
j=1

We can evaluate Eq. (24) by relying on the abstract transformers from Tab. 3 and by evaluat-
ing u
as discussed shortly.

10
Background: Concrete Case (ii). We now suppose R anti-commutes with at least one Qj . In
this case, we can rewrite ρ such that R anti-commutes with Q1 , and commutes with all other Qj .
Specifically, we can select any Qj ∗ which anti-commutes with R, swap bij ∗ and Qj ∗ with bi1 and
Q1 , and replace all other Qj anti-commuting with R by Q1 Qj (and analogously bij by bij + bi1 ),
which leaves ρ invariant (see [2]). Assuming ρ is the result after this rewrite, we have:
n
(
X 0
0 I+(−1) R
Y I+(−1)bij Qj Pi if R  Pi = 0,
ρ+ = 1
2 c i Pi , where Pi =
0
(25)
i
2
j=2
2
(−1) Pi Q1 if R  Pi = 1.
bi1

Overall, after rewriting ρ as above, Eq. (25) replaces Pi by Pi0 , bi1 by 0, and Q1 by R.

Abstract Case (ii). After applying the same rewrite as in the concrete case, directly abstracting
Eq. (25) yields:

n P
 if R  P = {0},
{0} bj
I+(−1) Qj
R
Y
ρ+ = r ? 21 cP 0 I+(−1)
2 2 , where P 0
= (−1) b1
P Q1 if R  P = {1}, (26)
P t (−1) P Q1 otherwise.
 b1
j=2 

Again, we can evaluate Eq. (26) by relying on the abstract transformers from Tab. 3.

Joining Both Measurement Results. For measurements occurring within a quantum circuit,
stabilizer simulation generally requires randomly selecting either ρ+ or ρ− with probability tr(ρ+ )
and tr(ρ− ), respectively, and then continues only with the selected state. In contrast, Abstraqt
can join both measurement outcomes into a single abstract state ρ+ t ρ− , as the Qj are the same
in both. This allows us to pursue both measurement outcomes simultaneously, as we demonstrate
in §7.

5.3 Efficiently computing


To simulate the result of a measurement, we introduced operator {(−1)bj Qj } R, denoting that
some Pauli R can be written as a product of {(−1)bj Qj }. We now show how to compute
efficiently.

Background: Concrete case. We first note that {(−1)bj Qj } R holds if and only if there
exist some x ∈ B such that:
n
!
Y xj
R= (−1)bj Qj . (27)
j=1

Further, this solution x would satisfy:


 
n
!
Y x j
b(R) = b  (−1)bj Qj  (28)
j=1

Eq. (28) has a solution if and only if R commutes with all the Qj , in which case this solution x is
unique (see [2]). Hence, to check if {(−1)bj Qj } R, we can first verify whether R  Qj = 0 for all
j, and if so, check if the unique x satisfying Eq. (28) also satisfies Eq. (27).

Background: Finding x for Eq. (28). To compute this solution x, the stabilizer simulation
relies critically on an isomorphism g between Pauli matrices {I, X, Y, Z} and B2 .
Specifically, g maps I to ( 00 ), X to ( 10 ), Y to ( 11 ), and Z to ( 01 ). Further, g extends naturally
n
to bare Pauli elements R ∈ b(Pn ) and tuples Q = (Q1 , . . . , Qn ) ∈ b(Pn ) by:
(0)
 (0)
  (0)

g(R ) g(Q1 ) ··· g(Qn )
g(R) =  ..  and g(Q) =  .. .. .. ,
. . . .
(n−1) (n−1) (n−1)
g(R ) g(Q1 ) ··· g(Qn )

11
where g(R) ∈ B2n×1 and g(Q) ∈ B2n×n . We can naturally extend g to Pn , by defining g(R) =
g(b(R)).
This isomorphism g is designed so that the product of bare Pauli elements ignoring prefactors
corresponds to a component-wise addition of encodings:
g(P1 P2 ) = g(P1 ) + g(P2 ). (29)
Using Eq. (29), we can obtain solution candidates x for Eq. (28) by solving a system of linear
equations using Gaussian elimination modulo 2:
!
n n
! Q xj P
g (R) = g Qj = g(Qj )xj = g(Q)x. (30)
j=1 j=1

Because in our case, g(Q) is over-determined and has full rank, Eq. (30) either has no solution, or
a unique solution x.

Background: Checking prefactors. Once we have found the unique x (if it exists) satisfying
Eq. (28) as described above, we need to check if it also satisfies Eq. (27). It is enough to check if
the prefactors match:  
! x
Y
f (R) = f  (−1)bj xj Qj j  ,
j

or equivalently:  
x !
Y X
f (R) − f  Qj j  − 2 bj xj = 0,
j j

where the subtraction and sum operations are over Z4 .


Putting it all together, we can define F : Pn × Pnn × Bn → Z4 ∪ {E} with

if ∃j, R  Qj = 1,

E
 !
F(R, Q, b) = n
Q xj n (31)
xj bj otherwise,
P
f(R) − f
 Qj −2
j=1 j=1

where x is the unique value such that g(R) = g(Q)x and E indicates there is no such x. We then
have that {(−1)bj Qj } R if and only if F(R, Q, b) = 0, and {(−1)bj Qj } 6 R if and only if
F(R, Q, b) 6= 0.

F for abstract bj . For abstract values bj , we define F : Pn × Pnn × Bn → 2Z4 ∪{E} as follows:

if ∃j, R  Qj = 1,

{E}
 !
F(R, Q, b) = n
Q xj n (32)
xj bj otherwise.
P
f(R) − f
 Qj −2
j=1 j=1

Following the same reasoning as above, we have that {(−1)bj Qj } u


R if and only if F(R, Q, b) =
{0} and {(−1)bj Qj } 6 u R if and only if F(R, Q, b) ∩ {0} = ∅.

F for abstract bj and R. To compute the trace of a state (see §5.4), we further extend Eq. (31)
to abstract bj and abstract R, defining F : P n × Pnn × Bn → 2Z4 ∪{E} as:

if ∃j.R  Qj = {1},


{E} !

 n n
x

if ∀j.R  Qj = {0},
Q P
f(R) − f Qj j − 2

xj bj
F(R, Q, b) = j=1 j=1 (33)
 !
 n n
f(R) − f Q Qxj − 2 P x b ∪ {E} otherwise,



 j j j
j=1 j=1

for g(R) = g(Q)x. (34)

12
Here, evaluating Eq. (33) requires evaluating Qbj for an abstract boolean b, which we define natu-
rally as 
{Qj }
 if b = {1},
b
Qj := {I} if b = {0},
{Qj , I} if b = {0, 1}.

Further, Eq. (34) requires over-approximating all x which satisfy g(R) = g(Q)x. Here, we naturally
extend g to abstract Paulis by joining their images. For instance, we have that g({X, Y }) =
{1} 
{( 10 )} t {( 11 )} = {0,1} . We then view g(R) = g(Q)x as a system of linear equations b = Ax,
where the left-hand side consists of abstract booleans b ∈ B2n . We then drop all equations in this
equation system where the left-hand side is {0, 1}, as they do not constrain the solution space.
This updated system is fully concrete, hencePp we can solve it using Gaussian elimination. We get
either no solution, or a solution space y + k=1 λk uk , where y is a possible solution and u1 , ..., up
is a possibly empty basis of the null solution space.
PIn the case of no solution, x is not needed in
m
Eq. (33). Otherwise, we can compute xj as {yj + k=1 λk uk,j | λk ∈ B}.

5.4 Trace
Recall that the probability of obtaining state ρ+ when measuring ρ is tr (ρ+ ). We now describe
how to compute this trace using F defined above.

Background: Concrete Trace. Following [2], we compute the trace of a density matrix ρ by:
m
X  
tr (ρ) = Re ci iF(P,Q,bi ) , (35)
i=1

where we define iE := 0. Because the trace of a density matrix is always real, Re(·) is redundant,
but will be convenient to avoid complex traces in our abstraction.

Abstract Trace. For an abstract state ρ, we define:


 
tr (ρ) = r · Re ciF(P ,Q,b) , (36)

where we use F(·) as defined in Eq. (33).

6 Implementation
In the following, we discuss our implementation of the abstract transformers from §4 and §5 in
Abstraqt.

Language and Libraries. We implemented Abstraqt in Python 3.8, relying on Qiskit 0.40.0 [14]
for handling quantum circuits, and a combination of NumPy 1.20.0 [15] and Numba 0.54 [16] to
handle matrix operations.

Qn I+(−1)bj Qj
Bit Encodings. An abstract density matrix ρ = r ? c · P · j=1 2 is encoded as a
tuple (r, c, P , b1 , ..., bn , Q1 , . . . , Qn ). To encode the concrete Pauli matrices Qj , we follow concrete
stabilizer simulation encodings such as [17] and encode Pauli matrices P using two bits g(P ) (see
§5.3). To encode abstract elements of a finite set we use bit patterns. For example, we encode
b1 = {1, 0} ∈ B as 112 , where the least significant bit (i.e. the right-most bit) indicates that
0 ∈ b1 . Analogously, we encode v = {3, 0} ∈ Z4 as 10012 . Further, we encode {Z, Y} as 11002 ,
where the indicator bits correspond to Z, Y, X, and I, respectively, from left to right. Hence the
abstact Pauli P = ({0, 3}, {Z, Y}, {X}) would be represented as (10012 , 11002 , 00102 ).

13
Implementing Transformers. The abstract transformers on abstract density matrices can be
implemented using operations in B, Z4 , C, and P 1 . As B, Z4 , and P 1 are small finite domains,
we can implement operations in these domains using lookup tables, which avoids the need for bit
manipulation tricks. While such tricks are applicable in our context (e.g., [2] uses bit manipulations

to compute H(i) P H(i) for P ∈ Pn ), they are generally hard to come up with [18]. In contrast, the
efficiency of our lookup tables is comparable to that of bit manipulation tricks, without requiring
new insights for new operations.
For example, to evaluate {} + {0} over B using Eq. (7), we encode the first argument {} as 00
and the second argument {0} as 01. Looking up entry (00, 01) in a two-dimensional pre-computed
table then yields 00, the encoding of the correct result {}. We note that we cannot implement
this operation directly using a XOR instruction on encodings, as this would yield incorrect results:
00 XOR 01 = 01 ' {0}, which is incorrect.

Gaussian Elimination. To efficiently solve equations modulo two as discussed in §5, we imple-
mented a custom Gaussian elimination relying on bit-packing (i.e., storing 32 boolean values in
a single 32-bit integer). In the future, it would be interesting to explore if Gaussian elimination
could be avoided altogether, as suggested by previous works [2, 17].

Testing. To reduce the likelihood of implementation errors, we have complemented Abstraqt


with extensive automated tests. We test that abstract transformers f ] are sound with respect to
concrete functions f , that is to say that

∀x1 ∈ γ(x1 ) · · · ∀xk ∈ γ(xk ).f (x1 , . . . , xn ) ∈ f ] (x1 , . . . , xk ).

We check this inclusion for multiple selected samples of xi and xi ∈ xi (typically corner cases).
This approach is highly effective at catching implementation errors, which we have found in
multiple existing tools as shown in §7.

7 Evaluation
We now present our evaluation of Abstraqt, demonstrating that it can establish circuit properties
no existing tool can establish.

7.1 Benchmarks
To evaluate Abstraqt, we generated 8 benchmark circuits, summarized and visualized in Tab. 4.

Benchmark Circuit Generation. Each circuit operates on 62 qubits, partitioned into 31 upper
qubits and 31 lower qubits. We picked the limit of 62 qubits because our baseline ESS (discussed
shortly) only supports up to 63 qubits; Abstraqt is not subject to such a limitation.
Each circuit operates on initial state |0i and is constructed to ensure that all lower qubits are
eventually reverted to state |0i. We chose this invariant as it can be expressed for each of the
evaluated tools, as we will show in §7.2. Further, as some tools can only check this for one qubit
at a time, we only check if the very last qubit is reverted to |0i, instead of running 31 independent
checks (which would artificially slow down some baselines). Note that this check is of equivalent
difficulty for all lower qubits.
Most of the circuits are built from three concatenated subcircuits. First c1 which only modifies
the upper qubits, then c2 which only modifies the lower qubits (potentially using gates controlled
by the upper qubits) and finally c3 which is generated by inverting c2 and optimizing the result
using PyZX [19]. Thus, running c1 ; c2 ; c3 on initial state |0i reverts the lower qubits to |0i, but
this is hard to establish as c3 is obfuscated by an optimization pass. Further, in all but the first
two circuits, the upper and lower qubits are entangled with each other. Tab. 4 details how c1 and
c2 were generated for each circuit. Note that Cliff+T;H;CZ+RX and CCX+H;Cliff slighter differ
from this construction. In the former, the circuit is built as c1 ; ch ; c2 ; c3 ; ch where ch applies an H
gate to each of the lower qubits in the circuit. In the latter, the circuit c2 also modifies the upper

14
Table 4: Description of benchmark circuits, where upper = {1, . . . , 31} and lower = {32, . . . , 62}.

Circuit Generation Gates


104
c1 ∈ {o(q) | o ∈ {H, S}, q ∈ upper} ∪ {CX(q1 , q2 ) | q1 , q2 ∈ upper}
Cliff;Cliff 104
c2 ∈ {o(q) | o ∈ {H, S}, q ∈ lower} ∪ {CX(q1 , q2 ) | q1 , q2 ∈ lower} 26k × Clifford
c3 = opt(c†2 );
return c1 ; c2 ; c3
104
c1 ∈ {o(q) | o ∈ {H, S, T }, q ∈ upper} ∪ {CX(q1 , q2 ) | q1 , q2 ∈ upper}
Cliff+T;Cliff 104
c2 ∈ {o(q) | o ∈ {H, S}, q ∈ lower} ∪ {CX(q1 , q2 ) | q1 , q2 ∈ lower} 23k × Clifford,
2.5k × T
c3 = opt(c†2 );
return c1 ; c2 ; c3
104
c1 ∈ {o(q) | o ∈ {H, S, T }, q ∈ upper} ∪ {CX(q1 , q2 ) | q1 , q2 ∈ upper}
Cliff+T;CX+T 104
c2 ∈ {CX(q1 , q2 ) | q1 ∈ upper, q2 ∈ lower} ∪ {T (q) | q ∈ lower} 18k × Clifford,
9k × T , 40 × T †
c3 = opt(c†2 );
return c1 ; c2 ; c3
104
c1 ∈ {o(q) | o ∈ {H, S, T }, q ∈ upper} ∪ {CX(q1 , q2 ) | q1 , q2 ∈ upper}
Cliff+T;H;CZ+RX ch = H(32); . . . ; H(62) 18k × Clifford,
104 5k × RX π ,
c2 ∈ {CZ(q1 , q2 ) | q1 ∈ upper, q2 ∈ lower} ∪ {RX (q) | q ∈ lower}
π 4
4 4k × T , 45 × T †
c3 = opt(c†2 );
return c1 ; ch ; c2 ; c3 ; ch
104
c1 ∈ {CCX(q1 , q2 , q3 ) | q1 , q2 , q3 ∈ upper} ∪ {H(q) | q ∈ upper}
CCX+H;Cliff c2 ∈ {o(q) | o ∈ {H, S}, q ∈ lower}∪
104 22k × Clifford,
{CX(q1 , q2 ) | q1 ∈ lower, q2 ∈ lower ∪ upper} 5k × CCX
c3 = opt(c†2 )
return c1 ; c2 ; c3
104
c1 ∈ {CCX(q1 , q2 , q3 ) | q1 , q2 , q3 ∈ upper} ∪ {H(q) | q ∈ upper}
CCX+H;CX+T 104 16k × Clifford,
c2 ∈ {CX(q1 , q2 ) | q1 ∈ upper, q2 ∈ lower} ∪ {T (q) | q ∈ lower} 5k × CCX,
c3 = opt(c†2 ); 7k × T , 29 × T †
return c1 ; c2 ; c3
104
c1 ∈ {o(q) | o ∈ {RZ2 , H}, q ∈ upper}
RZ2 +H;CX 104
c2 ∈ {CX(q1 , q2 ) | q1 ∈ upper, q2 ∈ lower} 16k × Clifford,
5k × RZ2
c3 = opt(c†2 );
return c1 ; c2 ; c3
MeasureGHZ c1 = CX(1, 2); . . . ; CX(1, 62)
12k × Clifford,
c2 = H(0); c1 ; measure(0), c1
100 × measure
return c2 ; . . . ; c2 (100 times)

15
qubits using gates controlled by the lower ones. Overall, our benchmark covers various gates, with
all applying Clifford gates, three applying T gates, two applying CCX gates, one applying RX π4
gates (one qubit gate, rotation around the X axis of π4 radians), and one applying RZ2 gates (one
qubit gate, rotation around the Z axis of 2 radians).
The last benchmark applies internal measurements. It first generates a GHZ state √12 |0 · · · 0i+
√1 |1 · · · 1i, and collapses it to |0 · · · 0i or |1 · · · 1i by measuring the first qubit. Then, it resets all
2
qubits to |0i except for the first one. It then repeats this process, with the first qubit starting
in either |0i or |1i. Thus, the state before measurement is either √12 |0 · · · 0i + √12 |1 · · · 1i or
√1 |0 · · · 0i − √1 |1 · · · 1i, but every repetition still resets all lower qubits to |0i.
2 2

Discussion. Overall, all benchmarks are constructed to revert the lower qubits to |0i, but in a
non-obvious way. As fully precise simulation of most benchmarks is unrealistic, we expect that
over-abstraction is typically necessary to establish this fact.

7.2 Baselines
We now discuss how we instantiated existing tools to establish that a circuit c evolves a qubit q to
state |0i. Overall, we considered two tools based on stabilizer simulation (ESS [5] and QuiZX [4]),
one tool based on abstract interpretation (YP21 [20], in two different modes), and one tool based
on state vectors (Statevector as implemented by Qiskit [14]).

ESS. Qiskit [14] provides an extended stabilizer simulator implementing the ideas published in [5]
which (i) decomposes quantum circuits into Clifford circuits, (ii) simulates these circuits separately,
and (iii) performs measurements by an aggregation across these circuits. To check if a circuit c
consistently evolves a qubit q to |0i, we check if c extended by a measurement of q always yields
0. To run our simulation, we used default parameters.

QuiZX. QuiZX [4] improves upon [5] by alternating between decomposing circuits (splitting
non-Clifford gates into Clifford gates) and optimizing the decomposed circuits (which may further
reduce non-Clifford gates). We can use QuiZX to establish that a qubit is in state |0i by "plugging"
output q as |1i and establishing that the probability of this output is zero. 4

YP21. Like Abstraqt, YP21 [20] also uses abstract interpretation, but relies on projectors
instead of stabilizer simulation. Specifically, it encodes the abstract state of selected (small) subsets
of qubits as projectors {Pj }j∈J , which constrain the state of these qubits to the range of Pj .
To check if a qubit q is in state |0i, we check if the subspace resulting from intersecting the range
of all Pj is a subset of the range of I + Z(q) —an operation which is natively supported by YP21.
When running YP21, we used the two execution modes suggested in its original evaluation [20].
The first mode tracks the state of all pairs of qubits, while the second considers subsets of 5 qubits
that satisfy a particular condition (for details, see [20, §9]). Because [20] does not discuss which
execution mode to pick for new circuits, we evaluated all circuits in both modes.
We note that because YP21 does not support CX(a, b) for a > b, we instead encoded such
gates as H(a); H(b); CX(b, a); H(b); H(a).

Statevector. Qiskit [14] further provides a simulator based on state vectors, which we also used
for completeness.

Abstraqt. In Abstraqt, we can establish that a qubit is in state |0i by measuring the final
abstract state ρ in basis Z(i) and checking if the probability of obtaining |1i is 0.

4 The use of plugging is described on https://github.com/Quantomatic/quizx/issues/9.

16
Table 5: Results when running simulators on benchmarks from Tab. 4. OOM indicates running out of memory,
unsupp. indicates the tool does not support an operation present in the circuit, and incorr. indicates incorrect
simulation results.

Label Abstraqt ESS QuiZX YP21 (mode 1) YP21 (mode 2) Statevec.


Cliff;Cliff 3 (13s) 7 (12s, incorr.) 7 (0s, error) 7 (3.1h, imprec.) 7 (5s, incorr.) 7 (OOM)
Cliff+T;Cliff 3 (11s) 7 (12s, incorr.) 3 (3.1h) 7 (3.0h, imprec.) 7 (5s, incorr.) 7 (OOM)
Cliff+T;CX+T 3 (18s) 7 (OOM) 7 (OOM) 7 (3.1h, imprec.) 7 (5s, incorr.) 7 (OOM)
Cliff+T;H+CZ+RX 3 (21s) 7 (OOM) 7 (>6h) 7 (3.4h, imprec.) 7 (6s, incorr.) 7 (OOM)
CCX+H;Cliff 3 (70s) 7 (OOM) 7 (>6h) 7 (>6h) 7 (OOM) 7 (OOM)
CCX+H;CX+T 3 (77s) 7 (OOM) 7 (OOM) 7 (>6h) 7 (OOM) 7 (OOM)
RZ2 +H;CX 3 (12s) 7 (OOM) 7 (error, 0s) 7 (unsupp.) 7 (unsupp.) 7 (OOM)
MeasureGHZ 3 ( 4s) 7 (unsupp.) 7 (unsupp.) 7 (unsupp.) 7 (unsupp.) 7 (unsupp.)

Experimental Setup. We executed all experiments on a desktop machine with 16 GB RAM


and 4 cores at 3.4 GHz, running Ubuntu 18.04. Because some tools consumed excessive amounts of
memory, we limited them to 12 GB of RAM. This was not necessary for Abstraqt, which never
required more than 600 MB of RAM.

7.3 Results
Tab. 5 summarizes the results when using all tools discussed in §7.2 to establish that the last qubit
in each circuit is in state |0i. Overall, it demonstrates that while Abstraqt can establish this
for all benchmarks within minutes, QuiZX can only establish it for one benchmark and all other
tools cannot establish it for any circuit. Further, we found that for some circuits the established
simulation tool ESS yields incorrect results. We now discuss the results of each tool in more details.

MeasureGHZ. Importantly, no baseline tool except Abstraqt can simultaneously simulate both
outcomes of a measurement, without incurring an exponential blow-up. Therefore, for MeasureGHZ,
we consider internal measurements as an unsupported operation in these tools. We note that we
could randomly select one measurement outcome and simulate the remainder of the circuit for
it, but then we can only establish that the final state is |0i for a given sequence of measurement
outcomes. In contrast, a single run of Abstraqt can establish that the final state is |0i for all
possible measurement outcomes (see also §5.2).

ESS. Surprisingly, ESS does not simulate circuits Cliff;Cliff and Cliff+T;Cliff correctly.
Instead, it samples the impossible measurement of 1 around 50% of cases. Interestingly, smaller cir-
cuits generated with the same process are handled correctly. It is reassuring to see that Abstraqt
allows us to discover such instabilities in established tools.
Note that it may be surprising that ESS can simulate circuits containing many T gates—this is
because Qiskit can establish that the Clifford+T part of circuit Cliff+T;Cliff is irrelevant when
measuring the last qubit. In contrast, for most remaining circuits, ESS runs out of memory as it
decomposes the circuit into exponentially many Clifford circuits.

QuiZX. QuiZX also fails to simulate Cliff;Cliff, which we conjecture is due to a bug for
circuits that do not contain non-Clifford gates. After adding a single T gate, or when running
Cliff+T;Cliff, simulation is successful. However, we note that Abstraqt is significantly faster
than QuiZX, possibly because it does not need to repeatedly optimize circuits.
The results on the remaining circuits are analogous to ESS, except that QuiZX sometimes times
out instead of running out of memory. Further, we note that QuiZX runs into an internal error
when simulating RZ2 +H;CX.

YP21. YP21 typically either times out, throws an internal error, does not support a relevant
operation (e.g., measurements or RZ2 ), or returns incorrect results. The latter is because on some
circuits, mode 2 choses an empty set of projectors, which leads to trivially unsound results. When
YP21 does terminate, it is too imprecise to establish that the last qubit is in state |0i.

17
Statevector. Unsurprisingly, statevector simulation cannot handle the circuits in Tab. 5. This
is because it requires space exponential in the number of qubits, which precludes simulating any
of the benchmarks.

7.4 Discussion and Limitations


We note that our benchmarks are designed to showcase successful applications of Abstraqt where
it outperforms existing tools. Of course, Abstraqt is not precise on all circuits—e.g., Abstraqt
quickly loses precision on general Clifford+T circuits (analogously to the imprecise measurement
discussed in §3).
We expect that for many real-world circuits, existing approaches work better than the current
implementation of Abstraqt. However, as Abstraqt only over-abstracts the first stabilizer
simulation generalized to non-Clifford gates [2, §VII-C], we believe it paves the way to also over-
abstract more recent stabilizer simulators. For example, ESS [5] operates on so-called CH-forms
which, like the generalized stabilizer simulation underlying Abstraqt, can be encoded using bits
and complex numbers. Hence, it seems plausible that our ideas could be adapted to abstract ESS.
QuiZX operates on ZX-diagrams consisting of graphs whose nodes are parametrized by rotation
angles α. Again, a promising direction for future research is introducing abstract ZX-diagrams that
support abstract rotation angles. This is particularly promising because both ESS and QuiZX scale
better in number of T gates than [2, §VII-C]: with 2n instead of 4n .
Overall, we believe that all tools in Tab. 5 are valuable to analyze quantum circuits. We are
hoping that addressing some limitations of the considered baselines (e.g., fixing bugs in QuiZX and
ESS) and cross-pollinating ideas (e.g., extending QuiZX by abstract interpretation) will allow the
community to benefit from the fundamentally different mathematical foundations of all tools.

8 Related Work
Here, we discuss works related to our goal and methods.

Quantum Abstract Interpretation. Some existing works have investigated abstract interpre-
tation for simulating quantum circuits [20, 21, 22]. As [20] is not specialized for Clifford circuits,
it is very imprecise on the circuits investigated in §7: it cannot derive that the lower qubits are
|0i for any of them. While [21, 22] are inspired by stabilizer simulation, they only focus on de-
termining if certain qubits are entangled or not, whereas Abstraqt can extract more precise
information about the state. Further, both tools are inherently imprecise on non-Clifford gates—
in contrast, a straight-forward extension of Abstraqt can treat some non-Clifford gates precisely
at the exponential cost of not merging summands.

Stabilizer Simulation. The Gottesman-Knill theorem [1] established that stabilizers can be
used to efficiently simulate Clifford circuits. Stim [17] is a recent implementation of such a simu-
lator, which only supports non-Clifford gates and Pauli measurements.
Stabilizer simulation was extended to allow for non-Clifford gates at an exponential cost, while
still allowing efficient simulation of Clifford gates [2, §VII-C]. Various works build upon this in-
sight, handling Clifford gates efficiently but suffering from an exponential blow-up on non-Clifford
gates [3, 4, 5, 6, 7]. In our evaluation, we demonstrate that Abstraqt extends the reach of
state-of-the-art stabilizer simulation by comparing to two tools from this category, ESS [5] (chosen
because it is implemented in the popular Qiskit library) and QuiZX [4] (chosen because it is a
recent tool reporting favorable runtimes).

Verifying Quantum Programs. Another approach to establishing circuit properties is end-to-


end formal program verification, as developed in [23] for instance. However, this approach typically
requires new insights for each program it is applied to. Even though recent works have greatly
improved verification automation, proving even the simplest programs still requires a significant
time investment [24], whereas our approach can analyze it without any human time investment.

18
Finally, the work [25] automatically generates rich invariants, but is exponential in the number of
qubits, limiting its use to small circuits.

9 Conclusion
In this work, we have demonstrated that combining abstract interpretation with stabilizer simula-
tion allows to establish circuit properties that are intractable otherwise.
Our key idea was to over-abstract the behavior of non-Clifford gates in the generalized stabilizer
simulation of Aaronson and Gottesman [2] by merging summands in the sum representation of
the quantum states density matrix. Our carefully chosen abstract domain allows us to define
efficient abstract transformers that approximate each of the concrete stabilizer simulation functions,
including measurement.

References
[1] Daniel Gottesman. “The Heisenberg Representation of Quantum Computers”. Technical Re-
port arXiv:quant-ph/9807006. arXiv (1998).
[2] Scott Aaronson and Daniel Gottesman. “Improved Simulation of Stabilizer Circuits”. Physical
Review A 70, 052328 (2004).
[3] Robert Rand, Aarthi Sundaram, Kartik Singhal, and Brad Lackey. “Extend-
ing gottesman types beyond the clifford group”. In The Second International
Workshop on Programming Languages for Quantum Computing (PLanQC 2021).
(2021). url: https://pldi21.sigplan.org/details/planqc-2021-papers/9/
Extending-Gottesman-Types-Beyond-the-Clifford-Group.
[4] Aleks Kissinger and John van de Wetering. “Simulating quantum circuits with ZX-calculus
reduced stabiliser decompositions”. Quantum Science and Technology 7, 044001 (2022).
[5] Sergey Bravyi, Dan Browne, Padraic Calpin, Earl Campbell, David Gosset, and Mark
Howard. “Simulation of quantum circuits by low-rank stabilizer decompositions”. Quantum
3, 181 (2019).
[6] Hakop Pashayan, Oliver Reardon-Smith, Kamil Korzekwa, and Stephen D. Bartlett. “Fast
estimation of outcome probabilities for quantum circuits”. PRX Quantum 3, 020361 (2022).
[7] “Classical simulation of quantum circuits with partial and graphical stabiliser decompositions”.
Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2022).
[8] Patrick Cousot and Radhia Cousot. “Abstract Interpretation: A Unified Lattice Model for
Static Analysis of Programs by Construction or Approximation of Fixpoints”. In Proceedings
of the 4th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages.
Pages 238–252. POPL ’77New York, NY, USA (1977). ACM.
[9] Patrick Cousot and Radhia Cousot. “Abstract interpretation frameworks”. Journal of logic
and computation 2, 511–547 (1992).
[10] Bruno Blanchet, Patrick Cousot, Radhia Cousot, Jérome Feret, Laurent Mauborgne, Antoine
Miné, David Monniaux, and Xavier Rival. “A static analyzer for large safety-critical software”.
ACM SIGPLAN Notices 38, 196–207 (2003).
[11] Francesco Logozzo and Manuel Fähndrich. “Pentagons: A weakly relational abstract domain
for the efficient validation of array accesses”. Science of Computer Programming 75, 796–
807 (2010).
[12] Timon Gehr, Matthew Mirman, Dana Drachsler-Cohen, Petar Tsankov, Swarat Chaudhuri,
and Martin Vechev. “AI2: Safety and Robustness Certification of Neural Networks with
Abstract Interpretation”. In 2018 IEEE Symposium on Security and Privacy (SP). Pages
3–18. San Francisco, CA (2018). IEEE.
[13] Michael A. Nielsen and Isaac L. Chuang. “Quantum computation and quantum information:
10th anniversary edition”. Cambridge University Press. (2010).

19
[14] Héctor Abraham et al. “Qiskit: An open-source framework for quantum computing” (2019).
[15] Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt, Ralf Gommers, Pauli Vir-
tanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith,
Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan
Haldane, Jaime Fernández del Río, Mark Wiebe, Pearu Peterson, Pierre Gérard-Marchant,
Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and
Travis E. Oliphant. “Array programming with NumPy”. Nature 585, 357–362 (2020).
[16] Siu Kwan Lam, Antoine Pitrou, and Stanley Seibert. “Numba: a LLVM-based Python JIT
compiler”. In Proceedings of the Second Workshop on the LLVM Compiler Infrastructure
in HPC. Pages 1–6. LLVM ’15New York, NY, USA (2015). Association for Computing
Machinery.
[17] Craig Gidney. “Stim: a fast stabilizer circuit simulator”. Quantum 5, 497 (2021).
[18] Henry S. Warren. “Hacker’s delight”. Addison-Wesley Professional. (2012). 2nd edition.
[19] Aleks Kissinger and John van de Wetering. “PyZX: Large Scale Automated Diagrammatic
Reasoning”. In Bob Coecke and Matthew Leifer, editors, Proceedings 16th International
Conference on Quantum Physics and Logic, Chapman University, Orange, CA, USA., 10-14
June 2019. Volume 318 of Electronic Proceedings in Theoretical Computer Science, pages
229–241. Open Publishing Association (2020).
[20] Nengkun Yu and Jens Palsberg. “Quantum abstract interpretation”. In Proceedings of the
42nd ACM SIGPLAN International Conference on Programming Language Design and Imple-
mentation. Pages 542–558. PLDI 2021New York, NY, USA (2021). Association for Computing
Machinery.
[21] Simon Perdrix. “Quantum Entanglement Analysis Based on Abstract Interpretation”. In
Proceedings of the 15th International Symposium on Static Analysis. Pages 270–282. SAS
’08Berlin, Heidelberg (2008). Springer-Verlag.
[22] Kentaro Honda. “Analysis of Quantum Entanglement in Quantum Programs using Stabilizer
Formalism”. Electronic Proceedings in Theoretical Computer Science195 (2015).
[23] Kesha Hietala, Robert Rand, Shih-Han Hung, Liyi Li, and Michael Hicks. “Proving Quantum
Programs Correct”. Leibniz International Proceedings in Informatics (LIPIcs) 193, 21:1–
21:19 (2021).
[24] Christophe Chareton, Sébastien Bardin, François Bobot, Valentin Perrelle, and Benoît Val-
iron. “An automated deductive verification framework for circuit-building quantum programs”.
In Programming Languages and Systems. Pages 148–177. Springer International Publish-
ing (2021).
[25] Mingsheng Ying, Shenggang Ying, and Xiaodi Wu. “Invariants of quantum programs: Char-
acterisations and generation”. SIGPLAN Not. 52, 818–832 (2017).

20
A Abstract Transformers Soundness
Here, we prove the soundness of the trace transformer Eq. (36):
Theorem A.1. Trace. For all ρ ∈ D we have

γ ◦ tr (ρ) ⊇ tr ◦γ(ρ).

Proof. The over-approximation F# follows closely the form of F, where the first term f(P ) over-
approximates the prefactors of P and secondQn term over-approximates the prefactors originating
y
from the solution space for y of b(P ) = b( j=1 Qj j ). Overall, we have:
( r n
)!
X Y bij

1
tr ◦γ (ρ) = tr ci Pi 2
I + (−1) Qj ci ∈ c, Pi ∈ P , bij ∈ bj
i=1 j=1
( r n
! )
X Y bij

1
= tr ci Pi 2
I + (−1) Qj ci ∈ c, Pi ∈ P , bij ∈ bj
i=1 j=1
( r )
X F(P,Q,bij )

= Re ci i ci ∈ c, Pi ∈ P , bij ∈ bj Concrete trace, §5.4
i=1
r
X
Re {ci ∈ c} · iF({Pi ∈P },Q,{bij ∈bj })

=
i=1
r
!
 
F] (P ,Q,bj )
X
⊆γ Re c · i Soundness of transf.
i=1
  ]

(P ,Q,bj )
= γ r · Re c · iF Property of intervals

= γ ◦ tr (ρ) .

21
0 −i
 1 0

Table 6: States stabilized by Pauli matrices P and also −P , where X := ( 01 10 ), Y := i 0 , Z := 0 −1 ,
and I2 := ( 10 01 ).

Stab. State vec. Dens. mat. Stab. State vec. Dens. mat.
1 −1
1 1 1 1
 1
 
√1 1
∧ ∧
X √ (1)
2 1
= |+i 2 1 1 −X 2 −1 = |−i 2 −1 1
1 −i
1 1 1 i
 1
 
Y √ (1) −Y √1 1
2 i 2 −i 1 2 −i 2 i 1
∧ 1 0
 0
 ∧ 0 0

Z ( 10 ) = |0i 0 0 −Z 1 = |1i 0 1

I2 (any vec.) - −I2 (no vec.) -

Table 7: Multiplication of Pauli matrices.

II = I IX = X IY = Y IZ = Z
XI = X XX = I XY = iZ XZ = −iY
YI = Y YX = −iZ YY = I YZ = iX
ZI = Z ZX = iY ZY = −iX ZZ = I

B Stabilizers and Pauli Matrices


Tab. 6 shows the states stabilized by each Pauli matrix, together with the density matrix of the
stabilized state. Further, Tab. 7 shows the multiplication table for the Pauli matrices.

22

You might also like