##// END OF EJS Templates
Updating examples notebooks.
Updating examples notebooks.

File last commit:

r4337:0f16a103
r4337:0f16a103
Show More
gate_rules.ipynb
1 line | 2.3 KiB | text/plain | TextLexer

Gate rules and circuit simplification

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
from sympy.physics.quantum.gaterules import *

The computational cost of a quantum algorithm is related to the number of gates in the circuit that implements that algorithm. Just like a classical computer, we would like to reduce the computational cost by optimizing the circuit. This can be done by searching for relationships (or "rules") between gates. Many such rules exist, but so far, there has been little work done to find, classify and use these rules in a systematic way.

SymPy's symbolic capabilities are perfect for this work as we don't have to represent the gates as $2^N\times2^N$ dimensional matrices.

Find circuits equivalent to the Hadamard gate

In [3]:
h0 = match_gate_rules(H(0))
for rule in h0:
    display(Eq(H(0),rule))

Find circuits equivalent to the Z gate

In [4]:
z0 = match_gate_rules(Z(0))
for rule in z0:
    display(Eq(Z(0),rule))

Find circuits equivalent to the X gate

In [5]:
x0 = match_gate_rules(X(0))
for rule in x0:
    display(Eq(X(0),rule))

Display a CNOT gate

In [6]:
circuit_plot(CNOT(1,0), nqubits=2)

Find and display a circuit equivalent to the CNOT gate

In [7]:
c10 = match_gate_rules(CNOT(1,0))
In [8]:
circuit_plot(c10[8], nqubits=2)
In [16]:
%notebook save gate_rules.ipynb
In [25]: