dqcnac.local_routing.basic_router module
Basic router class module.
- class dqcnac.local_routing.basic_router.BasicRouter(coupling_map: qiskit.transpiler.CouplingMap, ebits: List[int], initial_layout: qiskit.transpiler.Layout, network_to_local: Dict[str, Dict[int, int]], reg_to_node: Dict[qiskit.circuit.Qubit, str], couplings: Dict[str, qiskit.transpiler.CouplingMap])[source]
Bases:
objectPerform routing of a DAGCircuit with remote gates onto a coupling_map adding swap gates. When a cz is does not comply with the coupling map, insert one or more swaps in front (on the shortest path) to make it compatible.
- __init__(coupling_map: qiskit.transpiler.CouplingMap, ebits: List[int], initial_layout: qiskit.transpiler.Layout, network_to_local: Dict[str, Dict[int, int]], reg_to_node: Dict[qiskit.circuit.Qubit, str], couplings: Dict[str, qiskit.transpiler.CouplingMap])[source]
BasicSwap initializer.
- Parameters:
coupling_map (CouplingMap) – Directed graph represented the coupling map of the network.
ebits (list) – list of ebits in the coupling map
initial_layout (Layout) – initial layout
network_to_local (dict) – dictionary mapping qubits in the network to qubits on the nodes
reg_to_node (dict) – dictionary mapping circuit register to nodes
couplings (dict) – dictionary mapping nodes to their coupling map
- dijkstra_shortest_path(coupling: qiskit.transpiler.CouplingMap, initial: int, end: int) List[int][source]
Use dijkstra algorithm to compute the shortest path between two nodes in a graph
- Parameters:
coupling – the graph
initial – the source node
end – the target node
- Returns:
the shortest path
- distance(local_map: qiskit.transpiler.CouplingMap, node: str, p1: int, p2: int) int[source]
Compute the distance between two qubits in a coupling map
- Parameters:
local_map – the coupling map
node – the network node to which the qubits pertains
p1 – the first qubit
p2 – the second qubit
- Returns:
the distance between the qubits
- is_ebit(q: int | qiskit.circuit.Qubit, layout) bool[source]
Check if a qubit is an ebit
- Parameters:
q – qubit to check
layout – layout of the circuit
- Returns:
True if qubit is an ebit, False otherwise
- static multi_qubit_ops(dag: qiskit.dagcircuit.DAGCircuit) List[qiskit.dagcircuit.DAGNode][source]
Get a list of 2 qubit operations. Ignore directives like snapshot and barrier.
- Parameters:
dag – the circuit
- Returns:
a list of two qubit gates in the circuit
- run(dag: qiskit.dagcircuit.DAGCircuit) Tuple[qiskit.dagcircuit.DAGCircuit, qiskit.transpiler.Layout][source]
Inserts swap ro route a circuit on a coupling map
- Parameters:
dag – the circuit
- Returns:
the routed circuit and the final mapping
- shortest_undirected_path(coupling_map: qiskit.transpiler.CouplingMap, physical_qubit1: int, physical_qubit2: int) List[int][source]
Compute the shortest undirected path between two physical qubits
- Parameters:
coupling_map – the coupling map
physical_qubit1 – the first physical qubit
physical_qubit2 – the second physical qubit
- Returns:
the path from physical qubit1 to physical qubit2