Simulation of quantum circuits by ZX-diagram contraction John van - - PowerPoint PPT Presentation

simulation of quantum circuits by zx diagram contraction
SMART_READER_LITE
LIVE PREVIEW

Simulation of quantum circuits by ZX-diagram contraction John van - - PowerPoint PPT Presentation

Simulation of quantum circuits by ZX-diagram contraction John van de Wetering john@vdwetering.name Institute for Computing and Information Sciences Radboud University Nijmegen September 6, 2019 Holy Trinity of quantum circuits Holy Trinity


slide-1
SLIDE 1

Simulation of quantum circuits by ZX-diagram contraction

John van de Wetering

john@vdwetering.name

Institute for Computing and Information Sciences Radboud University Nijmegen

September 6, 2019

slide-2
SLIDE 2

Holy Trinity of quantum circuits

slide-3
SLIDE 3

Holy Trinity of quantum circuits

slide-4
SLIDE 4

Holy Trinity of quantum circuits

slide-5
SLIDE 5

Quantum circuit simulation

The Problem: Given quantum circuit C, and input state |ψy, answer some question about C |ψy.

slide-6
SLIDE 6

Quantum circuit simulation

The Problem: Given quantum circuit C, and input state |ψy, answer some question about C |ψy. E.g. Find the probability |x0 ¨ ¨ ¨ 0|C |ψy|2.

slide-7
SLIDE 7

Quantum circuit simulation

The Problem: Given quantum circuit C, and input state |ψy, answer some question about C |ψy. E.g. Find the probability |x0 ¨ ¨ ¨ 0|C |ψy|2. Why do we care?

§ Verification of correctness of circuits. § Modelling physical systems. § Understand when quantum supremacy has been reached.

slide-8
SLIDE 8

Weak versus Strong simulation

Suppose we measure all qubits in computational basis at the end

  • f the circuit. Then we get a probability distribution

Ppx1 ¨ ¨ ¨ xnq “ |xx1 ¨ ¨ ¨ xn|C |ψy|2

slide-9
SLIDE 9

Weak versus Strong simulation

Suppose we measure all qubits in computational basis at the end

  • f the circuit. Then we get a probability distribution

Ppx1 ¨ ¨ ¨ xnq “ |xx1 ¨ ¨ ¨ xn|C |ψy|2 Weak simulation: sample from this distribution. This is BQP-complete.

slide-10
SLIDE 10

Weak versus Strong simulation

Suppose we measure all qubits in computational basis at the end

  • f the circuit. Then we get a probability distribution

Ppx1 ¨ ¨ ¨ xnq “ |xx1 ¨ ¨ ¨ xn|C |ψy|2 Weak simulation: sample from this distribution. This is BQP-complete. Strong simulation: get any marginal probability of Ppx1 ¨ ¨ ¨ xnq. This is #P-hard.

slide-11
SLIDE 11

Direct simulation

Write n-qubit state as 2n complex numbers. Every gate in the circuit modifies this vector.

slide-12
SLIDE 12

Direct simulation

Write n-qubit state as 2n complex numbers. Every gate in the circuit modifies this vector.

§ Naively, for n “ 50 would take « 1000TB.

slide-13
SLIDE 13

Direct simulation

Write n-qubit state as 2n complex numbers. Every gate in the circuit modifies this vector.

§ Naively, for n “ 50 would take « 1000TB. § But n « 80 has been achieved in practice by being smart.

(exploiting sparsity, limited depth of circuit, etc.)

slide-14
SLIDE 14

Direct simulation

Write n-qubit state as 2n complex numbers. Every gate in the circuit modifies this vector.

§ Naively, for n “ 50 would take « 1000TB. § But n « 80 has been achieved in practice by being smart.

(exploiting sparsity, limited depth of circuit, etc.) All these methods in a sense rely on tensor contraction. They are all exponential in number of qubits.

slide-15
SLIDE 15

Stabilizer decompositions 1

Gottesman-Knill Theorem

Any Clifford computation can be efficiently simulated. Q: Can we exploit this somehow to simulate arbitrary circuits?

slide-16
SLIDE 16

Stabilizer decompositions 1

Gottesman-Knill Theorem

Any Clifford computation can be efficiently simulated. Q: Can we exploit this somehow to simulate arbitrary circuits? Observation: Clifford states linearly span the set of all states.

slide-17
SLIDE 17

Stabilizer decompositions 1

Gottesman-Knill Theorem

Any Clifford computation can be efficiently simulated. Q: Can we exploit this somehow to simulate arbitrary circuits? Observation: Clifford states linearly span the set of all states.

  • 1. Gadgetize T-gates to write any circuit as:

Clifford circuit C & |Ty magic state ancillae.

slide-18
SLIDE 18

Stabilizer decompositions 1

Gottesman-Knill Theorem

Any Clifford computation can be efficiently simulated. Q: Can we exploit this somehow to simulate arbitrary circuits? Observation: Clifford states linearly span the set of all states.

  • 1. Gadgetize T-gates to write any circuit as:

Clifford circuit C & |Ty magic state ancillae.

  • 2. Write input state + ancillae as linear combination of Cliffords:

|ψy “ řn

i λi |φiy.

slide-19
SLIDE 19

Stabilizer decompositions 1

Gottesman-Knill Theorem

Any Clifford computation can be efficiently simulated. Q: Can we exploit this somehow to simulate arbitrary circuits? Observation: Clifford states linearly span the set of all states.

  • 1. Gadgetize T-gates to write any circuit as:

Clifford circuit C & |Ty magic state ancillae.

  • 2. Write input state + ancillae as linear combination of Cliffords:

|ψy “ řn

i λi |φiy.

  • 3. Note: Each C |φiy can be efficiently simulated!
slide-20
SLIDE 20

Stabilizer decompositions 2

Given Clifford circuit C and input |ψy “ řn

i λi |φiy

where the |φiy are Clifford. How do we approximate C |ψy?

slide-21
SLIDE 21

Stabilizer decompositions 2

Given Clifford circuit C and input |ψy “ řn

i λi |φiy

where the |φiy are Clifford. How do we approximate C |ψy? Two methods:

  • 1. Monte-Carlo over the |φiy weighted by |λi|.

Polynomial in the negativity: λ “ řn

i |λi|.

slide-22
SLIDE 22

Stabilizer decompositions 2

Given Clifford circuit C and input |ψy “ řn

i λi |φiy

where the |φiy are Clifford. How do we approximate C |ψy? Two methods:

  • 1. Monte-Carlo over the |φiy weighted by |λi|.

Polynomial in the negativity: λ “ řn

i |λi|.

  • 2. Compute řn

i λiC |φiy.

Polynomial in the stabilizer rank: Rp|ψyq “ n.

slide-23
SLIDE 23

Stabilizer decompositions 2

Given Clifford circuit C and input |ψy “ řn

i λi |φiy

where the |φiy are Clifford. How do we approximate C |ψy? Two methods:

  • 1. Monte-Carlo over the |φiy weighted by |λi|.

Polynomial in the negativity: λ “ řn

i |λi|.

  • 2. Compute řn

i λiC |φiy.

Polynomial in the stabilizer rank: Rp|ψyq “ n. Benefit of first: can deal with density matrices and noise. Benefit of second: better constants and thus scaling.

slide-24
SLIDE 24

Stabilizer decompositions 2

Given Clifford circuit C and input |ψy “ řn

i λi |φiy

where the |φiy are Clifford. How do we approximate C |ψy? Two methods:

  • 1. Monte-Carlo over the |φiy weighted by |λi|.

Polynomial in the negativity: λ “ řn

i |λi|.

  • 2. Compute řn

i λiC |φiy.

Polynomial in the stabilizer rank: Rp|ψyq “ n. Benefit of first: can deal with density matrices and noise. Benefit of second: better constants and thus scaling. We will only use the second approach.

slide-25
SLIDE 25

Stabilizer rank

T-magic state |Ty :“ |0y ` eiπ{4 |1y has rank Rp|Tyq “ 2.

slide-26
SLIDE 26

Stabilizer rank

T-magic state |Ty :“ |0y ` eiπ{4 |1y has rank Rp|Tyq “ 2. Hence: Rp|Tybnq ď 2n e.g. |Ty b |Ty “ |00y ` eiπ{4 |01y ` eiπ{4 |10y ` eiπ{2 |11y

slide-27
SLIDE 27

Stabilizer rank

T-magic state |Ty :“ |0y ` eiπ{4 |1y has rank Rp|Tyq “ 2. Hence: Rp|Tybnq ď 2n e.g. |Ty b |Ty “ |00y ` eiπ{4 |01y ` eiπ{4 |10y ` eiπ{2 |11y But also: |Ty b |Ty “ p|00y ` i |11yq ` eiπ{4p|01y ` |10yq, so actually Rp|Tyb2q “ 2,

slide-28
SLIDE 28

Stabilizer rank

T-magic state |Ty :“ |0y ` eiπ{4 |1y has rank Rp|Tyq “ 2. Hence: Rp|Tybnq ď 2n e.g. |Ty b |Ty “ |00y ` eiπ{4 |01y ` eiπ{4 |10y ` eiπ{2 |11y But also: |Ty b |Ty “ p|00y ` i |11yq ` eiπ{4p|01y ` |10yq, so actually Rp|Tyb2q “ 2, and hence: Rp|Tybnq “ Rpp|Ty b |Tyqn{2q ď 2n{2

slide-29
SLIDE 29

Stabilizer rank

T-magic state |Ty :“ |0y ` eiπ{4 |1y has rank Rp|Tyq “ 2. Hence: Rp|Tybnq ď 2n e.g. |Ty b |Ty “ |00y ` eiπ{4 |01y ` eiπ{4 |10y ` eiπ{2 |11y But also: |Ty b |Ty “ p|00y ` i |11yq ` eiπ{4p|01y ` |10yq, so actually Rp|Tyb2q “ 2, and hence: Rp|Tybnq “ Rpp|Ty b |Tyqn{2q ď 2n{2 Can also show that Rp|Tyb6q “ 7, and hence: Rp|Tybnq ď 2αn where α “ log2p7q{6 « 0.468

slide-30
SLIDE 30

The goal: combine tensor contraction & stabilizer decompositions using the ZX-calculus.

slide-31
SLIDE 31

ZX-diagrams

What gates are to circuits, spiders are to ZX-diagrams.

slide-32
SLIDE 32

ZX-diagrams

What gates are to circuits, spiders are to ZX-diagrams. Z-spider X-spider |0 ¨ ¨ ¨ 0y x0 ¨ ¨ ¨ 0| |+ ¨ ¨ ¨ +y x+ ¨ ¨ ¨ +| `eiα |1 ¨ ¨ ¨ 1y x1 ¨ ¨ ¨ 1| ` eiα |- ¨ ¨ ¨ -y x- ¨ ¨ ¨ -|

α

... ...

α

... ...

slide-33
SLIDE 33

ZX-diagrams

What gates are to circuits, spiders are to ZX-diagrams. Z-spider X-spider |0 ¨ ¨ ¨ 0y x0 ¨ ¨ ¨ 0| |+ ¨ ¨ ¨ +y x+ ¨ ¨ ¨ +| `eiα |1 ¨ ¨ ¨ 1y x1 ¨ ¨ ¨ 1| ` eiα |- ¨ ¨ ¨ -y x- ¨ ¨ ¨ -|

α

... ...

α

... ... Spiders can be wired in any way:

α

π 2 3π 2

β π

slide-34
SLIDE 34

Quantum gates as ZX-diagrams

Every quantum gate can be written as a ZX-diagram: S “

π 2

T “

π 4

H “ :=

π 2 π 2 π 2

CNOT “ CZ “ “

slide-35
SLIDE 35

Quantum gates as ZX-diagrams

Every quantum gate can be written as a ZX-diagram: S “

π 2

T “

π 4

H “ :=

π 2 π 2 π 2

CNOT “ CZ “ “

Universality

Any linear map between qubits can be represented as a ZX-diagram.

slide-36
SLIDE 36

Rules for ZX-diagrams: The ZX-calculus

β

... ...

α

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

α`β p-1qaα

aπ aπ aπ α

... ...

aπ aπ

...

aπ α

“ ...

aπ aπ α

... “

α

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

slide-37
SLIDE 37

Completeness of the ZX-calculus

Theorem

ZX-diagrams representing same linear map, can be transformed into one another using previous rules (and some additional ones).

slide-38
SLIDE 38

Circuit simulation with ZX-calculus

  • 1. Write circuit+state as ZX-diagram.
  • 2. Simplify using ZX-calculus rules.
slide-39
SLIDE 39

Circuit simulation with ZX-calculus

  • 1. Write circuit+state as ZX-diagram.
  • 2. Simplify using ZX-calculus rules.
  • 3. Replace magic states by stabilizer decomposition.
slide-40
SLIDE 40

Circuit simulation with ZX-calculus

  • 1. Write circuit+state as ZX-diagram.
  • 2. Simplify using ZX-calculus rules.
  • 3. Replace magic states by stabilizer decomposition.
  • 4. Repeat.
  • 5. ...
  • 6. Profit!
slide-41
SLIDE 41

Simplifying ZX-diagrams

Same as in previous talk (local complementation, pivoting, gadgetization)

slide-42
SLIDE 42

Simplifying ZX-diagrams

Same as in previous talk (local complementation, pivoting, gadgetization) But:

§ All rewrites now need to be scalar accurate.

slide-43
SLIDE 43

Simplifying ZX-diagrams

Same as in previous talk (local complementation, pivoting, gadgetization) But:

§ All rewrites now need to be scalar accurate. § We no longer care about circuit extraction,

so we can do more stuff!

slide-44
SLIDE 44

Scalar-accurate local complementation and pivot

˘ π

2

α1 αn

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

α1¯ π

2

...

αn ¯ π

2

α2

...

αn

´ 1

...

α2¯ π

2

...

αn

´ 1¯ π 2

... ... e˘iπ{4? 2

pn´1qpn´2q 2

jπ α1

αn βm β1 γ1 γl kπ

... ... ...

αn ` kπ β1 ` pj ` k ` 1qπ

...

βm ` pj ` k ` 1qπ γ1 ` jπ α1 ` kπ

... ...

γl ` jπ

... ... ... ... ... ... ... ... ... ... ... ... p´1qab? 2

pn´1qm

? 2

pl´1qm

? 2

pn´1qpl´1q

slide-45
SLIDE 45

Scalar-accurate local complementation and pivot

˘ π

2

α1 αn

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

α1¯ π

2

...

αn ¯ π

2

α2

...

αn

´ 1

...

α2¯ π

2

...

αn

´ 1¯ π 2

... ... e˘iπ{4? 2

pn´1qpn´2q 2

jπ α1

αn βm β1 γ1 γl kπ

... ... ...

αn ` kπ β1 ` pj ` k ` 1qπ

...

βm ` pj ` k ` 1qπ γ1 ` jπ α1 ` kπ

... ...

γl ` jπ

... ... ... ... ... ... ... ... ... ... ... ... p´1qab? 2

pn´1qm

? 2

pl´1qm

? 2

pn´1qpl´1q

These + variations kill all internal Clifford spiders.

slide-46
SLIDE 46

Further optimization

From previous talk:

α β

... ... =

α ` β

... ...

α β α1 αn

...

α ` β α1 αn

... = ... ... ... ... ´

1 ? 2

¯n´1

slide-47
SLIDE 47

New rule: Supplementarity

Rule used in ZX for completeness:

α α ` π

=

2α ` π

1 2

slide-48
SLIDE 48

New rule: Supplementarity

Rule used in ZX for completeness:

α α ` π

=

2α ` π

1 2

Can be generalised to following four cases:

α α ` π

= . . .

2α ` π

. . .

1 2n

n n

α α ` π

= . . .

. . .

1 2n`1

n n

α ´α ` π

= . . .

2α ` π π π

. . .

  • e´iα

2n

n n

α ´α ` π

= . . .

2α π π

. . .

e´iα 2n`1

n n

slide-49
SLIDE 49

Example

Consider benchmark circuit hwb6: 7 qubits, and 105 T-gates. After PyZX simplification: 75 T-gates.

slide-50
SLIDE 50

Example

Consider benchmark circuit hwb6: 7 qubits, and 105 T-gates. After PyZX simplification: 75 T-gates. Inputting the state |` ` ´ ´ ´ ` ´y and effect x`011 ´ 1´|,

slide-51
SLIDE 51

Example

Consider benchmark circuit hwb6: 7 qubits, and 105 T-gates. After PyZX simplification: 75 T-gates. Inputting the state |` ` ´ ´ ´ ` ´y and effect x`011 ´ 1´|, and further simplifying gives (up to scalar):

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

This has 33 T-gates.

slide-52
SLIDE 52

Example

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

=

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

π

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

Now we should apply the stabilizer decomposition to these states.

slide-53
SLIDE 53

Stabilizer decompositions in ZX

π 4

= eiπ{4

π

+

π 4

= eiπ{4 +

π 4

π

π 2

But what about the 6 T-gate rank 7 decomposition?

slide-54
SLIDE 54

Source: Sergey Bravyi, Graeme Smith, and John A Smolin. Trading classical and quantum computational resources (2016).

slide-55
SLIDE 55

eiπ{4

π 4 π 4 π 4 π 4 π 4 π 4

= ´1`

? 2 4 1´ ? 2 4

π π π π π π

+ ´2i

π

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

´2 ? 2i

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

`2eiπ{4

  • π

2

`8 ? 2i

π

`8 ? 2i

π

slide-56
SLIDE 56

Demo time

slide-57
SLIDE 57

Conclusions

§ With ZX-calculus we can combine tensor contraction with

stabilizer decomposition.

slide-58
SLIDE 58

Conclusions

§ With ZX-calculus we can combine tensor contraction with

stabilizer decomposition.

§ With rewriting we can further reduce amount of non-Cliffords

in each sub-diagram.

slide-59
SLIDE 59

Conclusions

§ With ZX-calculus we can combine tensor contraction with

stabilizer decomposition.

§ With rewriting we can further reduce amount of non-Cliffords

in each sub-diagram.

§ Even removing just 1 extra spider in every diagram would

allow « 15% bigger circuits.

slide-60
SLIDE 60

Future work

§ Investigate which groups of spiders should be replaced. § Find right trade-off in using more computation early on.

slide-61
SLIDE 61

Future work

§ Investigate which groups of spiders should be replaced. § Find right trade-off in using more computation early on. § Approximate decompositions and pruning of small branches.

slide-62
SLIDE 62

Future work

§ Investigate which groups of spiders should be replaced. § Find right trade-off in using more computation early on. § Approximate decompositions and pruning of small branches. § Make high-performance implementation of the algorithm.

slide-63
SLIDE 63

Future work

§ Investigate which groups of spiders should be replaced. § Find right trade-off in using more computation early on. § Approximate decompositions and pruning of small branches. § Make high-performance implementation of the algorithm. § Marginal probabilities possible with CPM construction. Is

there a better way?

slide-64
SLIDE 64

Thank you for your attention!

github.com/Quantomatic/pyzx zxcalculus.com/pyzx