def bfs_identity_search(gate_list, nqubits, max_depth=None, identity_only=False):
 if ((max_depth is None) or (max_depth <= 0)):
  max_depth = len(gate_list)
 id_only = identity_only
 queue = deque([()])
 ids = set()
 while (len(queue) > 0):
  current_circuit = queue.popleft()
  for next_gate in gate_list:
   new_circuit = (current_circuit + (next_gate,))
   circuit_reducible = is_reducible(new_circuit, nqubits, 1, len(new_circuit))
   if (is_scalar_matrix(new_circuit, nqubits, id_only) and (not is_degenerate(ids, new_circuit)) and (not circuit_reducible)):
    ids.add(GateIdentity(*new_circuit))
   elif ((len(new_circuit) < max_depth) and (not circuit_reducible)):
    queue.append(new_circuit)
 return ids

def bfs_identity_search ( gate_list , nqubits , max_depth = None , identity_only = False ) : if ( ( max_depth is None ) or ( max_depth <= 0 ) ) : max_depth = len ( gate_list ) id_only = identity_only queue = deque ( [ ( ) ] ) ids = set ( ) while ( len ( queue ) > 0 ) : current_circuit = queue . popleft ( ) for next_gate in gate_list : new_circuit = ( current_circuit + ( next_gate , ) ) circuit_reducible = is_reducible ( new_circuit , nqubits , 1 , len ( new_circuit ) ) if ( is_scalar_matrix ( new_circuit , nqubits , id_only ) and ( not is_degenerate ( ids , new_circuit ) ) and ( not circuit_reducible ) ) : ids . add ( GateIdentity ( * new_circuit ) ) elif ( ( len ( new_circuit ) < max_depth ) and ( not circuit_reducible ) ) : queue . append ( new_circuit ) return ids
constructs a set of gate identities from the list of possible gates .