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 § In fault-tolerant quantum computing, Clifford gates are cheap.
Introduction § In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates.
Introduction § In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ R Z p π { 4 q .
Introduction § In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ R Z p π { 4 q . § T gates are far more expensive than Clifford gates.
Introduction § In fault-tolerant quantum computing, Clifford gates are cheap. § But to achieve universal QC we need other gates. § Most commonly T “ R Z p π { 4 q . § T gates are far more expensive than Clifford gates. § So: Optimizing fault tolerant QC means optimizing T-count.
T-count optimization Finding optimal T-count is NP-hard, so we need heuristics.
T-count optimization Finding optimal T-count is NP-hard, so we need heuristics. Existing heuristics fall basically in two categories.
Method 1: Commutation and Cancellation Adjacent T gates become Clifford: T : = T = T T S
Method 1: Commutation and Cancellation Adjacent T gates become Clifford: T : = T = T T S ñ By making T gates adjacent, we can decrease T count.
Method 1: Commutation and Cancellation Adjacent T gates become Clifford: T : = T = T T S ñ By making T gates adjacent, we can decrease T count. T T = + + = T T T T + + + +
Method 1: Commutation and Cancellation Adjacent T gates become Clifford: T : = T = T T S ñ By making T gates adjacent, we can decrease T count. T T = + + = T T T T + + + + And loads more...
Method 2: Phase Polynomials Circuits built out of CNOT and T gates can be written as 4 g p x q | f 1 p x q , . . . , f n p x qy U | x y “ e i π where x P Z n 2 is a binary vector, g : Z n 2 Ñ Z 8 is a polynomial and f i : Z n 2 Ñ Z 2 are Z 2 -linear functions.
Method 2: Phase Polynomials Circuits built out of CNOT and T gates can be written as 4 g p x q | f 1 p x q , . . . , f n p x qy U | x y “ e i π where x P Z n 2 is a binary vector, g : Z n 2 Ñ Z 8 is a polynomial and f i : Z n 2 Ñ Z 2 are Z 2 -linear functions. ñ Using this translation, we can make interesting simplifications
Method 2: Phase Polynomials Circuits built out of CNOT and T gates can be written as 4 g p x q | f 1 p x q , . . . , f n p x qy U | x y “ e i π where x P Z n 2 is a binary vector, g : Z n 2 Ñ Z 8 is a polynomial and f i : Z n 2 Ñ Z 2 are Z 2 -linear functions. ñ Using this translation, we can make interesting simplifications T + + = T T S T + + + + (but optimal T-count finding still seems to be in NP)
Limitations Using commutation, cancellation and phase polynomials, a lot of progress can be made...
Limitations Using commutation, cancellation and phase polynomials, a lot of progress can be made... ...but there is an obvious limitation:
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
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
ZX-diagrams § ZX-diagrams consist of two types of maps x 0 ¨ ¨ ¨ 0 | ` e i α | 1 ¨ ¨ ¨ 1 y § Z-spiders : “ | 0 ¨ ¨ ¨ 0 y x 1 ¨ ¨ ¨ 1 | α ... ... x + ¨ ¨ ¨ + | ` e i α | - ¨ ¨ ¨ - y § X-spiders : “ | + ¨ ¨ ¨ + y x - ¨ ¨ ¨ - | α ... ...
ZX-diagrams § ZX-diagrams consist of two types of maps x 0 ¨ ¨ ¨ 0 | ` e i α | 1 ¨ ¨ ¨ 1 y § Z-spiders : “ | 0 ¨ ¨ ¨ 0 y x 1 ¨ ¨ ¨ 1 | α ... ... x + ¨ ¨ ¨ + | ` e i α | - ¨ ¨ ¨ - y § X-spiders : “ | + ¨ ¨ ¨ + y x - ¨ ¨ ¨ - | α ... ... § By wiring these together, we can make arbitrary linear maps between qubits. For instance: “ H “ T “ - π - π - π π 2 2 2 4 CNOT “ CZ “
ZX-diagrams § ZX-diagrams consist of two types of maps x 0 ¨ ¨ ¨ 0 | ` e i α | 1 ¨ ¨ ¨ 1 y § Z-spiders : “ | 0 ¨ ¨ ¨ 0 y x 1 ¨ ¨ ¨ 1 | α ... ... x + ¨ ¨ ¨ + | ` e i α | - ¨ ¨ ¨ - y § X-spiders : “ | + ¨ ¨ ¨ + y x - ¨ ¨ ¨ - | α ... ... § By wiring these together, we can make arbitrary linear maps between qubits. For instance: “ H “ T “ - π - π - π π 2 2 2 4 CNOT “ CZ “ But also: GHZ = T magic state = π 4
ZX-calculus α ... ... “ ... α ` β “ ... ... α α ... ... β ... ... a π a π a π a π “ a π α “ ... ... a π α p - 1 q a α ... ... a π a π “ “ “ α, β P r 0 , 2 π s , a P t 0 , 1 u
Circuit optimization with the ZX-calculus § Write your circuit as a ZX-diagram.
Circuit optimization with the ZX-calculus § Write your circuit as a ZX-diagram. § Apply rewrite rules to simplify it.
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.
First steps: graph-like ZX-diagrams § First turn all X-spiders into Z-spiders: = α α ... ... ... ...
First steps: graph-like ZX-diagrams § First turn all X-spiders into Z-spiders: = α α ... ... ... ... § Cancel all double Hadamards: “ .
First steps: graph-like ZX-diagrams § First turn all X-spiders into Z-spiders: = α α ... ... ... ... § Cancel all double Hadamards: “ . § Fuse all adjacent spiders.
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: ... ... ... ... = ... ... ... = = ... α β α β α β α β
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: : “
Example α α “ γ γ α α “ “ γ γ α α “ “ γ γ
More involved example π π 2 2 π π π 2 2 2 π π 2 2 π 2 = π π 2 2 π π π 2 2 2 π π 2
More involved example π π 2 2 π π π 2 2 2 π π 2 2 π 2 = π π 2 2 π π π 2 2 2 π π 2 We call these diagrams graph-like .
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.
Local complementation and pivoting ˘ π α 1 ¯ π α n ¯ π 2 2 2 ... ... ... α 1 α n “ ... ... ... α 2 ¯ π 1 ¯ π α n 2 ´ 2 α n α 2 1 ´ ... ... ... ... ... ... ... ... j π k π α 1 γ 1 α 1 ` k π γ 1 ` j π ... ... ... ... “ ... α n γ n α n ` k π γ n ` j π ... ... ... ... β n ... ... β n ` p j ` k ` 1 q π β 1 ... ... β 1 ` p j ` k ` 1 q π ...
Simplification so far § Convert diagram into graph-like diagram.
Simplification so far § Convert diagram into graph-like diagram. § Remove all internal ˘ π { 2 spiders by local complementation.
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.
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 π α j π “ ˚ ˚ ... ... ... ... α 1 α n α 1 α n ... ... ... ...
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 π α j π “ ˚ ˚ ... ... ... ... α 1 α n α 1 α n ... ... ... ... § If the original diagram was Clifford, then the simplified diagram has no internal spiders
Clifford example Recall the example Clifford diagram: π π 2 2 π π π 2 2 2 π π 2
Clifford example Recall the example Clifford diagram: π π 2 2 π π π 2 2 2 π π 2 This can be reduced by the described procedure to: π π π π π 2 π π 2
Clifford+T example 7 π 5 π 4 4 π 2 3 π 5 π 2 4 3 π π 2 4
Clifford+T example 7 π 5 π 4 4 π 2 3 π 5 π 2 4 3 π π 2 4 Question: How do we turn this into a circuit.
Recommend
More recommend