SlideShare a Scribd company logo
1 of 37
Download to read offline
A Verified Optimizer for
Quantum Circuits
Kesha Hietala, Robert Rand, Shih-Han Hung,

Xiaodi Wu, Michael Hicks
Verified translation between
low-level quantum languages
Kartik Singhal, Robert Rand, Michael Hicks
&
1 PLanQC 2020
Verified Compiler Stack
• End goal: verified compiler stack for quantum programs
High-level Language
E.g. QWIRE, Quipper, Q#
Unoptimized IR
E.g. OpenQASM, Quil
Optimized IR
E.g. OpenQASM, Quil
Hardware Instructions
2
Verified Compiler Stack
• End goal: verified compiler stack for quantum programs
High-level Language
E.g. QWIRE, Quipper, Q#
Unoptimized IR
E.g. OpenQASM, Quil
Optimized IR
E.g. OpenQASM, Quil
Hardware Instructions
2
Optimization

Circuit synthesis

Circuit mapping

…
Verified Compiler Stack
• End goal: verified compiler stack for quantum programs
High-level Language
E.g. QWIRE, Quipper, Q#
Unoptimized IR
E.g. OpenQASM, Quil
Optimized IR
E.g. OpenQASM, Quil
Hardware Instructions
2
Optimization

Circuit synthesis

Circuit mapping

…
Means that we’ve formally
verified that the transformation
is semantics-preserving
Verified Compiler Stack
• We present VOQC, our Verified Optimizer for Quantum
Circuits, which is built on top of SQIR, our Small
Quantum Intermediate Representation

• Implemented in 8000 lines of Coq code, with 1500 for
core SQIR and the rest for program transformations

• 400 lines of standalone OCaml code for parsing and
translating OpenQASM

• We extract VOQC to OCaml and compile it to a binary, so
using VOQC doesn’t require knowledge of Coq or OCaml
3
Verified Compiler Stack
• End goal: verified compiler stack for quantum programs
High-level Language
E.g. QWIRE, Quipper, Q#
Unoptimized IR
E.g. OpenQASM, Quil
Optimized IR
E.g. OpenQASM, Quil
Hardware Instructions
4
Unoptimized SQIR
Optimized SQIR
VOQC
SQIR
• Syntax

• Semantics assumes a global register of size d
• A unitary program corresponds to a unitary matrix of
size 

• A non-unitary program corresponds to a function
between density matrices of size
2d
× 2d
2d
× 2d
5
 pro-
s uni-
which
s that
, a
nto a
allow
ubits,
te set
lobal
ation
ts are
dex is
will often want something more general since   and ei
 
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
∀P, nT(P)o = nPo
SQIR
• Syntax

• Semantics assumes a global register of size d
Unitary semantics Non-unitary semantics
6
 pro-
s uni-
which
s that
, a
nto a
allow
ubits,
te set
lobal
ation
ts are
dex is
will often want something more general since   and ei
 
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
∀P, nT(P)o = nPo
Dra paper, November 22, 2019, K. Hietala, R. Rand, S. Hung, X. Wu  M
nU1; U2od = nU2od × nU1od
nG1 qod =



appl 1(G1, q, d) well-typed
02d otherwise
nG2 q1 q2od =



appl 2(G2, q1, q2, d) well-typed
02d otherwise
Figure 3. Semantics of unitary s programs, assuming a
controlled-not gate. We refer to this gate set as the
It is the same as the underlying set used by OpenQA
and is universal, meaning that it can approximate any
operation to within arbitrary error. The matrix interp
of the single-qubit R , , gate is

cos( 2) −ei
sin( 2)
ei
sin( 2) ei( + )
cos( 2)

and the matrix interpretation of the CNOT gate is g
Section 2.1.
A Verified Optimizer for antum Circuits
{skip}d ( ) =
{P1; P2}d ( ) = ({P2}d ○ {P1}d )( )
{U }d ( ) = nU od × × nU o†
d
{meas q P1 P2}d ( ) = {P2}d (0q0 × × 0q0)
+ {P1}d (1q1 × × 1q1)
Figure 4. s density matrix semantics, assuming a globa
VOQC Transformations
• Unitary optimizations - inspired by Nam et al.1

• Gate propagation and cancellation

• Rotation merging

• Non-unitary optimizations

• Classical state propagation

• Removing z-rotations before measurement

• Circuit mapping

• Naive mapping for arbitrary connected graph
1Nam et al. Automated Optimization of Large Quantum Circuits with Continuous Parameters. 2018.
7
Example: X/Z Propagation
• Simplified code:

8
er 22, 2019, K. Hietala, R. Rand, S. Hung,
X H ● H X
→
H Z ● H X
→
H ● Z H X
→
H ● H X X
→
H ● H
e of not propagation. In the rst step the leftmost X gate propagates through the le
he second step the Z gate propagates through the control of the CNOT gate. In the th
he rightmost H gate and becomes an X gate. In the nal step the two X gates cancel.
H ≡
●
H H Rz 4(k)
●
k′) ≡
● ●
Rz 4(k′) Rz 4(k)
Whereas evaluation of the right-hand cir
x1,x2 → x1,x1 ⊕ x2
→ x2,x1 ⊕ x2
→ ei((k+k′
) 4)x2
x2,x
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and e  
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Example: X/Z Propagation
• Simplified code:

8
A
A
er 22, 2019, K. Hietala, R. Rand, S. Hung,
X H ● H X
→
H Z ● H X
→
H ● Z H X
→
H ● H X X
→
H ● H
e of not propagation. In the rst step the leftmost X gate propagates through the le
he second step the Z gate propagates through the control of the CNOT gate. In the th
he rightmost H gate and becomes an X gate. In the nal step the two X gates cancel.
H ≡
●
H H Rz 4(k)
●
k′) ≡
● ●
Rz 4(k′) Rz 4(k)
Whereas evaluation of the right-hand cir
x1,x2 → x1,x1 ⊕ x2
→ x2,x1 ⊕ x2
→ ei((k+k′
) 4)x2
x2,x
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and e  
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Example: X/Z Propagation
• Simplified code:

8
B
B
er 22, 2019, K. Hietala, R. Rand, S. Hung,
X H ● H X
→
H Z ● H X
→
H ● Z H X
→
H ● H X X
→
H ● H
e of not propagation. In the rst step the leftmost X gate propagates through the le
he second step the Z gate propagates through the control of the CNOT gate. In the th
he rightmost H gate and becomes an X gate. In the nal step the two X gates cancel.
H ≡
●
H H Rz 4(k)
●
k′) ≡
● ●
Rz 4(k′) Rz 4(k)
Whereas evaluation of the right-hand cir
x1,x2 → x1,x1 ⊕ x2
→ x2,x1 ⊕ x2
→ ei((k+k′
) 4)x2
x2,x
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and e  
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Proof Overview
• For a transformation T, we want to prove that
(up to a global phase)

• For complex optimizations, rather than proving this
equality directly we may prove that and have
the same output on every basis state

• For circuit mapping we also prove that for every ,
respects the provided connectivity constraints

• Proofs proceed by induction on
→ [X q]
t → t
t → H q ; propagate_Z q t
: t → Rz†
q ; propagate_X q t
∀P, nT(P)o = nPo
mand meas q P1 P2 (inspired by a similar con-
PL [43]) measures the qubit q and either performs
or P2 depending on the result. We dene non-
measurement and resetting a qubit to 0 in terms
g measurement:
measure q = meas q skip skip
reset q = meas q (X q) skip
denes the semantics of non-unitary programs
density matrices, following the approach of sev-
T(P) P
P T(P)
P
9
Example: X/Z Propagation
• We will want to prove that for any instruction list lst,
(propagate_X q lst) has the same denotation as (X q ; lst)

• propagate_X q lst X q ; lst

• Proof proceeds by induction on lst



≡
10
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and ei
 
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Example: X/Z Propagation
• We will want to prove that for any instruction list lst,
(propagate_X q lst) has the same denotation as (X q ; lst)

• propagate_X q lst X q ; lst

• Proof proceeds by induction on lst



≡
propagate_X q [ ] [ X q ] X q ; [ ]→ ≡
10
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and ei
 
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Example: X/Z Propagation
• We will want to prove that for any instruction list lst,
(propagate_X q lst) has the same denotation as (X q ; lst)

• propagate_X q lst X q ; lst

• Proof proceeds by induction on lst



≡
propagate_X q (X q :: t) t X q ; X q ; t→ ≡
10
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and ei
 
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Example: X/Z Propagation
• We will want to prove that for any instruction list lst,
(propagate_X q lst) has the same denotation as (X q ; lst)

• propagate_X q lst X q ; lst

• Proof proceeds by induction on lst



≡
propagate_X (Rz q :: t) 

Rz† q ; propagate_X q t
Rz† q ; (X q ; t) 

X q ; Rz q ; t
→
≡
≡
10
ro-
ni-
ch
hat
, a
o a
ow
its,
set
bal
on
will often want something more general since   and ei
 
(for ∈ R) represent the same physical state. We therefore say
that two circuits are equivalent up to a global phase, written
U1 ≅ U2, when there exists a such that nU1od = ei
nU2od .
3.2 Adding Measurement
To describe general quantum programs P, we extend unitary
s with a branching measurement operation.
U ∶= U1; U2  G q  G q1 q2
P ∶= skip  P1; P2  U  meas q P1 P2
let propagate_X q lst = match lst with
| [] → [X q]
| X q :: t → t
| H q :: t → H q ; propagate_Z q t
| Rz q :: t → Rz†
q ; propagate_X q t
...
Verifying Matrix Equivalences
• Proving matrix equivalences in Coq is tedious

• E.g. 

11
each other out.
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to justify
local rewrites. Proof that an optimization is correct thus relies
on proofs that the circuit equivalences it uses are correct.
Many of our circuit equivalence proofs have a common form,
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denition
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
per Figure 3. Suppose both sides of the equation are well
typed (m  d and n  d and m = n), and consider the case
m  n (the n  m case is similar). We expand appl 1 and
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
term.)
simpli
matrix
In o
gridif
I2m ⊗
provin
We
in the
is mos
alence
apply t
For eq
one us
but sti
4.3 O
Our pr
localiz
rules. T
of gate
other out.
Proving Circuit Equivalences
’s optimizations use circuit equivalences to justify
ewrites. Proof that an optimization is correct thus relies
oofs that the circuit equivalences it uses are correct.
of our circuit equivalence proofs have a common form,
we illustrate by example.
pose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
bitrary n,m and dimension d. Applying our denition
ivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
gure 3. Suppose both sides of the equation are well
(m  d and n  d and m = n), and consider the case
(the n  m case is similar). We expand appl 1 and
2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
m p q
term.) After expressions are in g
simplies them by removing mu
matrix and rewriting simple matr
In our example, after normaliz
gridify, both sides of the equalit
I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m
proving that the two expressions
We use gridify to verify mos
in the optimizations given in Sec
is most eective when equivale
alences used in gate cancellation
apply to patterns of at most ve
For equivalences over larger, non
one used in rotation merging, we
but still rely on our automation f
4.3 Optimization by Propaga
Our propagate-cancel optimizatio
localize a set of gates by repeate
rules. Then we apply a circuit equ
of gates. In  most optimizatio
of code patterns, but one—not pr
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to jus
local rewrites. Proof that an optimization is correct thus re
on proofs that the circuit equivalences it uses are corr
Many of our circuit equivalence proofs have a common fo
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denit
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
per Figure 3. Suppose both sides of the equation are w
typed (m  d and n  d and m = n), and consider the c
m  n (the n  m case is similar). We expand appl 1 a
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
+ I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
Verifying Matrix Equivalences
• Proving matrix equivalences in Coq is tedious

• E.g. 

11
each other out.
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to justify
local rewrites. Proof that an optimization is correct thus relies
on proofs that the circuit equivalences it uses are correct.
Many of our circuit equivalence proofs have a common form,
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denition
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
per Figure 3. Suppose both sides of the equation are well
typed (m  d and n  d and m = n), and consider the case
m  n (the n  m case is similar). We expand appl 1 and
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
term.)
simpli
matrix
In o
gridif
I2m ⊗
provin
We
in the
is mos
alence
apply t
For eq
one us
but sti
4.3 O
Our pr
localiz
rules. T
of gate
other out.
Proving Circuit Equivalences
’s optimizations use circuit equivalences to justify
ewrites. Proof that an optimization is correct thus relies
oofs that the circuit equivalences it uses are correct.
of our circuit equivalence proofs have a common form,
we illustrate by example.
pose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
bitrary n,m and dimension d. Applying our denition
ivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
gure 3. Suppose both sides of the equation are well
(m  d and n  d and m = n), and consider the case
(the n  m case is similar). We expand appl 1 and
2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
m p q
term.) After expressions are in g
simplies them by removing mu
matrix and rewriting simple matr
In our example, after normaliz
gridify, both sides of the equalit
I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m
proving that the two expressions
We use gridify to verify mos
in the optimizations given in Sec
is most eective when equivale
alences used in gate cancellation
apply to patterns of at most ve
For equivalences over larger, non
one used in rotation merging, we
but still rely on our automation f
4.3 Optimization by Propaga
Our propagate-cancel optimizatio
localize a set of gates by repeate
rules. Then we apply a circuit equ
of gates. In  most optimizatio
of code patterns, but one—not pr
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to jus
local rewrites. Proof that an optimization is correct thus re
on proofs that the circuit equivalences it uses are corr
Many of our circuit equivalence proofs have a common fo
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denit
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
per Figure 3. Suppose both sides of the equation are w
typed (m  d and n  d and m = n), and consider the c
m  n (the n  m case is similar). We expand appl 1 a
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
+ I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
local rewrites. Proof that an optimization is correct thus relies
on proofs that the circuit equivalences it uses are correct.
Many of our circuit equivalence proofs have a common form,
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denition
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
per Figure 3. Suppose both sides of the equation are well
typed (m  d and n  d and m = n), and consider the case
m  n (the n  m case is similar). We expand appl 1 and
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
+ I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
gridify, both sides of th
I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗
proving that the two ex
We use gridify to ve
in the optimizations give
is most eective when
alences used in gate ca
apply to patterns of at m
For equivalences over la
one used in rotation mer
but still rely on our auto
4.3 Optimization by
Our propagate-cancel op
localize a set of gates by
rules. Then we apply a c
of gates. In  most op
of code patterns, but on
we discuss it rst.
6
Many of our circuit equivalence proofs have a common form
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denitio
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(
per Figure 3. Suppose both sides of the equation are we
typed (m  d and n  d and m = n), and consider the cas
m  n (the n  m case is similar). We expand appl 1 an
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
+ I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
Verifying Matrix Equivalences
• Proving matrix equivalences in Coq is tedious

• E.g. 

11
each other out.
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to justify
local rewrites. Proof that an optimization is correct thus relies
on proofs that the circuit equivalences it uses are correct.
Many of our circuit equivalence proofs have a common form,
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denition
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
per Figure 3. Suppose both sides of the equation are well
typed (m  d and n  d and m = n), and consider the case
m  n (the n  m case is similar). We expand appl 1 and
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
term.)
simpli
matrix
In o
gridif
I2m ⊗
provin
We
in the
is mos
alence
apply t
For eq
one us
but sti
4.3 O
Our pr
localiz
rules. T
of gate
other out.
Proving Circuit Equivalences
’s optimizations use circuit equivalences to justify
ewrites. Proof that an optimization is correct thus relies
oofs that the circuit equivalences it uses are correct.
of our circuit equivalence proofs have a common form,
we illustrate by example.
pose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
bitrary n,m and dimension d. Applying our denition
ivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
gure 3. Suppose both sides of the equation are well
(m  d and n  d and m = n), and consider the case
(the n  m case is similar). We expand appl 1 and
2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
m p q
term.) After expressions are in g
simplies them by removing mu
matrix and rewriting simple matr
In our example, after normaliz
gridify, both sides of the equalit
I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m
proving that the two expressions
We use gridify to verify mos
in the optimizations given in Sec
is most eective when equivale
alences used in gate cancellation
apply to patterns of at most ve
For equivalences over larger, non
one used in rotation merging, we
but still rely on our automation f
4.3 Optimization by Propaga
Our propagate-cancel optimizatio
localize a set of gates by repeate
rules. Then we apply a circuit equ
of gates. In  most optimizatio
of code patterns, but one—not pr
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to jus
local rewrites. Proof that an optimization is correct thus re
on proofs that the circuit equivalences it uses are corr
Many of our circuit equivalence proofs have a common fo
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denit
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
per Figure 3. Suppose both sides of the equation are w
typed (m  d and n  d and m = n), and consider the c
m  n (the n  m case is similar). We expand appl 1 a
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
+ I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
ate-of-
e two
gation
ern of
latter
duces
ect of
ram—
cancel
ustify
relies
orrect.
form,
dimensions are appropriate):
● Imn = Im ⊗ In
● A × (B +C) = A × B + A ×C
● (A + B) ×C = A ×C + B ×C
● A ⊗ (B +C) = A ⊗ B + A ⊗C
● (A + B) ⊗C = A ⊗C + B ⊗C
● (A ⊗ B) × (C ⊗ D) = (A ×C) ⊗ (B × D)
The rst rule is applied to facilitate application of the other
rules. (For instance, in the example above, I2n would be re-
placed by I2m ⊗ I2 ⊗ I2p to match the structure of the appl 2
term.) After expressions are in grid normal form, gridify
simplies them by removing multiplication by the identity
matrix and rewriting simple matrix products (e.g. x x = I2).
In our example, after normalization and simplication by
gridify, both sides of the equality in Equation (1) become
I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ x ⊗ I2q ,
proving that the two expressions are equal.
We use gridify to verify most of the equivalences used
in the optimizations given in Sections 4.3 and 4.4. The tactic
Verifying Matrix Equivalences
• Proving matrix equivalences in Coq is tedious

• E.g. 

• Fortunately, this is mostly automated in our development
11
each other out.
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to justify
local rewrites. Proof that an optimization is correct thus relies
on proofs that the circuit equivalences it uses are correct.
Many of our circuit equivalence proofs have a common form,
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denition
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
per Figure 3. Suppose both sides of the equation are well
typed (m  d and n  d and m = n), and consider the case
m  n (the n  m case is similar). We expand appl 1 and
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
term.)
simpli
matrix
In o
gridif
I2m ⊗
provin
We
in the
is mos
alence
apply t
For eq
one us
but sti
4.3 O
Our pr
localiz
rules. T
of gate
other out.
Proving Circuit Equivalences
’s optimizations use circuit equivalences to justify
ewrites. Proof that an optimization is correct thus relies
oofs that the circuit equivalences it uses are correct.
of our circuit equivalence proofs have a common form,
we illustrate by example.
pose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
bitrary n,m and dimension d. Applying our denition
ivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
(1)
gure 3. Suppose both sides of the equation are well
(m  d and n  d and m = n), and consider the case
(the n  m case is similar). We expand appl 1 and
2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
m p q
term.) After expressions are in g
simplies them by removing mu
matrix and rewriting simple matr
In our example, after normaliz
gridify, both sides of the equalit
I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m
proving that the two expressions
We use gridify to verify mos
in the optimizations given in Sec
is most eective when equivale
alences used in gate cancellation
apply to patterns of at most ve
For equivalences over larger, non
one used in rotation merging, we
but still rely on our automation f
4.3 Optimization by Propaga
Our propagate-cancel optimizatio
localize a set of gates by repeate
rules. Then we apply a circuit equ
of gates. In  most optimizatio
of code patterns, but one—not pr
4.2 Proving Circuit Equivalences
All of ’s optimizations use circuit equivalences to jus
local rewrites. Proof that an optimization is correct thus re
on proofs that the circuit equivalences it uses are corr
Many of our circuit equivalence proofs have a common fo
which we illustrate by example.
Suppose we wish to prove the equivalence
X n; CNOT m n ≡ CNOT m n; X n
for arbitrary n,m and dimension d. Applying our denit
of equivalence, this amounts to proving
appl 1(X,n,d) × appl 2(CNOT,m,n,d) =
appl 2(CNOT,m,n,d) × appl 1(X,n,d),
per Figure 3. Suppose both sides of the equation are w
typed (m  d and n  d and m = n), and consider the c
m  n (the n  m case is similar). We expand appl 1 a
appl 2 as follows with p = n −m − 1 and q = d − n − 1:
appl 1(X,n,d) = I2n ⊗ x ⊗ I2q
appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q
+ I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
Experiment
• Evaluated unitary optimizations

• Compared against Qiskit, t ket , PyZX, Nam et al. and
Amy et al.2

• Benchmark of 29 programs from Amy et al., ranging from
45 to 61629 gates and 5 to 192 qubits

• Considered reduction in total gate count and T-gate count
2Amy et al. Polynomial-Time T-Depth Optimization of Clifford+T Circuits Via Matroid Partitioning. 2014.
⟩|
12
Results
• Average gate count reduction

• Average T-count reduction

Amy et al. Nam et al. PyZX VOQC
40.9% 41.0% 42.6% 39.4%
Nam et al. Qiskit t ket VOQC
26.5% 10.7% 11.2% 18.4%
⟩|
13
❓
❓
Is the translation between

industry IRs and SQIR correct?
High-level Language
E.g. QWIRE, Quipper, Q#
Unoptimized IR
E.g. OpenQASM, Quil
Optimized IR
E.g. OpenQASM, Quil
Hardware Instructions
Unoptimized SQIR
Optimized SQIR
VOQC
14
Is the translation between

industry IRs and SQIR correct?
High-level Language
E.g. QWIRE, Quipper, Q#
Unoptimized IR
E.g. OpenQASM, Quil
Optimized IR
E.g. OpenQASM, Quil
Hardware Instructions
Unoptimized SQIR
Optimized SQIR
VOQC
14
We verify translation between

OpenQASM and SQIR
A feature-complete parser for OpenQASM

Translation between unitary fragments of

the two languages

A denotational semantics for unitary OpenQASM

Semantic preservation property of translation
15
Unitary SQIR and OpenQASM

have fairly similar abstract syntax
cute code on real machines [Wille et al. 2019].
observe that at their core, OpenQASM and s are very similar languages but dier
pect. Namely, s assumes a global, indexed register that makes it easy to refer to any
ble to the program with its unique index; while OpenQASM uses abstract identier
o be declared and looked up.
verify correctness of a translation from/to OpenQASM, we must develop a denota
tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid
ional semantics for a subset of the language which we use as a starting point.
Syntax. We employ the following syntax of OpenQASM, following Amy [2019]:
Identier x
Index i
Expression E ::= x | x[i]
Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2
Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2
yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet
l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes
arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library
liberate choice for the purpose of translation as most OpenQASM programs are written
mmon gates dened in the standard library. Other single-qubit gates are similar modul
OpenQASMa
OpenQASM is a larger language

that supports declaring qubit registers

and user-defined gates
SQIR
s is a language for describing quantum programs that
is deeply embedded in the Coq proof assistant. In s, a
qubit is referred to by a natural number that indices into a
global register of quantum bits. Unitary s programs allow
sequencing and unitary gate application to one or two qubits,
drawing from a xed set of gates.
U ∶∶= U1; U2  G q  G q1 q2
G ∶∶= H  CNOT
Each s program is parameterized by a unitary gate set
(from which G is drawn) and the dimension of the global
register (i.e., the number of available qubits).
A unitary programU is well-typed if every gate application
is valid. A gate application is valid if all of its arguments are
in-bounds indices into the global register, and no index is
repeated. This second requirement enforces linearity and
thereby quantum mechanics’ no-cloning theorem.
The semantics of unitary s programs is shown in Fig-
ure 3. If a program is not well-typed, its denotation is the
zero matrix. The advantage of this denition is that it allows
gate is R
gate is R0,
as s pro
swaps two
We say
U1 ≡ U2, if
For verifyi
will often w
(for ∈ R)
that two c
U1 ≅ U2, w
3.2 Add
To describ
s with
The comm
QPL [41])
P1 or P2 de
measurem
Qubits are indices into a global register
16
Unitary SQIR and OpenQASM

have fairly similar abstract syntax
cute code on real machines [Wille et al. 2019].
observe that at their core, OpenQASM and s are very similar languages but dier
pect. Namely, s assumes a global, indexed register that makes it easy to refer to any
ble to the program with its unique index; while OpenQASM uses abstract identier
o be declared and looked up.
verify correctness of a translation from/to OpenQASM, we must develop a denota
tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid
ional semantics for a subset of the language which we use as a starting point.
Syntax. We employ the following syntax of OpenQASM, following Amy [2019]:
Identier x
Index i
Expression E ::= x | x[i]
Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2
Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2
yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet
l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes
arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library
liberate choice for the purpose of translation as most OpenQASM programs are written
mmon gates dened in the standard library. Other single-qubit gates are similar modul
OpenQASMa
OpenQASM is a larger language

that supports declaring qubit registers

and user-defined gates
SQIR
s is a language for describing quantum programs that
is deeply embedded in the Coq proof assistant. In s, a
qubit is referred to by a natural number that indices into a
global register of quantum bits. Unitary s programs allow
sequencing and unitary gate application to one or two qubits,
drawing from a xed set of gates.
U ∶∶= U1; U2  G q  G q1 q2
G ∶∶= H  CNOT
Each s program is parameterized by a unitary gate set
(from which G is drawn) and the dimension of the global
register (i.e., the number of available qubits).
A unitary programU is well-typed if every gate application
is valid. A gate application is valid if all of its arguments are
in-bounds indices into the global register, and no index is
repeated. This second requirement enforces linearity and
thereby quantum mechanics’ no-cloning theorem.
The semantics of unitary s programs is shown in Fig-
ure 3. If a program is not well-typed, its denotation is the
zero matrix. The advantage of this denition is that it allows
gate is R
gate is R0,
as s pro
swaps two
We say
U1 ≡ U2, if
For verifyi
will often w
(for ∈ R)
that two c
U1 ≅ U2, w
3.2 Add
To describ
s with
The comm
QPL [41])
P1 or P2 de
measurem
Qubits are indices into a global register
16
Unitary SQIR and OpenQASM

have fairly similar abstract syntax
cute code on real machines [Wille et al. 2019].
observe that at their core, OpenQASM and s are very similar languages but dier
pect. Namely, s assumes a global, indexed register that makes it easy to refer to any
ble to the program with its unique index; while OpenQASM uses abstract identier
o be declared and looked up.
verify correctness of a translation from/to OpenQASM, we must develop a denota
tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid
ional semantics for a subset of the language which we use as a starting point.
Syntax. We employ the following syntax of OpenQASM, following Amy [2019]:
Identier x
Index i
Expression E ::= x | x[i]
Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2
Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2
yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet
l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes
arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library
liberate choice for the purpose of translation as most OpenQASM programs are written
mmon gates dened in the standard library. Other single-qubit gates are similar modul
OpenQASMa
OpenQASM is a larger language

that supports declaring qubit registers

and user-defined gates
SQIR
s is a language for describing quantum programs that
is deeply embedded in the Coq proof assistant. In s, a
qubit is referred to by a natural number that indices into a
global register of quantum bits. Unitary s programs allow
sequencing and unitary gate application to one or two qubits,
drawing from a xed set of gates.
U ∶∶= U1; U2  G q  G q1 q2
G ∶∶= H  CNOT
Each s program is parameterized by a unitary gate set
(from which G is drawn) and the dimension of the global
register (i.e., the number of available qubits).
A unitary programU is well-typed if every gate application
is valid. A gate application is valid if all of its arguments are
in-bounds indices into the global register, and no index is
repeated. This second requirement enforces linearity and
thereby quantum mechanics’ no-cloning theorem.
The semantics of unitary s programs is shown in Fig-
ure 3. If a program is not well-typed, its denotation is the
zero matrix. The advantage of this denition is that it allows
gate is R
gate is R0,
as s pro
swaps two
We say
U1 ≡ U2, if
For verifyi
will often w
(for ∈ R)
that two c
U1 ≅ U2, w
3.2 Add
To describ
s with
The comm
QPL [41])
P1 or P2 de
measurem
Qubits are indices into a global register
16
Unitary SQIR and OpenQASM

have fairly similar abstract syntax
cute code on real machines [Wille et al. 2019].
observe that at their core, OpenQASM and s are very similar languages but dier
pect. Namely, s assumes a global, indexed register that makes it easy to refer to any
ble to the program with its unique index; while OpenQASM uses abstract identier
o be declared and looked up.
verify correctness of a translation from/to OpenQASM, we must develop a denota
tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid
ional semantics for a subset of the language which we use as a starting point.
Syntax. We employ the following syntax of OpenQASM, following Amy [2019]:
Identier x
Index i
Expression E ::= x | x[i]
Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2
Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2
yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet
l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes
arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library
liberate choice for the purpose of translation as most OpenQASM programs are written
mmon gates dened in the standard library. Other single-qubit gates are similar modul
OpenQASMa
OpenQASM is a larger language

that supports declaring qubit registers

and user-defined gates
SQIR
s is a language for describing quantum programs that
is deeply embedded in the Coq proof assistant. In s, a
qubit is referred to by a natural number that indices into a
global register of quantum bits. Unitary s programs allow
sequencing and unitary gate application to one or two qubits,
drawing from a xed set of gates.
U ∶∶= U1; U2  G q  G q1 q2
G ∶∶= H  CNOT
Each s program is parameterized by a unitary gate set
(from which G is drawn) and the dimension of the global
register (i.e., the number of available qubits).
A unitary programU is well-typed if every gate application
is valid. A gate application is valid if all of its arguments are
in-bounds indices into the global register, and no index is
repeated. This second requirement enforces linearity and
thereby quantum mechanics’ no-cloning theorem.
The semantics of unitary s programs is shown in Fig-
ure 3. If a program is not well-typed, its denotation is the
zero matrix. The advantage of this denition is that it allows
gate is R
gate is R0,
as s pro
swaps two
We say
U1 ≡ U2, if
For verifyi
will often w
(for ∈ R)
that two c
U1 ≅ U2, w
3.2 Add
To describ
s with
The comm
QPL [41])
P1 or P2 de
measurem
Qubits are indices into a global register
16
Only shown a sample gate set

of Hadamard (H) and

controlled NOT (CNOT or CX)
Unitary SQIR and OpenQASM

have fairly similar abstract syntax
aAmy M. Sized Types for Low-Level Quantum Metaprogramming. Reversible Computation. RC 2019.
cute code on real machines [Wille et al. 2019].
observe that at their core, OpenQASM and s are very similar languages but dier
pect. Namely, s assumes a global, indexed register that makes it easy to refer to any
ble to the program with its unique index; while OpenQASM uses abstract identier
o be declared and looked up.
verify correctness of a translation from/to OpenQASM, we must develop a denota
tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid
ional semantics for a subset of the language which we use as a starting point.
Syntax. We employ the following syntax of OpenQASM, following Amy [2019]:
Identier x
Index i
Expression E ::= x | x[i]
Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2
Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2
yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet
l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes
arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library
liberate choice for the purpose of translation as most OpenQASM programs are written
mmon gates dened in the standard library. Other single-qubit gates are similar modul
OpenQASMa
OpenQASM is a larger language

that supports declaring qubit registers

and user-defined gates
SQIR
s is a language for describing quantum programs that
is deeply embedded in the Coq proof assistant. In s, a
qubit is referred to by a natural number that indices into a
global register of quantum bits. Unitary s programs allow
sequencing and unitary gate application to one or two qubits,
drawing from a xed set of gates.
U ∶∶= U1; U2  G q  G q1 q2
G ∶∶= H  CNOT
Each s program is parameterized by a unitary gate set
(from which G is drawn) and the dimension of the global
register (i.e., the number of available qubits).
A unitary programU is well-typed if every gate application
is valid. A gate application is valid if all of its arguments are
in-bounds indices into the global register, and no index is
repeated. This second requirement enforces linearity and
thereby quantum mechanics’ no-cloning theorem.
The semantics of unitary s programs is shown in Fig-
ure 3. If a program is not well-typed, its denotation is the
zero matrix. The advantage of this denition is that it allows
gate is R
gate is R0,
as s pro
swaps two
We say
U1 ≡ U2, if
For verifyi
will often w
(for ∈ R)
that two c
U1 ≅ U2, w
3.2 Add
To describ
s with
The comm
QPL [41])
P1 or P2 de
measurem
Qubits are indices into a global register
16
Only shown a sample gate set

of Hadamard (H) and

controlled NOT (CNOT or CX)
Denotational semantics of SQIR

and OpenQASM correspond
17
SQIR
Dra paper, November 22, 2019, K. Hietala, R. Rand, S. Hung, X. Wu 
nU1; U2od = nU2od × nU1od
nG1 qod =



appl 1(G1, q, d) well-typed
02d otherwise
nG2 q1 q2od =



appl 2(G2, q1, q2, d) well-typed
02d otherwise
Figure 3. Semantics of unitary s programs, assuming a
global register of dimension d. The appl k function maps a
gate name to its corresponding unitary matrix and extends
the intended operation to the given dimension by applying
an identity operation on every other qubit in the system. For
example, appl 1(X, q, d) = I2q ⊗ x ⊗ I2(d−q−1) where x is
the matrix interpretation of the X gate.
3.1 Unitary Core
s is a language for describing quantum programs that
is deeply embedded in the Coq proof assistant. In s, a
qubit is referred to by a natural number that indices into a
global register of quantum bits. Unitary s programs allow
sequencing and unitary gate application to one or two qubits,
drawing from a xed set of gates.
{skip}d ( ) =
{P1; P2}d ( ) = ({P2}d ○ {P1}d )( )
{U }d ( ) = nU od × × nU o†
d
{meas q P1 P2}d ( ) = {P2}d (0q0 × × 0
+ {P1}d (1q1 × × 1
Figure 4. s density matrix semantics, assumin
register of size d.
and the matrix interpretation of the CNOT gate
Section 2.1.
Common single-qubit gates can be dened in
R , , . For example, the identity I is R0,0,0; the Ha
gate is R 2,0, ; the Pauli X gate is R ,0, and th
gate is R0,0, . We can also dene more complex o
as s programs. For example the SWAP operat
swaps two qubits, is a sequence of three CNOT g
We say that two unitary programs are equivale
U1 ≡ U2, if their denotation is the same, i.e., nU1o
For verifying equivalence of quantum programs, ho
will often want something more general since  
(for ∈ R) represent the same physical state. We th
A SQIR unitary program

denotes a unitary matrix2d
× 2d
OpenQASM 3
Value V = Location, l + Loc. Array, (lj, . . . ,lk )
+ Unitary Gate, (x1, . . . ,xn).U
Environment = Identier ! Value
Quantum State | i = 2d -dimension complex vector
Here | i is a vector in a 2m-dimension complex Hilbert space, representing the complete quantum
state available to a program. For a given program, the size of the vector is determined by m =
Õ
ni
where ni are the sizes of each of the declared quantum registers.
Similar to the semantics of s, we need padding functions that are used to determine the
modied quantum state after applying a unitary operation to the given location(s), for example:
apply(H, | i ,l) = (I ⌦l
⌦ H ⌦ I ⌦m l 1
) | i
This manipulation of global quantum state is necessary as quantum computing inherently
involves non-local eects such as entanglement.
We can now specify semantic functions for each of the three syntactic classes:
Expressions need environment 

and return bound values

Unitary statements modify

quantum state

Commands modify both

environment and quantum state
Value V = Location, l + Loc. Array, (lj, . . . ,lk )
+ Unitary Gate, (x1, . . . ,xn).U
Environment = Identier ! Value
Quantum State | i = 2d -dimension complex vector
| i is a vector in a 2m-dimension complex Hilbert space, representing the complete quantum
available to a program. For a given program, the size of the vector is determined by m =
Õ
ni
re ni are the sizes of each of the declared quantum registers.
milar to the semantics of s, we need padding functions that are used to determine the
ied quantum state after applying a unitary operation to the given location(s), for example:
apply(H, | i ,l) = (I ⌦l
⌦ H ⌦ I ⌦m l 1
) | i
his manipulation of global quantum state is necessary as quantum computing inherently
lves non-local eects such as entanglement.
e can now specify semantic functions for each of the three syntactic classes:
(| |)E : E ⇥ ! V
(| |)U : U ⇥ ⇥ | i ! | 0
i
(| |)C : C ⇥ ⇥ | i ! 0
⇥ | 0
i
(| |)E : E ⇥ ! V
(| |)U : U ⇥ ⇥ | i ! | 0i
(| |)C : C ⇥ ⇥ | i ! 0 ⇥ | 0i
xpressions need an environment to return bound values. Unitary statements require an environ-
t and the complete quantum state but only manipulate the quantum state. Finally, commands
Details elided
Semantic preservation properties

are maintained during translation
18
inally, we would also like to see that if we convert from one language to another and back, we
ain the identity function:
8x 2 L(s), (f (x)) = x (3)
is very easy to use our translation to obtain the original program written in s and hence the
mposition of and f is equivalent to identity function. But a similar statement for translating
enQASM to s and back does not hold. This is because of the lack of identiers in s. Our
Further, converting from SQIR to OpenQASM and back

recovers the original program.
For all valid programs in SQIR of dimension ,

their denotation is equivalent to

the denotation of their translation, and vice versa.
dwant to show that the translations from s to OpenQASM (which we will call f ) and
ASM to s ( ) are semantics preserving:
8x 2 L(s), nxod = (|f (x)|) (1)
8 2 L(OpenQASM), (| |) = n ( )od (2)
f : L(s) ! L(OpenQASM) (3)
: L(OpenQASM) ! L(s) (4)
of these properties are easy to prove using structural induction on the abstract syntax. For
reate a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and
ngle mapping for that in the environment . For (2), we also need to prove the correctness
unction that maps an OpenQASM register and its index to a s global index.
M to s ( ) are semantics preserving:
8x 2 L(s), nxod = (|f (x)|) (1)
8 2 L(OpenQASM), (| |) = n ( )od (2)
f : L(s) ! L(OpenQASM) (3)
: L(OpenQASM) ! L(s) (4)
hese properties are easy to prove using structural induction on the abstract syntax. For
te a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and
e mapping for that in the environment . For (2), we also need to prove the correctness
tion that maps an OpenQASM register and its index to a s global index.
we would also like to see that if we convert from one language to another and back, we
identity function:
8x 2 L(s), (f (x)) = x (5)
easy to use our translation to obtain the original program written in s and hence the
n of and f is equivalent to identity function. But a similar statement for translating
M to s and back does not hold. This is because of the lack of identiers in s. Our
to s is necessarily forgetful and hence, when we translate the program back to
M, we lose some of the structure of the original program.
ocamllex (the OCaml lexer generator) and the Menhir parser generator [Pottier and
as 2019] to write a feature-complete parser for OpenQASM. We then translate the
Semantic preservation properties

are maintained during translation
18
inally, we would also like to see that if we convert from one language to another and back, we
ain the identity function:
8x 2 L(s), (f (x)) = x (3)
is very easy to use our translation to obtain the original program written in s and hence the
mposition of and f is equivalent to identity function. But a similar statement for translating
enQASM to s and back does not hold. This is because of the lack of identiers in s. Our
Further, converting from SQIR to OpenQASM and back

recovers the original program.
But the reverse direction does not hold.
For all valid programs in SQIR of dimension ,

their denotation is equivalent to

the denotation of their translation, and vice versa.
dwant to show that the translations from s to OpenQASM (which we will call f ) and
ASM to s ( ) are semantics preserving:
8x 2 L(s), nxod = (|f (x)|) (1)
8 2 L(OpenQASM), (| |) = n ( )od (2)
f : L(s) ! L(OpenQASM) (3)
: L(OpenQASM) ! L(s) (4)
of these properties are easy to prove using structural induction on the abstract syntax. For
reate a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and
ngle mapping for that in the environment . For (2), we also need to prove the correctness
unction that maps an OpenQASM register and its index to a s global index.
M to s ( ) are semantics preserving:
8x 2 L(s), nxod = (|f (x)|) (1)
8 2 L(OpenQASM), (| |) = n ( )od (2)
f : L(s) ! L(OpenQASM) (3)
: L(OpenQASM) ! L(s) (4)
hese properties are easy to prove using structural induction on the abstract syntax. For
te a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and
e mapping for that in the environment . For (2), we also need to prove the correctness
tion that maps an OpenQASM register and its index to a s global index.
we would also like to see that if we convert from one language to another and back, we
identity function:
8x 2 L(s), (f (x)) = x (5)
easy to use our translation to obtain the original program written in s and hence the
n of and f is equivalent to identity function. But a similar statement for translating
M to s and back does not hold. This is because of the lack of identiers in s. Our
to s is necessarily forgetful and hence, when we translate the program back to
M, we lose some of the structure of the original program.
ocamllex (the OCaml lexer generator) and the Menhir parser generator [Pottier and
as 2019] to write a feature-complete parser for OpenQASM. We then translate the
OpenQASM parser written in

OCaml programming language

19
Conforms to OpenQASM specb

Uses OCamllex and Menhir parser generator

Available now as an OCaml library on

OPAM package repository:

opam install openQASM
bCross et al. Open Quantum Assembly Language. arXiv:1707.03429
Ongoing and Future Work
• We’re always looking for more transformations to verify

• Optimization from other compilers (incl. error aware)

• More sophisticated circuit mapping

• Compilation of classical circuits

• Performance improvements; evaluations on larger sets of
benchmarks

• Larger verified toolchain

• Translation and verification of non-unitary fragments

• Validate our OpenQASM parser using Menhir’s Coq backend

• Verify translation from high-level languages such as QWIRE
20
Conclusions
• We have developed a compiler VOQC and an IR SQIR, both
implemented and verified in Coq

• Performance is comparable to state-of-the-art compilers

• We have also taken steps to ease interoperability with industry
toolchains with translation from and to OpenQASM

• Lots of ongoing work, let us know if you’re interested!

• Code:

•github.com/inQWIRE/SQIR
•github.com/inQWIRE/openqasm-parser
• Draft of VOQC paper: cs.umd.edu/~mwh/papers/voqc-draft.pdf
21

More Related Content

What's hot

Task Constrained Motion Planning for Snake Robot
Task Constrained Motion Planning for Snake RobotTask Constrained Motion Planning for Snake Robot
Task Constrained Motion Planning for Snake RobotGiovanni Murru
 
Joint blind calibration and time-delay estimation for multiband ranging
Joint blind calibration and time-delay estimation for multiband rangingJoint blind calibration and time-delay estimation for multiband ranging
Joint blind calibration and time-delay estimation for multiband rangingTarik Kazaz
 
Controllers for 3R Robot
Controllers for 3R RobotControllers for 3R Robot
Controllers for 3R RobotGiovanni Murru
 
Process Algebras and Petri Nets are Discrete Dynamical Systems
Process Algebras and Petri Nets are Discrete Dynamical SystemsProcess Algebras and Petri Nets are Discrete Dynamical Systems
Process Algebras and Petri Nets are Discrete Dynamical SystemsFacultad de Informática UCM
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landauangely alcendra
 
D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...
D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...
D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...SEENET-MTP
 
N. Bilic - Supersymmetric Dark Energy
N. Bilic - Supersymmetric Dark EnergyN. Bilic - Supersymmetric Dark Energy
N. Bilic - Supersymmetric Dark EnergySEENET-MTP
 
S. Duplij, Constraintless approach to singular theories, new brackets and mul...
S. Duplij, Constraintless approach to singular theories, new brackets and mul...S. Duplij, Constraintless approach to singular theories, new brackets and mul...
S. Duplij, Constraintless approach to singular theories, new brackets and mul...Steven Duplij (Stepan Douplii)
 
Achieving Spatial Adaptivity while Searching for Approximate Nearest Neighbors
Achieving Spatial Adaptivity while Searching for Approximate Nearest NeighborsAchieving Spatial Adaptivity while Searching for Approximate Nearest Neighbors
Achieving Spatial Adaptivity while Searching for Approximate Nearest NeighborsDon Sheehy
 
simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonkanikkk
 

What's hot (20)

Task Constrained Motion Planning for Snake Robot
Task Constrained Motion Planning for Snake RobotTask Constrained Motion Planning for Snake Robot
Task Constrained Motion Planning for Snake Robot
 
Joint blind calibration and time-delay estimation for multiband ranging
Joint blind calibration and time-delay estimation for multiband rangingJoint blind calibration and time-delay estimation for multiband ranging
Joint blind calibration and time-delay estimation for multiband ranging
 
Controllers for 3R Robot
Controllers for 3R RobotControllers for 3R Robot
Controllers for 3R Robot
 
Kalman_Filter_Report
Kalman_Filter_ReportKalman_Filter_Report
Kalman_Filter_Report
 
Nfa to-dfa
Nfa to-dfaNfa to-dfa
Nfa to-dfa
 
Process Algebras and Petri Nets are Discrete Dynamical Systems
Process Algebras and Petri Nets are Discrete Dynamical SystemsProcess Algebras and Petri Nets are Discrete Dynamical Systems
Process Algebras and Petri Nets are Discrete Dynamical Systems
 
Metodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang LandauMetodo Monte Carlo -Wang Landau
Metodo Monte Carlo -Wang Landau
 
Queueing theory
Queueing theoryQueueing theory
Queueing theory
 
Graph Kernelpdf
Graph KernelpdfGraph Kernelpdf
Graph Kernelpdf
 
Dimen
DimenDimen
Dimen
 
D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...
D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...
D. Vulcanov: Symbolic Computation Methods in Cosmology and General Relativity...
 
N. Bilic - Supersymmetric Dark Energy
N. Bilic - Supersymmetric Dark EnergyN. Bilic - Supersymmetric Dark Energy
N. Bilic - Supersymmetric Dark Energy
 
02 newton-raphson
02 newton-raphson02 newton-raphson
02 newton-raphson
 
S. Duplij, Constraintless approach to singular theories, new brackets and mul...
S. Duplij, Constraintless approach to singular theories, new brackets and mul...S. Duplij, Constraintless approach to singular theories, new brackets and mul...
S. Duplij, Constraintless approach to singular theories, new brackets and mul...
 
Achieving Spatial Adaptivity while Searching for Approximate Nearest Neighbors
Achieving Spatial Adaptivity while Searching for Approximate Nearest NeighborsAchieving Spatial Adaptivity while Searching for Approximate Nearest Neighbors
Achieving Spatial Adaptivity while Searching for Approximate Nearest Neighbors
 
Finite automata
Finite automataFinite automata
Finite automata
 
simple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilonsimple problem to convert NFA with epsilon to without epsilon
simple problem to convert NFA with epsilon to without epsilon
 
Finite automata
Finite automataFinite automata
Finite automata
 
Knn solution
Knn solutionKnn solution
Knn solution
 
Ece4510 notes08
Ece4510 notes08Ece4510 notes08
Ece4510 notes08
 

Similar to Merged Talk: A Verified Optimizer for Quantum Circuits & Verified Translation Between Low-Level Quantum Languages

Modeling biased tracers at the field level
Modeling biased tracers at the field levelModeling biased tracers at the field level
Modeling biased tracers at the field levelMarcel Schmittfull
 
p-adic integration and elliptic curves over number fields
p-adic integration and elliptic curves over number fieldsp-adic integration and elliptic curves over number fields
p-adic integration and elliptic curves over number fieldsmmasdeu
 
Non-archimedean construction of elliptic curves and abelian surfaces
Non-archimedean construction of elliptic curves and abelian surfacesNon-archimedean construction of elliptic curves and abelian surfaces
Non-archimedean construction of elliptic curves and abelian surfacesmmasdeu
 
Mit2 092 f09_lec23
Mit2 092 f09_lec23Mit2 092 f09_lec23
Mit2 092 f09_lec23Rahman Hakim
 
Ph 101-9 QUANTUM MACHANICS
Ph 101-9 QUANTUM MACHANICSPh 101-9 QUANTUM MACHANICS
Ph 101-9 QUANTUM MACHANICSChandan Singh
 
Detection of unknown signal
Detection of unknown signalDetection of unknown signal
Detection of unknown signalsumitf1
 
A Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann HypothesisA Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann HypothesisCharaf Ech-Chatbi
 
A Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann HypothesisA Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann HypothesisCharaf Ech-Chatbi
 
Nonlinear stochastic programming by Monte-Carlo estimators
Nonlinear stochastic programming by Monte-Carlo estimatorsNonlinear stochastic programming by Monte-Carlo estimators
Nonlinear stochastic programming by Monte-Carlo estimatorsSSA KPI
 
2014 04 22 wits presentation oqw
2014 04 22 wits presentation oqw2014 04 22 wits presentation oqw
2014 04 22 wits presentation oqwRene Kotze
 
lecture 10 formal methods in software enginnering.pptx
lecture 10 formal methods in software enginnering.pptxlecture 10 formal methods in software enginnering.pptx
lecture 10 formal methods in software enginnering.pptxSohaibAlviWebster
 
2 cooper
2 cooper2 cooper
2 cooperYandex
 
Probabilistic Control of Switched Linear Systems with Chance Constraints
Probabilistic Control of Switched Linear Systems with Chance ConstraintsProbabilistic Control of Switched Linear Systems with Chance Constraints
Probabilistic Control of Switched Linear Systems with Chance ConstraintsLeo Asselborn
 
Unbiased MCMC with couplings
Unbiased MCMC with couplingsUnbiased MCMC with couplings
Unbiased MCMC with couplingsPierre Jacob
 
Proceedings A Method For Finding Complete Observables In Classical Mechanics
Proceedings A Method For Finding Complete Observables In Classical MechanicsProceedings A Method For Finding Complete Observables In Classical Mechanics
Proceedings A Method For Finding Complete Observables In Classical Mechanicsvcuesta
 

Similar to Merged Talk: A Verified Optimizer for Quantum Circuits & Verified Translation Between Low-Level Quantum Languages (20)

PCA on graph/network
PCA on graph/networkPCA on graph/network
PCA on graph/network
 
Quantum chaos of generic systems - Marko Robnik
Quantum chaos of generic systems - Marko RobnikQuantum chaos of generic systems - Marko Robnik
Quantum chaos of generic systems - Marko Robnik
 
Modeling biased tracers at the field level
Modeling biased tracers at the field levelModeling biased tracers at the field level
Modeling biased tracers at the field level
 
p-adic integration and elliptic curves over number fields
p-adic integration and elliptic curves over number fieldsp-adic integration and elliptic curves over number fields
p-adic integration and elliptic curves over number fields
 
QMC: Transition Workshop - Probabilistic Integrators for Deterministic Differ...
QMC: Transition Workshop - Probabilistic Integrators for Deterministic Differ...QMC: Transition Workshop - Probabilistic Integrators for Deterministic Differ...
QMC: Transition Workshop - Probabilistic Integrators for Deterministic Differ...
 
Non-archimedean construction of elliptic curves and abelian surfaces
Non-archimedean construction of elliptic curves and abelian surfacesNon-archimedean construction of elliptic curves and abelian surfaces
Non-archimedean construction of elliptic curves and abelian surfaces
 
Mit2 092 f09_lec23
Mit2 092 f09_lec23Mit2 092 f09_lec23
Mit2 092 f09_lec23
 
Basic concepts and how to measure price volatility
Basic concepts and how to measure price volatility Basic concepts and how to measure price volatility
Basic concepts and how to measure price volatility
 
Ph 101-9 QUANTUM MACHANICS
Ph 101-9 QUANTUM MACHANICSPh 101-9 QUANTUM MACHANICS
Ph 101-9 QUANTUM MACHANICS
 
Detection of unknown signal
Detection of unknown signalDetection of unknown signal
Detection of unknown signal
 
A Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann HypothesisA Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann Hypothesis
 
A Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann HypothesisA Proof of the Generalized Riemann Hypothesis
A Proof of the Generalized Riemann Hypothesis
 
Nonlinear stochastic programming by Monte-Carlo estimators
Nonlinear stochastic programming by Monte-Carlo estimatorsNonlinear stochastic programming by Monte-Carlo estimators
Nonlinear stochastic programming by Monte-Carlo estimators
 
2014 04 22 wits presentation oqw
2014 04 22 wits presentation oqw2014 04 22 wits presentation oqw
2014 04 22 wits presentation oqw
 
Kaifeng_final version1
Kaifeng_final version1Kaifeng_final version1
Kaifeng_final version1
 
lecture 10 formal methods in software enginnering.pptx
lecture 10 formal methods in software enginnering.pptxlecture 10 formal methods in software enginnering.pptx
lecture 10 formal methods in software enginnering.pptx
 
2 cooper
2 cooper2 cooper
2 cooper
 
Probabilistic Control of Switched Linear Systems with Chance Constraints
Probabilistic Control of Switched Linear Systems with Chance ConstraintsProbabilistic Control of Switched Linear Systems with Chance Constraints
Probabilistic Control of Switched Linear Systems with Chance Constraints
 
Unbiased MCMC with couplings
Unbiased MCMC with couplingsUnbiased MCMC with couplings
Unbiased MCMC with couplings
 
Proceedings A Method For Finding Complete Observables In Classical Mechanics
Proceedings A Method For Finding Complete Observables In Classical MechanicsProceedings A Method For Finding Complete Observables In Classical Mechanics
Proceedings A Method For Finding Complete Observables In Classical Mechanics
 

Recently uploaded

Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptxanandsmhk
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)DHURKADEVIBASKAR
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Patrick Diehl
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...jana861314
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...anilsa9823
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCEPRINCE C P
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxAleenaTreesaSaji
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoSérgio Sacani
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzohaibmir069
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxAleenaTreesaSaji
 
Module 4: Mendelian Genetics and Punnett Square
Module 4:  Mendelian Genetics and Punnett SquareModule 4:  Mendelian Genetics and Punnett Square
Module 4: Mendelian Genetics and Punnett SquareIsiahStephanRadaza
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tantaDashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tantaPraksha3
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsAArockiyaNisha
 

Recently uploaded (20)

Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptxUnlocking  the Potential: Deep dive into ocean of Ceramic Magnets.pptx
Unlocking the Potential: Deep dive into ocean of Ceramic Magnets.pptx
 
Engler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomyEngler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomy
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)Recombinant DNA technology( Transgenic plant and animal)
Recombinant DNA technology( Transgenic plant and animal)
 
Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?Is RISC-V ready for HPC workload? Maybe?
Is RISC-V ready for HPC workload? Maybe?
 
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
Traditional Agroforestry System in India- Shifting Cultivation, Taungya, Home...
 
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
Lucknow 💋 Russian Call Girls Lucknow Finest Escorts Service 8923113531 Availa...
 
The Philosophy of Science
The Philosophy of ScienceThe Philosophy of Science
The Philosophy of Science
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCESTERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptx
 
Isotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on IoIsotopic evidence of long-lived volcanism on Io
Isotopic evidence of long-lived volcanism on Io
 
zoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistanzoogeography of pakistan.pptx fauna of Pakistan
zoogeography of pakistan.pptx fauna of Pakistan
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
GFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptxGFP in rDNA Technology (Biotechnology).pptx
GFP in rDNA Technology (Biotechnology).pptx
 
Module 4: Mendelian Genetics and Punnett Square
Module 4:  Mendelian Genetics and Punnett SquareModule 4:  Mendelian Genetics and Punnett Square
Module 4: Mendelian Genetics and Punnett Square
 
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Munirka Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tantaDashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
Dashanga agada a formulation of Agada tantra dealt in 3 Rd year bams agada tanta
 
Natural Polymer Based Nanomaterials
Natural Polymer Based NanomaterialsNatural Polymer Based Nanomaterials
Natural Polymer Based Nanomaterials
 

Merged Talk: A Verified Optimizer for Quantum Circuits & Verified Translation Between Low-Level Quantum Languages

  • 1. A Verified Optimizer for Quantum Circuits Kesha Hietala, Robert Rand, Shih-Han Hung,
 Xiaodi Wu, Michael Hicks Verified translation between low-level quantum languages Kartik Singhal, Robert Rand, Michael Hicks & 1 PLanQC 2020
  • 2. Verified Compiler Stack • End goal: verified compiler stack for quantum programs High-level Language E.g. QWIRE, Quipper, Q# Unoptimized IR E.g. OpenQASM, Quil Optimized IR E.g. OpenQASM, Quil Hardware Instructions 2
  • 3. Verified Compiler Stack • End goal: verified compiler stack for quantum programs High-level Language E.g. QWIRE, Quipper, Q# Unoptimized IR E.g. OpenQASM, Quil Optimized IR E.g. OpenQASM, Quil Hardware Instructions 2 Optimization Circuit synthesis Circuit mapping …
  • 4. Verified Compiler Stack • End goal: verified compiler stack for quantum programs High-level Language E.g. QWIRE, Quipper, Q# Unoptimized IR E.g. OpenQASM, Quil Optimized IR E.g. OpenQASM, Quil Hardware Instructions 2 Optimization Circuit synthesis Circuit mapping … Means that we’ve formally verified that the transformation is semantics-preserving
  • 5. Verified Compiler Stack • We present VOQC, our Verified Optimizer for Quantum Circuits, which is built on top of SQIR, our Small Quantum Intermediate Representation • Implemented in 8000 lines of Coq code, with 1500 for core SQIR and the rest for program transformations • 400 lines of standalone OCaml code for parsing and translating OpenQASM • We extract VOQC to OCaml and compile it to a binary, so using VOQC doesn’t require knowledge of Coq or OCaml 3
  • 6. Verified Compiler Stack • End goal: verified compiler stack for quantum programs High-level Language E.g. QWIRE, Quipper, Q# Unoptimized IR E.g. OpenQASM, Quil Optimized IR E.g. OpenQASM, Quil Hardware Instructions 4 Unoptimized SQIR Optimized SQIR VOQC
  • 7. SQIR • Syntax • Semantics assumes a global register of size d • A unitary program corresponds to a unitary matrix of size • A non-unitary program corresponds to a function between density matrices of size 2d × 2d 2d × 2d 5 pro- s uni- which s that , a nto a allow ubits, te set lobal ation ts are dex is will often want something more general since and ei (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ... ∀P, nT(P)o = nPo
  • 8. SQIR • Syntax • Semantics assumes a global register of size d Unitary semantics Non-unitary semantics 6 pro- s uni- which s that , a nto a allow ubits, te set lobal ation ts are dex is will often want something more general since and ei (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ... ∀P, nT(P)o = nPo Dra paper, November 22, 2019, K. Hietala, R. Rand, S. Hung, X. Wu M nU1; U2od = nU2od × nU1od nG1 qod = appl 1(G1, q, d) well-typed 02d otherwise nG2 q1 q2od = appl 2(G2, q1, q2, d) well-typed 02d otherwise Figure 3. Semantics of unitary s programs, assuming a controlled-not gate. We refer to this gate set as the It is the same as the underlying set used by OpenQA and is universal, meaning that it can approximate any operation to within arbitrary error. The matrix interp of the single-qubit R , , gate is cos( 2) −ei sin( 2) ei sin( 2) ei( + ) cos( 2) and the matrix interpretation of the CNOT gate is g Section 2.1. A Verified Optimizer for antum Circuits {skip}d ( ) = {P1; P2}d ( ) = ({P2}d ○ {P1}d )( ) {U }d ( ) = nU od × × nU o† d {meas q P1 P2}d ( ) = {P2}d (0q0 × × 0q0) + {P1}d (1q1 × × 1q1) Figure 4. s density matrix semantics, assuming a globa
  • 9. VOQC Transformations • Unitary optimizations - inspired by Nam et al.1 • Gate propagation and cancellation • Rotation merging • Non-unitary optimizations • Classical state propagation • Removing z-rotations before measurement • Circuit mapping • Naive mapping for arbitrary connected graph 1Nam et al. Automated Optimization of Large Quantum Circuits with Continuous Parameters. 2018. 7
  • 10. Example: X/Z Propagation • Simplified code: 8 er 22, 2019, K. Hietala, R. Rand, S. Hung, X H ● H X → H Z ● H X → H ● Z H X → H ● H X X → H ● H e of not propagation. In the rst step the leftmost X gate propagates through the le he second step the Z gate propagates through the control of the CNOT gate. In the th he rightmost H gate and becomes an X gate. In the nal step the two X gates cancel. H ≡ ● H H Rz 4(k) ● k′) ≡ ● ● Rz 4(k′) Rz 4(k) Whereas evaluation of the right-hand cir x1,x2 → x1,x1 ⊕ x2 → x2,x1 ⊕ x2 → ei((k+k′ ) 4)x2 x2,x ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and e (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 11. Example: X/Z Propagation • Simplified code: 8 A A er 22, 2019, K. Hietala, R. Rand, S. Hung, X H ● H X → H Z ● H X → H ● Z H X → H ● H X X → H ● H e of not propagation. In the rst step the leftmost X gate propagates through the le he second step the Z gate propagates through the control of the CNOT gate. In the th he rightmost H gate and becomes an X gate. In the nal step the two X gates cancel. H ≡ ● H H Rz 4(k) ● k′) ≡ ● ● Rz 4(k′) Rz 4(k) Whereas evaluation of the right-hand cir x1,x2 → x1,x1 ⊕ x2 → x2,x1 ⊕ x2 → ei((k+k′ ) 4)x2 x2,x ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and e (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 12. Example: X/Z Propagation • Simplified code: 8 B B er 22, 2019, K. Hietala, R. Rand, S. Hung, X H ● H X → H Z ● H X → H ● Z H X → H ● H X X → H ● H e of not propagation. In the rst step the leftmost X gate propagates through the le he second step the Z gate propagates through the control of the CNOT gate. In the th he rightmost H gate and becomes an X gate. In the nal step the two X gates cancel. H ≡ ● H H Rz 4(k) ● k′) ≡ ● ● Rz 4(k′) Rz 4(k) Whereas evaluation of the right-hand cir x1,x2 → x1,x1 ⊕ x2 → x2,x1 ⊕ x2 → ei((k+k′ ) 4)x2 x2,x ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and e (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 13. Proof Overview • For a transformation T, we want to prove that (up to a global phase) • For complex optimizations, rather than proving this equality directly we may prove that and have the same output on every basis state • For circuit mapping we also prove that for every , respects the provided connectivity constraints • Proofs proceed by induction on → [X q] t → t t → H q ; propagate_Z q t : t → Rz† q ; propagate_X q t ∀P, nT(P)o = nPo mand meas q P1 P2 (inspired by a similar con- PL [43]) measures the qubit q and either performs or P2 depending on the result. We dene non- measurement and resetting a qubit to 0 in terms g measurement: measure q = meas q skip skip reset q = meas q (X q) skip denes the semantics of non-unitary programs density matrices, following the approach of sev- T(P) P P T(P) P 9
  • 14. Example: X/Z Propagation • We will want to prove that for any instruction list lst, (propagate_X q lst) has the same denotation as (X q ; lst) • propagate_X q lst X q ; lst • Proof proceeds by induction on lst ≡ 10 ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and ei (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 15. Example: X/Z Propagation • We will want to prove that for any instruction list lst, (propagate_X q lst) has the same denotation as (X q ; lst) • propagate_X q lst X q ; lst • Proof proceeds by induction on lst ≡ propagate_X q [ ] [ X q ] X q ; [ ]→ ≡ 10 ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and ei (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 16. Example: X/Z Propagation • We will want to prove that for any instruction list lst, (propagate_X q lst) has the same denotation as (X q ; lst) • propagate_X q lst X q ; lst • Proof proceeds by induction on lst ≡ propagate_X q (X q :: t) t X q ; X q ; t→ ≡ 10 ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and ei (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 17. Example: X/Z Propagation • We will want to prove that for any instruction list lst, (propagate_X q lst) has the same denotation as (X q ; lst) • propagate_X q lst X q ; lst • Proof proceeds by induction on lst ≡ propagate_X (Rz q :: t) Rz† q ; propagate_X q t Rz† q ; (X q ; t) X q ; Rz q ; t → ≡ ≡ 10 ro- ni- ch hat , a o a ow its, set bal on will often want something more general since and ei (for ∈ R) represent the same physical state. We therefore say that two circuits are equivalent up to a global phase, written U1 ≅ U2, when there exists a such that nU1od = ei nU2od . 3.2 Adding Measurement To describe general quantum programs P, we extend unitary s with a branching measurement operation. U ∶= U1; U2 G q G q1 q2 P ∶= skip P1; P2 U meas q P1 P2 let propagate_X q lst = match lst with | [] → [X q] | X q :: t → t | H q :: t → H q ; propagate_Z q t | Rz q :: t → Rz† q ; propagate_X q t ...
  • 18. Verifying Matrix Equivalences • Proving matrix equivalences in Coq is tedious • E.g. 11 each other out. 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to justify local rewrites. Proof that an optimization is correct thus relies on proofs that the circuit equivalences it uses are correct. Many of our circuit equivalence proofs have a common form, which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denition of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) per Figure 3. Suppose both sides of the equation are well typed (m d and n d and m = n), and consider the case m n (the n m case is similar). We expand appl 1 and appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q term.) simpli matrix In o gridif I2m ⊗ provin We in the is mos alence apply t For eq one us but sti 4.3 O Our pr localiz rules. T of gate other out. Proving Circuit Equivalences ’s optimizations use circuit equivalences to justify ewrites. Proof that an optimization is correct thus relies oofs that the circuit equivalences it uses are correct. of our circuit equivalence proofs have a common form, we illustrate by example. pose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n bitrary n,m and dimension d. Applying our denition ivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) gure 3. Suppose both sides of the equation are well (m d and n d and m = n), and consider the case (the n m case is similar). We expand appl 1 and 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q m p q term.) After expressions are in g simplies them by removing mu matrix and rewriting simple matr In our example, after normaliz gridify, both sides of the equalit I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m proving that the two expressions We use gridify to verify mos in the optimizations given in Sec is most eective when equivale alences used in gate cancellation apply to patterns of at most ve For equivalences over larger, non one used in rotation merging, we but still rely on our automation f 4.3 Optimization by Propaga Our propagate-cancel optimizatio localize a set of gates by repeate rules. Then we apply a circuit equ of gates. In most optimizatio of code patterns, but one—not pr 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to jus local rewrites. Proof that an optimization is correct thus re on proofs that the circuit equivalences it uses are corr Many of our circuit equivalence proofs have a common fo which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denit of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), per Figure 3. Suppose both sides of the equation are w typed (m d and n d and m = n), and consider the c m n (the n m case is similar). We expand appl 1 a appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
  • 19. Verifying Matrix Equivalences • Proving matrix equivalences in Coq is tedious • E.g. 11 each other out. 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to justify local rewrites. Proof that an optimization is correct thus relies on proofs that the circuit equivalences it uses are correct. Many of our circuit equivalence proofs have a common form, which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denition of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) per Figure 3. Suppose both sides of the equation are well typed (m d and n d and m = n), and consider the case m n (the n m case is similar). We expand appl 1 and appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q term.) simpli matrix In o gridif I2m ⊗ provin We in the is mos alence apply t For eq one us but sti 4.3 O Our pr localiz rules. T of gate other out. Proving Circuit Equivalences ’s optimizations use circuit equivalences to justify ewrites. Proof that an optimization is correct thus relies oofs that the circuit equivalences it uses are correct. of our circuit equivalence proofs have a common form, we illustrate by example. pose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n bitrary n,m and dimension d. Applying our denition ivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) gure 3. Suppose both sides of the equation are well (m d and n d and m = n), and consider the case (the n m case is similar). We expand appl 1 and 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q m p q term.) After expressions are in g simplies them by removing mu matrix and rewriting simple matr In our example, after normaliz gridify, both sides of the equalit I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m proving that the two expressions We use gridify to verify mos in the optimizations given in Sec is most eective when equivale alences used in gate cancellation apply to patterns of at most ve For equivalences over larger, non one used in rotation merging, we but still rely on our automation f 4.3 Optimization by Propaga Our propagate-cancel optimizatio localize a set of gates by repeate rules. Then we apply a circuit equ of gates. In most optimizatio of code patterns, but one—not pr 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to jus local rewrites. Proof that an optimization is correct thus re on proofs that the circuit equivalences it uses are corr Many of our circuit equivalence proofs have a common fo which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denit of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), per Figure 3. Suppose both sides of the equation are w typed (m d and n d and m = n), and consider the c m n (the n m case is similar). We expand appl 1 a appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q local rewrites. Proof that an optimization is correct thus relies on proofs that the circuit equivalences it uses are correct. Many of our circuit equivalence proofs have a common form, which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denition of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) per Figure 3. Suppose both sides of the equation are well typed (m d and n d and m = n), and consider the case m n (the n m case is similar). We expand appl 1 and appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q gridify, both sides of th I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ proving that the two ex We use gridify to ve in the optimizations give is most eective when alences used in gate ca apply to patterns of at m For equivalences over la one used in rotation mer but still rely on our auto 4.3 Optimization by Our propagate-cancel op localize a set of gates by rules. Then we apply a c of gates. In most op of code patterns, but on we discuss it rst. 6 Many of our circuit equivalence proofs have a common form which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denitio of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), ( per Figure 3. Suppose both sides of the equation are we typed (m d and n d and m = n), and consider the cas m n (the n m case is similar). We expand appl 1 an appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
  • 20. Verifying Matrix Equivalences • Proving matrix equivalences in Coq is tedious • E.g. 11 each other out. 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to justify local rewrites. Proof that an optimization is correct thus relies on proofs that the circuit equivalences it uses are correct. Many of our circuit equivalence proofs have a common form, which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denition of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) per Figure 3. Suppose both sides of the equation are well typed (m d and n d and m = n), and consider the case m n (the n m case is similar). We expand appl 1 and appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q term.) simpli matrix In o gridif I2m ⊗ provin We in the is mos alence apply t For eq one us but sti 4.3 O Our pr localiz rules. T of gate other out. Proving Circuit Equivalences ’s optimizations use circuit equivalences to justify ewrites. Proof that an optimization is correct thus relies oofs that the circuit equivalences it uses are correct. of our circuit equivalence proofs have a common form, we illustrate by example. pose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n bitrary n,m and dimension d. Applying our denition ivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) gure 3. Suppose both sides of the equation are well (m d and n d and m = n), and consider the case (the n m case is similar). We expand appl 1 and 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q m p q term.) After expressions are in g simplies them by removing mu matrix and rewriting simple matr In our example, after normaliz gridify, both sides of the equalit I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m proving that the two expressions We use gridify to verify mos in the optimizations given in Sec is most eective when equivale alences used in gate cancellation apply to patterns of at most ve For equivalences over larger, non one used in rotation merging, we but still rely on our automation f 4.3 Optimization by Propaga Our propagate-cancel optimizatio localize a set of gates by repeate rules. Then we apply a circuit equ of gates. In most optimizatio of code patterns, but one—not pr 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to jus local rewrites. Proof that an optimization is correct thus re on proofs that the circuit equivalences it uses are corr Many of our circuit equivalence proofs have a common fo which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denit of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), per Figure 3. Suppose both sides of the equation are w typed (m d and n d and m = n), and consider the c m n (the n m case is similar). We expand appl 1 a appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q ate-of- e two gation ern of latter duces ect of ram— cancel ustify relies orrect. form, dimensions are appropriate): ● Imn = Im ⊗ In ● A × (B +C) = A × B + A ×C ● (A + B) ×C = A ×C + B ×C ● A ⊗ (B +C) = A ⊗ B + A ⊗C ● (A + B) ⊗C = A ⊗C + B ⊗C ● (A ⊗ B) × (C ⊗ D) = (A ×C) ⊗ (B × D) The rst rule is applied to facilitate application of the other rules. (For instance, in the example above, I2n would be re- placed by I2m ⊗ I2 ⊗ I2p to match the structure of the appl 2 term.) After expressions are in grid normal form, gridify simplies them by removing multiplication by the identity matrix and rewriting simple matrix products (e.g. x x = I2). In our example, after normalization and simplication by gridify, both sides of the equality in Equation (1) become I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ x ⊗ I2q , proving that the two expressions are equal. We use gridify to verify most of the equivalences used in the optimizations given in Sections 4.3 and 4.4. The tactic
  • 21. Verifying Matrix Equivalences • Proving matrix equivalences in Coq is tedious • E.g. • Fortunately, this is mostly automated in our development 11 each other out. 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to justify local rewrites. Proof that an optimization is correct thus relies on proofs that the circuit equivalences it uses are correct. Many of our circuit equivalence proofs have a common form, which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denition of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) per Figure 3. Suppose both sides of the equation are well typed (m d and n d and m = n), and consider the case m n (the n m case is similar). We expand appl 1 and appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q term.) simpli matrix In o gridif I2m ⊗ provin We in the is mos alence apply t For eq one us but sti 4.3 O Our pr localiz rules. T of gate other out. Proving Circuit Equivalences ’s optimizations use circuit equivalences to justify ewrites. Proof that an optimization is correct thus relies oofs that the circuit equivalences it uses are correct. of our circuit equivalence proofs have a common form, we illustrate by example. pose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n bitrary n,m and dimension d. Applying our denition ivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), (1) gure 3. Suppose both sides of the equation are well (m d and n d and m = n), and consider the case (the n m case is similar). We expand appl 1 and 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q pl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q m p q term.) After expressions are in g simplies them by removing mu matrix and rewriting simple matr In our example, after normaliz gridify, both sides of the equalit I2m ⊗ 11 ⊗ I2p ⊗ I2 ⊗ I2q + I2m proving that the two expressions We use gridify to verify mos in the optimizations given in Sec is most eective when equivale alences used in gate cancellation apply to patterns of at most ve For equivalences over larger, non one used in rotation merging, we but still rely on our automation f 4.3 Optimization by Propaga Our propagate-cancel optimizatio localize a set of gates by repeate rules. Then we apply a circuit equ of gates. In most optimizatio of code patterns, but one—not pr 4.2 Proving Circuit Equivalences All of ’s optimizations use circuit equivalences to jus local rewrites. Proof that an optimization is correct thus re on proofs that the circuit equivalences it uses are corr Many of our circuit equivalence proofs have a common fo which we illustrate by example. Suppose we wish to prove the equivalence X n; CNOT m n ≡ CNOT m n; X n for arbitrary n,m and dimension d. Applying our denit of equivalence, this amounts to proving appl 1(X,n,d) × appl 2(CNOT,m,n,d) = appl 2(CNOT,m,n,d) × appl 1(X,n,d), per Figure 3. Suppose both sides of the equation are w typed (m d and n d and m = n), and consider the c m n (the n m case is similar). We expand appl 1 a appl 2 as follows with p = n −m − 1 and q = d − n − 1: appl 1(X,n,d) = I2n ⊗ x ⊗ I2q appl 2(CNOT,m,n,d) = I2m ⊗ 11 ⊗ I2p ⊗ x ⊗ I2q + I2m ⊗ 00 ⊗ I2p ⊗ I2 ⊗ I2q
  • 22. Experiment • Evaluated unitary optimizations • Compared against Qiskit, t ket , PyZX, Nam et al. and Amy et al.2 • Benchmark of 29 programs from Amy et al., ranging from 45 to 61629 gates and 5 to 192 qubits • Considered reduction in total gate count and T-gate count 2Amy et al. Polynomial-Time T-Depth Optimization of Clifford+T Circuits Via Matroid Partitioning. 2014. ⟩| 12
  • 23. Results • Average gate count reduction • Average T-count reduction Amy et al. Nam et al. PyZX VOQC 40.9% 41.0% 42.6% 39.4% Nam et al. Qiskit t ket VOQC 26.5% 10.7% 11.2% 18.4% ⟩| 13
  • 24. ❓ ❓ Is the translation between
 industry IRs and SQIR correct? High-level Language E.g. QWIRE, Quipper, Q# Unoptimized IR E.g. OpenQASM, Quil Optimized IR E.g. OpenQASM, Quil Hardware Instructions Unoptimized SQIR Optimized SQIR VOQC 14
  • 25. Is the translation between
 industry IRs and SQIR correct? High-level Language E.g. QWIRE, Quipper, Q# Unoptimized IR E.g. OpenQASM, Quil Optimized IR E.g. OpenQASM, Quil Hardware Instructions Unoptimized SQIR Optimized SQIR VOQC 14
  • 26. We verify translation between
 OpenQASM and SQIR A feature-complete parser for OpenQASM Translation between unitary fragments of
 the two languages A denotational semantics for unitary OpenQASM Semantic preservation property of translation 15
  • 27. Unitary SQIR and OpenQASM
 have fairly similar abstract syntax cute code on real machines [Wille et al. 2019]. observe that at their core, OpenQASM and s are very similar languages but dier pect. Namely, s assumes a global, indexed register that makes it easy to refer to any ble to the program with its unique index; while OpenQASM uses abstract identier o be declared and looked up. verify correctness of a translation from/to OpenQASM, we must develop a denota tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid ional semantics for a subset of the language which we use as a starting point. Syntax. We employ the following syntax of OpenQASM, following Amy [2019]: Identier x Index i Expression E ::= x | x[i] Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2 Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2 yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library liberate choice for the purpose of translation as most OpenQASM programs are written mmon gates dened in the standard library. Other single-qubit gates are similar modul OpenQASMa OpenQASM is a larger language
 that supports declaring qubit registers
 and user-defined gates SQIR s is a language for describing quantum programs that is deeply embedded in the Coq proof assistant. In s, a qubit is referred to by a natural number that indices into a global register of quantum bits. Unitary s programs allow sequencing and unitary gate application to one or two qubits, drawing from a xed set of gates. U ∶∶= U1; U2 G q G q1 q2 G ∶∶= H CNOT Each s program is parameterized by a unitary gate set (from which G is drawn) and the dimension of the global register (i.e., the number of available qubits). A unitary programU is well-typed if every gate application is valid. A gate application is valid if all of its arguments are in-bounds indices into the global register, and no index is repeated. This second requirement enforces linearity and thereby quantum mechanics’ no-cloning theorem. The semantics of unitary s programs is shown in Fig- ure 3. If a program is not well-typed, its denotation is the zero matrix. The advantage of this denition is that it allows gate is R gate is R0, as s pro swaps two We say U1 ≡ U2, if For verifyi will often w (for ∈ R) that two c U1 ≅ U2, w 3.2 Add To describ s with The comm QPL [41]) P1 or P2 de measurem Qubits are indices into a global register 16
  • 28. Unitary SQIR and OpenQASM
 have fairly similar abstract syntax cute code on real machines [Wille et al. 2019]. observe that at their core, OpenQASM and s are very similar languages but dier pect. Namely, s assumes a global, indexed register that makes it easy to refer to any ble to the program with its unique index; while OpenQASM uses abstract identier o be declared and looked up. verify correctness of a translation from/to OpenQASM, we must develop a denota tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid ional semantics for a subset of the language which we use as a starting point. Syntax. We employ the following syntax of OpenQASM, following Amy [2019]: Identier x Index i Expression E ::= x | x[i] Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2 Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2 yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library liberate choice for the purpose of translation as most OpenQASM programs are written mmon gates dened in the standard library. Other single-qubit gates are similar modul OpenQASMa OpenQASM is a larger language
 that supports declaring qubit registers
 and user-defined gates SQIR s is a language for describing quantum programs that is deeply embedded in the Coq proof assistant. In s, a qubit is referred to by a natural number that indices into a global register of quantum bits. Unitary s programs allow sequencing and unitary gate application to one or two qubits, drawing from a xed set of gates. U ∶∶= U1; U2 G q G q1 q2 G ∶∶= H CNOT Each s program is parameterized by a unitary gate set (from which G is drawn) and the dimension of the global register (i.e., the number of available qubits). A unitary programU is well-typed if every gate application is valid. A gate application is valid if all of its arguments are in-bounds indices into the global register, and no index is repeated. This second requirement enforces linearity and thereby quantum mechanics’ no-cloning theorem. The semantics of unitary s programs is shown in Fig- ure 3. If a program is not well-typed, its denotation is the zero matrix. The advantage of this denition is that it allows gate is R gate is R0, as s pro swaps two We say U1 ≡ U2, if For verifyi will often w (for ∈ R) that two c U1 ≅ U2, w 3.2 Add To describ s with The comm QPL [41]) P1 or P2 de measurem Qubits are indices into a global register 16
  • 29. Unitary SQIR and OpenQASM
 have fairly similar abstract syntax cute code on real machines [Wille et al. 2019]. observe that at their core, OpenQASM and s are very similar languages but dier pect. Namely, s assumes a global, indexed register that makes it easy to refer to any ble to the program with its unique index; while OpenQASM uses abstract identier o be declared and looked up. verify correctness of a translation from/to OpenQASM, we must develop a denota tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid ional semantics for a subset of the language which we use as a starting point. Syntax. We employ the following syntax of OpenQASM, following Amy [2019]: Identier x Index i Expression E ::= x | x[i] Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2 Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2 yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library liberate choice for the purpose of translation as most OpenQASM programs are written mmon gates dened in the standard library. Other single-qubit gates are similar modul OpenQASMa OpenQASM is a larger language
 that supports declaring qubit registers
 and user-defined gates SQIR s is a language for describing quantum programs that is deeply embedded in the Coq proof assistant. In s, a qubit is referred to by a natural number that indices into a global register of quantum bits. Unitary s programs allow sequencing and unitary gate application to one or two qubits, drawing from a xed set of gates. U ∶∶= U1; U2 G q G q1 q2 G ∶∶= H CNOT Each s program is parameterized by a unitary gate set (from which G is drawn) and the dimension of the global register (i.e., the number of available qubits). A unitary programU is well-typed if every gate application is valid. A gate application is valid if all of its arguments are in-bounds indices into the global register, and no index is repeated. This second requirement enforces linearity and thereby quantum mechanics’ no-cloning theorem. The semantics of unitary s programs is shown in Fig- ure 3. If a program is not well-typed, its denotation is the zero matrix. The advantage of this denition is that it allows gate is R gate is R0, as s pro swaps two We say U1 ≡ U2, if For verifyi will often w (for ∈ R) that two c U1 ≅ U2, w 3.2 Add To describ s with The comm QPL [41]) P1 or P2 de measurem Qubits are indices into a global register 16
  • 30. Unitary SQIR and OpenQASM
 have fairly similar abstract syntax cute code on real machines [Wille et al. 2019]. observe that at their core, OpenQASM and s are very similar languages but dier pect. Namely, s assumes a global, indexed register that makes it easy to refer to any ble to the program with its unique index; while OpenQASM uses abstract identier o be declared and looked up. verify correctness of a translation from/to OpenQASM, we must develop a denota tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid ional semantics for a subset of the language which we use as a starting point. Syntax. We employ the following syntax of OpenQASM, following Amy [2019]: Identier x Index i Expression E ::= x | x[i] Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2 Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2 yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library liberate choice for the purpose of translation as most OpenQASM programs are written mmon gates dened in the standard library. Other single-qubit gates are similar modul OpenQASMa OpenQASM is a larger language
 that supports declaring qubit registers
 and user-defined gates SQIR s is a language for describing quantum programs that is deeply embedded in the Coq proof assistant. In s, a qubit is referred to by a natural number that indices into a global register of quantum bits. Unitary s programs allow sequencing and unitary gate application to one or two qubits, drawing from a xed set of gates. U ∶∶= U1; U2 G q G q1 q2 G ∶∶= H CNOT Each s program is parameterized by a unitary gate set (from which G is drawn) and the dimension of the global register (i.e., the number of available qubits). A unitary programU is well-typed if every gate application is valid. A gate application is valid if all of its arguments are in-bounds indices into the global register, and no index is repeated. This second requirement enforces linearity and thereby quantum mechanics’ no-cloning theorem. The semantics of unitary s programs is shown in Fig- ure 3. If a program is not well-typed, its denotation is the zero matrix. The advantage of this denition is that it allows gate is R gate is R0, as s pro swaps two We say U1 ≡ U2, if For verifyi will often w (for ∈ R) that two c U1 ≅ U2, w 3.2 Add To describ s with The comm QPL [41]) P1 or P2 de measurem Qubits are indices into a global register 16 Only shown a sample gate set
 of Hadamard (H) and
 controlled NOT (CNOT or CX)
  • 31. Unitary SQIR and OpenQASM
 have fairly similar abstract syntax aAmy M. Sized Types for Low-Level Quantum Metaprogramming. Reversible Computation. RC 2019. cute code on real machines [Wille et al. 2019]. observe that at their core, OpenQASM and s are very similar languages but dier pect. Namely, s assumes a global, indexed register that makes it easy to refer to any ble to the program with its unique index; while OpenQASM uses abstract identier o be declared and looked up. verify correctness of a translation from/to OpenQASM, we must develop a denota tics for the language, which lacks one despite its pervasiveness. Amy [2019] provid ional semantics for a subset of the language which we use as a starting point. Syntax. We employ the following syntax of OpenQASM, following Amy [2019]: Identier x Index i Expression E ::= x | x[i] Unitary Statement U ::= H(E) | CX(E1, E2) | E(E1, . . . , En) | U1; U2 Command C ::= qreg x[i] | gate x(x1, . . . ,xn) { U } | U | C1; C2 yntax focuses on only the unitary fragment of OpenQASM. It also ignores gates paramet l numbers in favor of built-in gates. For example, instead of the unitary U gate that takes arameters, this syntax uses the Hadamard (H) gate from the OpenQASM standard library liberate choice for the purpose of translation as most OpenQASM programs are written mmon gates dened in the standard library. Other single-qubit gates are similar modul OpenQASMa OpenQASM is a larger language
 that supports declaring qubit registers
 and user-defined gates SQIR s is a language for describing quantum programs that is deeply embedded in the Coq proof assistant. In s, a qubit is referred to by a natural number that indices into a global register of quantum bits. Unitary s programs allow sequencing and unitary gate application to one or two qubits, drawing from a xed set of gates. U ∶∶= U1; U2 G q G q1 q2 G ∶∶= H CNOT Each s program is parameterized by a unitary gate set (from which G is drawn) and the dimension of the global register (i.e., the number of available qubits). A unitary programU is well-typed if every gate application is valid. A gate application is valid if all of its arguments are in-bounds indices into the global register, and no index is repeated. This second requirement enforces linearity and thereby quantum mechanics’ no-cloning theorem. The semantics of unitary s programs is shown in Fig- ure 3. If a program is not well-typed, its denotation is the zero matrix. The advantage of this denition is that it allows gate is R gate is R0, as s pro swaps two We say U1 ≡ U2, if For verifyi will often w (for ∈ R) that two c U1 ≅ U2, w 3.2 Add To describ s with The comm QPL [41]) P1 or P2 de measurem Qubits are indices into a global register 16 Only shown a sample gate set
 of Hadamard (H) and
 controlled NOT (CNOT or CX)
  • 32. Denotational semantics of SQIR
 and OpenQASM correspond 17 SQIR Dra paper, November 22, 2019, K. Hietala, R. Rand, S. Hung, X. Wu nU1; U2od = nU2od × nU1od nG1 qod = appl 1(G1, q, d) well-typed 02d otherwise nG2 q1 q2od = appl 2(G2, q1, q2, d) well-typed 02d otherwise Figure 3. Semantics of unitary s programs, assuming a global register of dimension d. The appl k function maps a gate name to its corresponding unitary matrix and extends the intended operation to the given dimension by applying an identity operation on every other qubit in the system. For example, appl 1(X, q, d) = I2q ⊗ x ⊗ I2(d−q−1) where x is the matrix interpretation of the X gate. 3.1 Unitary Core s is a language for describing quantum programs that is deeply embedded in the Coq proof assistant. In s, a qubit is referred to by a natural number that indices into a global register of quantum bits. Unitary s programs allow sequencing and unitary gate application to one or two qubits, drawing from a xed set of gates. {skip}d ( ) = {P1; P2}d ( ) = ({P2}d ○ {P1}d )( ) {U }d ( ) = nU od × × nU o† d {meas q P1 P2}d ( ) = {P2}d (0q0 × × 0 + {P1}d (1q1 × × 1 Figure 4. s density matrix semantics, assumin register of size d. and the matrix interpretation of the CNOT gate Section 2.1. Common single-qubit gates can be dened in R , , . For example, the identity I is R0,0,0; the Ha gate is R 2,0, ; the Pauli X gate is R ,0, and th gate is R0,0, . We can also dene more complex o as s programs. For example the SWAP operat swaps two qubits, is a sequence of three CNOT g We say that two unitary programs are equivale U1 ≡ U2, if their denotation is the same, i.e., nU1o For verifying equivalence of quantum programs, ho will often want something more general since (for ∈ R) represent the same physical state. We th A SQIR unitary program
 denotes a unitary matrix2d × 2d OpenQASM 3 Value V = Location, l + Loc. Array, (lj, . . . ,lk ) + Unitary Gate, (x1, . . . ,xn).U Environment = Identier ! Value Quantum State | i = 2d -dimension complex vector Here | i is a vector in a 2m-dimension complex Hilbert space, representing the complete quantum state available to a program. For a given program, the size of the vector is determined by m = Õ ni where ni are the sizes of each of the declared quantum registers. Similar to the semantics of s, we need padding functions that are used to determine the modied quantum state after applying a unitary operation to the given location(s), for example: apply(H, | i ,l) = (I ⌦l ⌦ H ⌦ I ⌦m l 1 ) | i This manipulation of global quantum state is necessary as quantum computing inherently involves non-local eects such as entanglement. We can now specify semantic functions for each of the three syntactic classes: Expressions need environment 
 and return bound values Unitary statements modify
 quantum state Commands modify both
 environment and quantum state Value V = Location, l + Loc. Array, (lj, . . . ,lk ) + Unitary Gate, (x1, . . . ,xn).U Environment = Identier ! Value Quantum State | i = 2d -dimension complex vector | i is a vector in a 2m-dimension complex Hilbert space, representing the complete quantum available to a program. For a given program, the size of the vector is determined by m = Õ ni re ni are the sizes of each of the declared quantum registers. milar to the semantics of s, we need padding functions that are used to determine the ied quantum state after applying a unitary operation to the given location(s), for example: apply(H, | i ,l) = (I ⌦l ⌦ H ⌦ I ⌦m l 1 ) | i his manipulation of global quantum state is necessary as quantum computing inherently lves non-local eects such as entanglement. e can now specify semantic functions for each of the three syntactic classes: (| |)E : E ⇥ ! V (| |)U : U ⇥ ⇥ | i ! | 0 i (| |)C : C ⇥ ⇥ | i ! 0 ⇥ | 0 i (| |)E : E ⇥ ! V (| |)U : U ⇥ ⇥ | i ! | 0i (| |)C : C ⇥ ⇥ | i ! 0 ⇥ | 0i xpressions need an environment to return bound values. Unitary statements require an environ- t and the complete quantum state but only manipulate the quantum state. Finally, commands Details elided
  • 33. Semantic preservation properties
 are maintained during translation 18 inally, we would also like to see that if we convert from one language to another and back, we ain the identity function: 8x 2 L(s), (f (x)) = x (3) is very easy to use our translation to obtain the original program written in s and hence the mposition of and f is equivalent to identity function. But a similar statement for translating enQASM to s and back does not hold. This is because of the lack of identiers in s. Our Further, converting from SQIR to OpenQASM and back
 recovers the original program. For all valid programs in SQIR of dimension ,
 their denotation is equivalent to
 the denotation of their translation, and vice versa. dwant to show that the translations from s to OpenQASM (which we will call f ) and ASM to s ( ) are semantics preserving: 8x 2 L(s), nxod = (|f (x)|) (1) 8 2 L(OpenQASM), (| |) = n ( )od (2) f : L(s) ! L(OpenQASM) (3) : L(OpenQASM) ! L(s) (4) of these properties are easy to prove using structural induction on the abstract syntax. For reate a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and ngle mapping for that in the environment . For (2), we also need to prove the correctness unction that maps an OpenQASM register and its index to a s global index. M to s ( ) are semantics preserving: 8x 2 L(s), nxod = (|f (x)|) (1) 8 2 L(OpenQASM), (| |) = n ( )od (2) f : L(s) ! L(OpenQASM) (3) : L(OpenQASM) ! L(s) (4) hese properties are easy to prove using structural induction on the abstract syntax. For te a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and e mapping for that in the environment . For (2), we also need to prove the correctness tion that maps an OpenQASM register and its index to a s global index. we would also like to see that if we convert from one language to another and back, we identity function: 8x 2 L(s), (f (x)) = x (5) easy to use our translation to obtain the original program written in s and hence the n of and f is equivalent to identity function. But a similar statement for translating M to s and back does not hold. This is because of the lack of identiers in s. Our to s is necessarily forgetful and hence, when we translate the program back to M, we lose some of the structure of the original program. ocamllex (the OCaml lexer generator) and the Menhir parser generator [Pottier and as 2019] to write a feature-complete parser for OpenQASM. We then translate the
  • 34. Semantic preservation properties
 are maintained during translation 18 inally, we would also like to see that if we convert from one language to another and back, we ain the identity function: 8x 2 L(s), (f (x)) = x (3) is very easy to use our translation to obtain the original program written in s and hence the mposition of and f is equivalent to identity function. But a similar statement for translating enQASM to s and back does not hold. This is because of the lack of identiers in s. Our Further, converting from SQIR to OpenQASM and back
 recovers the original program. But the reverse direction does not hold. For all valid programs in SQIR of dimension ,
 their denotation is equivalent to
 the denotation of their translation, and vice versa. dwant to show that the translations from s to OpenQASM (which we will call f ) and ASM to s ( ) are semantics preserving: 8x 2 L(s), nxod = (|f (x)|) (1) 8 2 L(OpenQASM), (| |) = n ( )od (2) f : L(s) ! L(OpenQASM) (3) : L(OpenQASM) ! L(s) (4) of these properties are easy to prove using structural induction on the abstract syntax. For reate a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and ngle mapping for that in the environment . For (2), we also need to prove the correctness unction that maps an OpenQASM register and its index to a s global index. M to s ( ) are semantics preserving: 8x 2 L(s), nxod = (|f (x)|) (1) 8 2 L(OpenQASM), (| |) = n ( )od (2) f : L(s) ! L(OpenQASM) (3) : L(OpenQASM) ! L(s) (4) hese properties are easy to prove using structural induction on the abstract syntax. For te a single qubit register “q” of size m (dim of s) to serve as the quantum state | i and e mapping for that in the environment . For (2), we also need to prove the correctness tion that maps an OpenQASM register and its index to a s global index. we would also like to see that if we convert from one language to another and back, we identity function: 8x 2 L(s), (f (x)) = x (5) easy to use our translation to obtain the original program written in s and hence the n of and f is equivalent to identity function. But a similar statement for translating M to s and back does not hold. This is because of the lack of identiers in s. Our to s is necessarily forgetful and hence, when we translate the program back to M, we lose some of the structure of the original program. ocamllex (the OCaml lexer generator) and the Menhir parser generator [Pottier and as 2019] to write a feature-complete parser for OpenQASM. We then translate the
  • 35. OpenQASM parser written in
 OCaml programming language
 19 Conforms to OpenQASM specb Uses OCamllex and Menhir parser generator Available now as an OCaml library on
 OPAM package repository: opam install openQASM bCross et al. Open Quantum Assembly Language. arXiv:1707.03429
  • 36. Ongoing and Future Work • We’re always looking for more transformations to verify • Optimization from other compilers (incl. error aware) • More sophisticated circuit mapping • Compilation of classical circuits • Performance improvements; evaluations on larger sets of benchmarks • Larger verified toolchain • Translation and verification of non-unitary fragments • Validate our OpenQASM parser using Menhir’s Coq backend • Verify translation from high-level languages such as QWIRE 20
  • 37. Conclusions • We have developed a compiler VOQC and an IR SQIR, both implemented and verified in Coq • Performance is comparable to state-of-the-art compilers • We have also taken steps to ease interoperability with industry toolchains with translation from and to OpenQASM • Lots of ongoing work, let us know if you’re interested! • Code: •github.com/inQWIRE/SQIR •github.com/inQWIRE/openqasm-parser • Draft of VOQC paper: cs.umd.edu/~mwh/papers/voqc-draft.pdf 21