##// END OF EJS Templates
add feedback that ctrl-d was pressed
add feedback that ctrl-d was pressed

File last commit:

r4637:d919e2ec
r4950:2b7a2280
Show More
decompose.ipynb
280 lines | 53.9 KiB | text/plain | TextLexer

Gate Decomposition

In [1]:
%load_ext sympyprinting
In [2]:
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin
from sympy.physics.quantum import *
from sympy.physics.quantum.qubit import *
from sympy.physics.quantum.gate import *
from sympy.physics.quantum.grover import *
from sympy.physics.quantum.qft import QFT, IQFT, Fourier
from sympy.physics.quantum.circuitplot import circuit_plot

Example 1

Create a symbolic controlled-Y gate

In [3]:
CY10 = CGate(1, Y(0)); CY10
Out[3]:
$$C_{1}{\left(Y_{0}\right)}$$

Decompose it into elementary gates and plot it

In [4]:
CY10.decompose()
Out[4]:
$$S_{0} CNOT_{1,0} S_{0} Z_{0}$$
In [5]:
circuit_plot(CY10.decompose(), nqubits=2)
Out[5]:
<sympy.physics.quantum.circuitplot.CircuitPlot object at 0x2c85f10>
No description has been provided for this image

Example 2

Create a controlled-Z gate

In [6]:
CZ01 = CGate(0, Z(1)); CZ01
Out[6]:
$$C_{0}{\left(Z_{1}\right)}$$

Decompose and plot it

In [7]:
CZ01.decompose()
Out[7]:
$$H_{1} CNOT_{0,1} H_{1}$$
In [8]:
circuit_plot(CZ01.decompose(), nqubits=2)
Out[8]:
<sympy.physics.quantum.circuitplot.CircuitPlot object at 0x472d550>
No description has been provided for this image

Example 3

Create a SWAP gate

In [9]:
SWAP10 = SWAP(1, 0); SWAP10
Out[9]:
$$SWAP_{1,0}$$

Decompose and plot it

In [10]:
SWAP10.decompose()
Out[10]:
$$CNOT_{1,0} CNOT_{0,1} CNOT_{1,0}$$
In [11]:
circuit_plot(SWAP10.decompose(), nqubits=2)
Out[11]:
<sympy.physics.quantum.circuitplot.CircuitPlot object at 0x7f082c973650>
No description has been provided for this image

All together now

In [12]:
gates = [CGate(1,Y(0)), CGate(0,Z(1)), SWAP(1, 0)]
In [16]:
for g in gates:
    dg = g.decompose()
    display(Eq(g, dg))
    circuit_plot(g, nqubits=2)
    circuit_plot(dg, nqubits=2)    
$$C_{1}{\left(Y_{0}\right)} = S_{0} CNOT_{1,0} S_{0} Z_{0}$$
$$C_{0}{\left(Z_{1}\right)} = H_{1} CNOT_{0,1} H_{1}$$
$$SWAP_{1,0} = CNOT_{1,0} CNOT_{0,1} CNOT_{1,0}$$
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image
No description has been provided for this image