<h1>Gate Decomposition</h1>


```
%load_ext sympyprinting
```


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

<h2>Example 1</h2>

Create a symbolic controlled-Y gate


```
CY10 = CGate(1, Y(0)); CY10

```

Decompose it into elementary gates and plot it


```
CY10.decompose()

```


```
circuit_plot(CY10.decompose(), nqubits=2)
```

<h2>Example 2</h2>

Create a controlled-Z gate


```
CZ01 = CGate(0, Z(1)); CZ01

```

Decompose and plot it


```
CZ01.decompose()

```


```
circuit_plot(CZ01.decompose(), nqubits=2)
```

<h2>Example 3</h2>

Create a SWAP gate


```
SWAP10 = SWAP(1, 0); SWAP10

```

Decompose and plot it


```
SWAP10.decompose()
```


```
circuit_plot(SWAP10.decompose(), nqubits=2)
```

<h2>All together now</h2>


```
gates = [CGate(1,Y(0)), CGate(0,Z(1)), SWAP(1, 0)]
```


```
for g in gates:
    dg = g.decompose()
    display(Eq(g, dg))
    circuit_plot(g, nqubits=2)
    circuit_plot(dg, nqubits=2)    
```

1c68f34f27b24a426cdc28cf993fb86689ae6304
ipynb
Jupyter Notebook
docs/examples/notebooks/decompose.ipynb
tinyclues/ipython
71e32606b0242772b81c9be0d40751ba47d95f2c
BSD-3-Clause-Clear
2016-05-26T10:57:18.000Z
2016-05-26T10:57:18.000Z
docs/examples/notebooks/decompose.ipynb
adgaudio/ipython
a924f50c0f7b84127391f1c396326258c2b303e2
BSD-3-Clause-Clear
docs/examples/notebooks/decompose.ipynb
adgaudio/ipython
a924f50c0f7b84127391f1c396326258c2b303e2
BSD-3-Clause-Clear
Qwen/Qwen-72B
1. YES
2. YES