Skip to content

shortest_path_router

ShortestPathRouter

Bases: Router

Source code in opensquirrel/passes/router/shortest_path_router.py
class ShortestPathRouter(Router):
    def __init__(self, connectivity: Connectivity, **kwargs: Any) -> None:
        super().__init__(connectivity, **kwargs)

    def route(self, ir: IR, qubit_register_size: int) -> IR:
        """Route the input IR using the [shortest-path](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html)
        search algorithm.

        Args:
            ir (IR): The input IR to be routed.
            qubit_register_size (int): Size of the qubit register.

        Returns:
            The routed IR.

        """
        pathfinder: PathFinderType = nx.shortest_path
        return ProcessSwaps.process_swaps(ir, qubit_register_size, self._connectivity, pathfinder)

route

route(ir: IR, qubit_register_size: int) -> IR

Route the input IR using the shortest-path search algorithm.

Parameters:

Name Type Description Default
ir IR

The input IR to be routed.

required
qubit_register_size int

Size of the qubit register.

required

Returns:

Type Description
IR

The routed IR.

Source code in opensquirrel/passes/router/shortest_path_router.py
def route(self, ir: IR, qubit_register_size: int) -> IR:
    """Route the input IR using the [shortest-path](https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.generic.shortest_path.html)
    search algorithm.

    Args:
        ir (IR): The input IR to be routed.
        qubit_register_size (int): Size of the qubit register.

    Returns:
        The routed IR.

    """
    pathfinder: PathFinderType = nx.shortest_path
    return ProcessSwaps.process_swaps(ir, qubit_register_size, self._connectivity, pathfinder)