"""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 # 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)) # Start with the trivial cases gate_list = [x] bfs_identity_search(gate_list, 1, max_depth=2) gate_list = [y] bfs_identity_search(gate_list, 1, max_depth=2) # 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) gate_list = [x, y, z, h] bfs_identity_search(gate_list, 2) # 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) # 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) gate_list = [cnot, cgate_z, h] bfs_identity_search(gate_list, 2, max_depth=4)