In [1]:
"""Demonstration of quantum gate identity search."""
from sympy.physics.quantum.gate import (X, Y, Z, H, S, T, CNOT,
IdentityGate, CGate, gate_simp)
from sympy.physics.quantum.identitysearch import *
from sympy.physics.quantum.dagger import Dagger
In [2]:
# Declare a few quantum gates
x = X(0)
y = Y(0)
z = Z(0)
h = H(0)
cnot = CNOT(1,0)
cgate_z = CGate((0,), Z(1))
In [6]:
# Start with the trivial cases
gate_list = [x]
bfs_identity_search(gate_list, 1, max_depth=2)
Out[6]:
In [7]:
gate_list = [y]
bfs_identity_search(gate_list, 1, max_depth=2)
Out[7]:
In [9]:
# bfs_identity_search looks for circuits that reduce to a
# scalar value unless told otherwise.
# The following list should produce 4 identities as a result.
gate_list = [x, y, z]
bfs_identity_search(gate_list, 2)
Out[9]:
In [10]:
gate_list = [x, y, z, h]
bfs_identity_search(gate_list, 2)
Out[10]:
In [12]:
# One has the option to limit the max size of the circuit.
# The default size is the size of the gate list.
bfs_identity_search(gate_list, 2, max_depth=3)
Out[12]:
In [13]:
# One also has the option to find circuits that only reduce
# to the Identity matrix rather than only scalar matrices.
bfs_identity_search(gate_list, 2, identity_only=True)
Out[13]:
In [14]:
gate_list = [cnot, cgate_z, h]
bfs_identity_search(gate_list, 2, max_depth=4)
Out[14]: