def is_valid_routing( circuit: circuits.Circuit, swap_network: SwapNetwork, *, equals: BINARY_OP_PREDICATE = operator.eq, can_reorder: BINARY_OP_PREDICATE = circuits.circuit_dag._disjoint_qubits, ) -> bool: """Determines whether a swap network is consistent with a given circuit. Args: circuit: The circuit. swap_network: The swap network whose validity is to be checked. equals: The function to determine equality of operations. Defaults to `operator.eq`. can_reorder: A predicate that determines if two operations may be reordered. """ circuit_dag = circuits.CircuitDag.from_circuit(circuit, can_reorder=can_reorder) logical_operations = swap_network.get_logical_operations() try: return cca.is_topologically_sorted(circuit_dag, logical_operations, equals) except ValueError as err: if re.match(r'Operation .* acts on unmapped qubit .*\.', str(err)): return False raise
def swap_network(self) -> SwapNetwork: return SwapNetwork(circuits.Circuit(self.physical_ops), self.initial_mapping)