Skip to content

Commit

Permalink
Update circuit_transpiler.py
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillermoAbadLopez committed Dec 30, 2024
1 parent cc56d71 commit 72c9c5d
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/qililab/digital/circuit_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,10 @@ def transpile_circuit(

# Routing stage;
if routing:
circuit, final_layout = self.route_circuit(circuit, placer, router, iterations=routing_iterations)
logger.info(f"The physical qubits used for the execution will be: {final_layout}")
gate_list, final_layout, nqubits = self.route_circuit(circuit, placer, router, routing_iterations)
else:
final_layout = {f"q{i}": i for i in range(circuit.nqubits)}

# Transpilation is done without constructing the Circuit class, from here onwards:
gate_list = circuit.queue
nqubits = circuit.nqubits
gate_list, nqubits = circuit.queue, circuit.nqubits
final_layout = {f"q{i}": i for i in range(nqubits)}

# Optimze qibo gates, cancelling redundant gates:
if optimize:
Expand All @@ -173,9 +169,9 @@ def route_circuit(
circuit: Circuit,
placer: Placer | type[Placer] | tuple[type[Placer], dict] | None = None,
router: Router | type[Router] | tuple[type[Router], dict] | None = None,
coupling_map: list[tuple[int, int]] | None = None,
iterations: int = 10,
) -> tuple[Circuit, dict[str, int]]:
coupling_map: list[tuple[int, int]] | None = None,
) -> tuple[list[gates.Gate], dict[str, int], int]:
"""Routes the virtual/logical qubits of a circuit to the physical qubits of a chip. Returns and logs the final qubit layout.
This process uses the provided `placer`, `router`, and `routing_iterations` parameters if they are passed; otherwise, default values are applied.
Expand Down Expand Up @@ -219,17 +215,16 @@ def route_circuit(
Args:
circuit (Circuit): circuit to route.
coupling_map (list[tuple[int, int]], optional): coupling map of the chip to route. This topology will be the one that rules,
which will overwrite any other in an instance of router or placer. Defaults to the platform topology.
placer (Placer | type[Placer] | tuple[type[Placer], dict], optional): `Placer` instance, or subclass `type[Placer]` to
use, with optionally, its kwargs dict (other than connectivity), both in a tuple. Defaults to `ReverseTraversal`.
router (Router | type[Router] | tuple[type[Router], dict], optional): `Router` instance, or subclass `type[Router]` to
use, with optionally, its kwargs dict (other than connectivity), both in a tuple. Defaults to `Sabre`.
iterations (int, optional): Number of times to repeat the routing pipeline, to keep the best stochastic result. Defaults to 10.
coupling_map (list[tuple[int, int]], optional): coupling map of the chip to route. This topology will be the one that rules,
which will overwrite any other in an instance of router or placer. Defaults to the platform topology.
Returns:
tuple[Circuit, dict[str, int]]: routed circuit, and final layout of the circuit {"qI": J}.
tuple[list[Gate], dict[str, int], int]: List of gates of the routed circuit, final layout of the circuit {"qI": J}, and number of qubits in the final circuit.
Raises:
ValueError: If StarConnectivity Placer and Router are used with non-star topologies.
Expand All @@ -238,7 +233,10 @@ def route_circuit(
topology = nx.Graph(coupling_map if coupling_map is not None else self.settings.topology)
circuit_router = CircuitRouter(topology, placer, router)

return circuit_router.route(circuit, iterations)
circuit, final_layout = circuit_router.route(circuit, iterations)
logger.info(f"The physical qubits used for the execution will be: {final_layout}")

return circuit.queue, final_layout, circuit.nqubits

@staticmethod
def optimize_gates(gate_list: list[gates.Gate]) -> list[gates.Gate]:
Expand Down

0 comments on commit 72c9c5d

Please sign in to comment.