PyZX: Quantum circuit optimization using the ZX-calculus
Aleks Kissinger
aleks@cs.ru.nl
John van de Wetering
john@vdwetering.name
Institute for Computing and Information Sciences Radboud University Nijmegen
December 17, 2018
PyZX: Quantum circuit optimization using the ZX-calculus Aleks - - PowerPoint PPT Presentation
PyZX: Quantum circuit optimization using the ZX-calculus Aleks Kissinger aleks@cs.ru.nl John van de Wetering john@vdwetering.name Institute for Computing and Information Sciences Radboud University Nijmegen December 17, 2018 Introduction
Aleks Kissinger
aleks@cs.ru.nl
John van de Wetering
john@vdwetering.name
Institute for Computing and Information Sciences Radboud University Nijmegen
December 17, 2018
§ In fault-tolerant quantum computing, Clifford gates are cheap.
§ In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates.
§ In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ RZpπ{4q.
§ In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ RZpπ{4q. § T gates are far more expensive than Clifford gates.
§ In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ RZpπ{4q. § T gates are far more expensive than Clifford gates. § So:
Optimizing fault tolerant QC means optimizing T-count.
Adjacent T gates become Clifford:
T T
=
S T: T
=
Adjacent T gates become Clifford:
T T
=
S T: T
= ñ By making T gates adjacent, we can decrease T count.
Adjacent T gates become Clifford:
T T
=
S T: T
= ñ By making T gates adjacent, we can decrease T count.
T
=
+
T
+
T
=
+ +
T T
+ +
T
Adjacent T gates become Clifford:
T T
=
S T: T
= ñ By making T gates adjacent, we can decrease T count.
T
=
+
T
+
T
=
+ +
T T
+ +
T
And loads more...
Circuits built out of CNOT and T gates can be written as U |xy “ ei π
4 gpxq |f1pxq, . . . , fnpxqy
where x P Zn
2 is a binary vector,
g : Zn
2 Ñ Z8 is a polynomial and
fi : Zn
2 Ñ Z2 are Z2-linear functions.
Circuits built out of CNOT and T gates can be written as U |xy “ ei π
4 gpxq |f1pxq, . . . , fnpxqy
where x P Zn
2 is a binary vector,
g : Zn
2 Ñ Z8 is a polynomial and
fi : Zn
2 Ñ Z2 are Z2-linear functions.
ñ Using this translation, we can make interesting simplifications
Circuits built out of CNOT and T gates can be written as U |xy “ ei π
4 gpxq |f1pxq, . . . , fnpxqy
where x P Zn
2 is a binary vector,
g : Zn
2 Ñ Z8 is a polynomial and
fi : Zn
2 Ñ Z2 are Z2-linear functions.
ñ Using this translation, we can make interesting simplifications =
+ +
T
+ +
T
+ +
S T T
(but optimal T-count finding still seems to be in NP)
Using commutation, cancellation and phase polynomials, a lot of progress can be made...
Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:
Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:
Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:
§ ZX-diagrams consist of two types of maps § Z-spiders
α
... ... :“ |0 ¨ ¨ ¨ 0y x0 ¨ ¨ ¨ 0| ` eiα |1 ¨ ¨ ¨ 1y x1 ¨ ¨ ¨ 1|
§ X-spiders
α
... ... :“ |+ ¨ ¨ ¨ +y x+ ¨ ¨ ¨ +| ` eiα |- ¨ ¨ ¨ -y x- ¨ ¨ ¨ -|
§ ZX-diagrams consist of two types of maps § Z-spiders
α
... ... :“ |0 ¨ ¨ ¨ 0y x0 ¨ ¨ ¨ 0| ` eiα |1 ¨ ¨ ¨ 1y x1 ¨ ¨ ¨ 1|
§ X-spiders
α
... ... :“ |+ ¨ ¨ ¨ +y x+ ¨ ¨ ¨ +| ` eiα |- ¨ ¨ ¨ -y x- ¨ ¨ ¨ -|
§ By wiring these together, we can make arbitrary linear maps
between qubits. For instance: H “ “
2
2
2
T “
π 4
CNOT “ CZ “
§ ZX-diagrams consist of two types of maps § Z-spiders
α
... ... :“ |0 ¨ ¨ ¨ 0y x0 ¨ ¨ ¨ 0| ` eiα |1 ¨ ¨ ¨ 1y x1 ¨ ¨ ¨ 1|
§ X-spiders
α
... ... :“ |+ ¨ ¨ ¨ +y x+ ¨ ¨ ¨ +| ` eiα |- ¨ ¨ ¨ -y x- ¨ ¨ ¨ -|
§ By wiring these together, we can make arbitrary linear maps
between qubits. For instance: H “ “
2
2
2
T “
π 4
CNOT “ CZ “ But also: GHZ = T magic state =
π 4
β
... ...
α
... ... “ ... ... ...
α`β p-1qaα
“
aπ aπ aπ α
... ...
aπ aπ
...
aπ α
“ ...
aπ aπ α
... “
α
... “ “ “ α, β P r0, 2πs, a P t0, 1u
§ Write your circuit as a ZX-diagram.
§ Write your circuit as a ZX-diagram. § Apply rewrite rules to simplify it.
§ Write your circuit as a ZX-diagram. § Apply rewrite rules to simplify it. § Turn the resulting diagram back into a circuit.
§ First turn all X-spiders into Z-spiders:
α
... ...
α
... ... =
§ First turn all X-spiders into Z-spiders:
α
... ...
α
... ... =
§ Cancel all double Hadamards:
“ .
§ First turn all X-spiders into Z-spiders:
α
... ...
α
... ... =
§ Cancel all double Hadamards:
“ .
§ Fuse all adjacent spiders.
§ First turn all X-spiders into Z-spiders:
α
... ...
α
... ... =
§ Cancel all double Hadamards:
“ .
§ Fuse all adjacent spiders. § Cancel parallel connections:
α β
... ... =
α
...
β
... ... ...
α β
=
α
...
β
... =
§ First turn all X-spiders into Z-spiders:
α
... ...
α
... ... =
§ Cancel all double Hadamards:
“ .
§ Fuse all adjacent spiders. § Cancel parallel connections:
α β
... ... =
α
...
β
... ... ...
α β
=
α
...
β
... = § Use new notation:
:“
α γ
“
γ α γ
“
α γ α
“
γ α
“
γ α
“
π 2 π 2 π 2 π 2 π 2 π 2 π 2 π 2
π 2
π
π 2 π 2 π 2 π 2 π 2
π 2 π 2 π 2 π 2 π 2 π 2 π 2 π 2
π 2
π
π 2 π 2 π 2 π 2 π 2
We call these diagrams graph-like.
π 2 π 2 π 2 π 2 π 2 π 2 π 2 π 2
π 2
π
π 2 π 2 π 2 π 2 π 2
We call these diagrams graph-like. To simplify these diagrams, we want to remove as many interior vertices as possible.
˘ π
2
α1 αn
... ... ... “ ...
α1¯ π
2
...
αn ¯ π
2
α2
...
αn
´ 1
...
α2¯ π
2
...
αn
´ 1¯ π 2
... ...
jπ α1
“
αn β1 βn γ1 γn kπ
... ... ...
αn ` kπ βn ` pj ` k ` 1qπ
...
β1 ` pj ` k ` 1qπ γ1 ` jπ α1 ` kπ
... ...
γn ` jπ
... ... ... ... ... ... ... ... ... ... ... ...
§ Convert diagram into graph-like diagram.
§ Convert diagram into graph-like diagram. § Remove all internal ˘π{2 spiders by local complementation.
§ Convert diagram into graph-like diagram. § Remove all internal ˘π{2 spiders by local complementation. § Remove all connected internal aπ spiders by pivoting.
§ Convert diagram into graph-like diagram. § Remove all internal ˘π{2 spiders by local complementation. § Remove all connected internal aπ spiders by pivoting. § Remove internal aπ spider connected to boundary by unfusing
and pivoting:
jπ α1
“
αn α
... ... ... ... ˚
jπ α1 αn
... ... ... ... ˚
α
˚ ˚
§ Convert diagram into graph-like diagram. § Remove all internal ˘π{2 spiders by local complementation. § Remove all connected internal aπ spiders by pivoting. § Remove internal aπ spider connected to boundary by unfusing
and pivoting:
jπ α1
“
αn α
... ... ... ... ˚
jπ α1 αn
... ... ... ... ˚
α
˚ ˚
§ If the original diagram was Clifford, then the simplified
diagram has no internal spiders
Recall the example Clifford diagram:
π 2
π
π 2 π 2 π 2 π 2 π 2
Recall the example Clifford diagram:
π 2
π
π 2 π 2 π 2 π 2 π 2
This can be reduced by the described procedure to:
π π π
π 2
π
π 2
π
π 2 7π 4 5π 4 π 4 3π 2 3π 2 5π 4
π 2 7π 4 5π 4 π 4 3π 2 3π 2 5π 4
Question: How do we turn this into a circuit.
π 2 7π 4 5π 4 π 4 3π 2 3π 2 5π 4
Question: How do we turn this into a circuit. Answer: We use the fact that it has a gFlow.
Informally, a gFlow associates an ‘arrow of time’ with a graph. Circuits have a gFlow.
Informally, a gFlow associates an ‘arrow of time’ with a graph. Circuits have a gFlow.
Proposition
Local complementation and pivoting preserve gFlow
Informally, a gFlow associates an ‘arrow of time’ with a graph. Circuits have a gFlow.
Proposition
Local complementation and pivoting preserve gFlow
Theorem
There is an efficient procedure that transforms a ZX-diagram with a gFlow into a circuit.
§ We indeed have a circuit-to-circuit simplification procedure
using the ZX-calculus.
§ It reduces Clifford circuits to a quasi normal-form.
§ We indeed have a circuit-to-circuit simplification procedure
using the ZX-calculus.
§ It reduces Clifford circuits to a quasi normal-form. § But: T gates never get removed by lcomp and pivoting.
§ We indeed have a circuit-to-circuit simplification procedure
using the ZX-calculus.
§ It reduces Clifford circuits to a quasi normal-form. § But: T gates never get removed by lcomp and pivoting. § So:
To do significant T-count optimization, we need to do better.
We turn all non-Clifford spiders into phase gadgets:
α
... = ...
α
gadget
We turn all non-Clifford spiders into phase gadgets:
α
... = ...
α
gadget This makes the base of the gadget available for pivoting.
After the first round of simplifications:
After the first round of simplifications: After gadgetization:
After the first round of simplifications: After gadgetization: After pivots/lcomps:
Whenever phase gadgets have the same set of neighbours, they can fuse:
α
=
β α β
=
α β
=
α β
=
α ` β α ` β
=
Problem: We still need to get a circuit out of the diagram.
Problem: We still need to get a circuit out of the diagram. The good news: We have ‘heuristics’ that always seem to work.
Problem: We still need to get a circuit out of the diagram. The good news: We have ‘heuristics’ that always seem to work. The bad news: We don’t know why.
Open problems:
§ Why does our circuit extraction work?
Open problems:
§ Why does our circuit extraction work? § How to use phase-polynomial methods on ZX-diagrams?
Open problems:
§ Why does our circuit extraction work? § How to use phase-polynomial methods on ZX-diagrams? § Is the ZH-calculus useful?