PyZX: Quantum circuit optimization using the ZX-calculus Aleks - - PowerPoint PPT Presentation

pyzx quantum circuit optimization using the zx calculus
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

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

slide-2
SLIDE 2

Introduction

§ In fault-tolerant quantum computing, Clifford gates are cheap.

slide-3
SLIDE 3

Introduction

§ In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates.

slide-4
SLIDE 4

Introduction

§ In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ RZpπ{4q.

slide-5
SLIDE 5

Introduction

§ 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.

slide-6
SLIDE 6

Introduction

§ 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.

slide-7
SLIDE 7

T-count optimization Finding optimal T-count is NP-hard, so we need heuristics.

slide-8
SLIDE 8

T-count optimization Finding optimal T-count is NP-hard, so we need heuristics. Existing heuristics fall basically in two categories.

slide-9
SLIDE 9

Method 1: Commutation and Cancellation

Adjacent T gates become Clifford:

T T

=

S T: T

=

slide-10
SLIDE 10

Method 1: Commutation and Cancellation

Adjacent T gates become Clifford:

T T

=

S T: T

= ñ By making T gates adjacent, we can decrease T count.

slide-11
SLIDE 11

Method 1: Commutation and Cancellation

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

slide-12
SLIDE 12

Method 1: Commutation and Cancellation

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...

slide-13
SLIDE 13

Method 2: Phase Polynomials

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.

slide-14
SLIDE 14

Method 2: Phase Polynomials

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

slide-15
SLIDE 15

Method 2: Phase Polynomials

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)

slide-16
SLIDE 16

Limitations

Using commutation, cancellation and phase polynomials, a lot of progress can be made...

slide-17
SLIDE 17

Limitations

Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:

slide-18
SLIDE 18

Limitations

Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:

These methods never stray from the circuit model

slide-19
SLIDE 19

Limitations

Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:

These methods never stray from the circuit model Enter the ZX-calculus

slide-20
SLIDE 20

ZX-diagrams

§ 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- ¨ ¨ ¨ -|

slide-21
SLIDE 21

ZX-diagrams

§ 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 “

slide-22
SLIDE 22

ZX-diagrams

§ 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

slide-23
SLIDE 23

ZX-calculus

β

... ...

α

... ... “ ... ... ...

α`β p-1qaα

aπ aπ aπ α

... ...

aπ aπ

...

aπ α

“ ...

aπ aπ α

... “

α

... “ “ “ α, β P r0, 2πs, a P t0, 1u

slide-24
SLIDE 24

Circuit optimization with the ZX-calculus

§ Write your circuit as a ZX-diagram.

slide-25
SLIDE 25

Circuit optimization with the ZX-calculus

§ Write your circuit as a ZX-diagram. § Apply rewrite rules to simplify it.

slide-26
SLIDE 26

Circuit optimization with the ZX-calculus

§ Write your circuit as a ZX-diagram. § Apply rewrite rules to simplify it. § Turn the resulting diagram back into a circuit.

slide-27
SLIDE 27

First steps: graph-like ZX-diagrams

§ First turn all X-spiders into Z-spiders:

α

... ...

α

... ... =

slide-28
SLIDE 28

First steps: graph-like ZX-diagrams

§ First turn all X-spiders into Z-spiders:

α

... ...

α

... ... =

§ Cancel all double Hadamards:

“ .

slide-29
SLIDE 29

First steps: graph-like ZX-diagrams

§ First turn all X-spiders into Z-spiders:

α

... ...

α

... ... =

§ Cancel all double Hadamards:

“ .

§ Fuse all adjacent spiders.

slide-30
SLIDE 30

First steps: graph-like ZX-diagrams

§ First turn all X-spiders into Z-spiders:

α

... ...

α

... ... =

§ Cancel all double Hadamards:

“ .

§ Fuse all adjacent spiders. § Cancel parallel connections:

α β

... ... =

α

...

β

... ... ...

α β

=

α

...

β

... =

slide-31
SLIDE 31

First steps: graph-like ZX-diagrams

§ First turn all X-spiders into Z-spiders:

α

... ...

α

... ... =

§ Cancel all double Hadamards:

“ .

§ Fuse all adjacent spiders. § Cancel parallel connections:

α β

... ... =

α

...

β

... ... ...

α β

=

α

...

β

... = § Use new notation:

:“

slide-32
SLIDE 32

Example

α γ

γ α γ

α γ α

γ α

γ α

slide-33
SLIDE 33

More involved example

π 2 π 2 π 2 π 2 π 2 π 2 π 2 π 2

=

π 2

π

π 2 π 2 π 2 π 2 π 2

slide-34
SLIDE 34

More involved example

π 2 π 2 π 2 π 2 π 2 π 2 π 2 π 2

=

π 2

π

π 2 π 2 π 2 π 2 π 2

We call these diagrams graph-like.

slide-35
SLIDE 35

More involved example

π 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.

slide-36
SLIDE 36

Local complementation and pivoting

˘ π

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π

... ... ... ... ... ... ... ... ... ... ... ...

slide-37
SLIDE 37

Simplification so far

§ Convert diagram into graph-like diagram.

slide-38
SLIDE 38

Simplification so far

§ Convert diagram into graph-like diagram. § Remove all internal ˘π{2 spiders by local complementation.

slide-39
SLIDE 39

Simplification so far

§ Convert diagram into graph-like diagram. § Remove all internal ˘π{2 spiders by local complementation. § Remove all connected internal aπ spiders by pivoting.

slide-40
SLIDE 40

Simplification so far

§ 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

... ... ... ... ˚

α

˚ ˚

slide-41
SLIDE 41

Simplification so far

§ 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

slide-42
SLIDE 42

Clifford example

Recall the example Clifford diagram:

π 2

π

π 2 π 2 π 2 π 2 π 2

slide-43
SLIDE 43

Clifford example

Recall the example Clifford diagram:

π 2

π

π 2 π 2 π 2 π 2 π 2

This can be reduced by the described procedure to:

π π π

π 2

π

π 2

π

slide-44
SLIDE 44

Clifford+T example

π 2 7π 4 5π 4 π 4 3π 2 3π 2 5π 4

slide-45
SLIDE 45

Clifford+T example

π 2 7π 4 5π 4 π 4 3π 2 3π 2 5π 4

Question: How do we turn this into a circuit.

slide-46
SLIDE 46

Clifford+T example

π 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.

slide-47
SLIDE 47

gFlow

Informally, a gFlow associates an ‘arrow of time’ with a graph. Circuits have a gFlow.

slide-48
SLIDE 48

gFlow

Informally, a gFlow associates an ‘arrow of time’ with a graph. Circuits have a gFlow.

Proposition

Local complementation and pivoting preserve gFlow

slide-49
SLIDE 49

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.

slide-50
SLIDE 50

The simplification procedure

§ We indeed have a circuit-to-circuit simplification procedure

using the ZX-calculus.

§ It reduces Clifford circuits to a quasi normal-form.

slide-51
SLIDE 51

The simplification procedure

§ 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.

slide-52
SLIDE 52

The simplification procedure

§ 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.

slide-53
SLIDE 53

Gadgetization

We turn all non-Clifford spiders into phase gadgets:

α

... = ...

α

gadget

slide-54
SLIDE 54

Gadgetization

We turn all non-Clifford spiders into phase gadgets:

α

... = ...

α

gadget This makes the base of the gadget available for pivoting.

slide-55
SLIDE 55

Example: Gadgetization and pivoting

After the first round of simplifications:

slide-56
SLIDE 56

Example: Gadgetization and pivoting

After the first round of simplifications: After gadgetization:

slide-57
SLIDE 57

Example: Gadgetization and pivoting

After the first round of simplifications: After gadgetization: After pivots/lcomps:

slide-58
SLIDE 58

Final step: phase gadget fusion

Whenever phase gadgets have the same set of neighbours, they can fuse:

α

=

β α β

=

α β

=

α β

=

α ` β α ` β

=

slide-59
SLIDE 59

Spider fusion + Local complementation + Pivoting + Gadgetization + Gadget fusion = State-of-the-art T-count optimization

slide-60
SLIDE 60

Circuit extraction

Problem: We still need to get a circuit out of the diagram.

slide-61
SLIDE 61

Circuit extraction

Problem: We still need to get a circuit out of the diagram. The good news: We have ‘heuristics’ that always seem to work.

slide-62
SLIDE 62

Circuit extraction

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.

slide-63
SLIDE 63

Demonstration of PyZX

slide-64
SLIDE 64

Conclusion and future work The Takeaway: The ZX-calculus is very useful for T-count optimization

slide-65
SLIDE 65

Conclusion and future work The Takeaway: The ZX-calculus is very useful for T-count optimization

Open problems:

§ Why does our circuit extraction work?

slide-66
SLIDE 66

Conclusion and future work The Takeaway: The ZX-calculus is very useful for T-count optimization

Open problems:

§ Why does our circuit extraction work? § How to use phase-polynomial methods on ZX-diagrams?

slide-67
SLIDE 67

Conclusion and future work The Takeaway: The ZX-calculus is very useful for T-count optimization

Open problems:

§ Why does our circuit extraction work? § How to use phase-polynomial methods on ZX-diagrams? § Is the ZH-calculus useful?

slide-68
SLIDE 68

Thank you for your attention