def merge_equal_strings(string_dag: circuits.CircuitDag) -> None: for node in tuple(string_dag.nodes()): if node not in string_dag.nodes(): # Node was removed continue commuting_nodes = (set(string_dag.nodes()) - set(networkx.dag.ancestors(string_dag, node)) - set(networkx.dag.descendants(string_dag, node)) - set([node])) for other_node in commuting_nodes: if node.val.pauli_string.equal_up_to_sign( other_node.val.pauli_string): string_dag.remove_node(other_node) node.val = node.val.merged_with(other_node.val)
def remove_negligible_strings(string_dag: circuits.CircuitDag, tolerance=linalg.Tolerance.DEFAULT) -> None: for node in tuple(string_dag.nodes()): if tolerance.all_near_zero_mod(node.val.half_turns, 2): string_dag.remove_node(node)
def remove_negligible_strings(string_dag: circuits.CircuitDag, atol=1e-8) -> None: for node in tuple(string_dag.nodes()): if linalg.all_near_zero_mod(node.val.exponent_relative, 2, atol=atol): string_dag.remove_node(node)
def remove_negligible_strings(string_dag: circuits.CircuitDag, atol=DEFAULT_ATOL) -> None: for node in tuple(string_dag.nodes()): if all_near_zero_mod(node.val.half_turns, 2, atol=atol): string_dag.remove_node(node)