mqt.qmap.ph.routing

Shortest-path routing and port inference for the photonic compiler.

Classes

MaskState

State codes for every (mode, layer) cell of the movement mask.

Functions

get_best_route(graph, layers) → tuple[list[int], float]

Find the minimum-cost route through the layered photonic DAG.

infer_input_and_output_ports(route, target_dim) → tuple[list[int], list[int]]

Infer the physical dual-rail input modes and output window from a route.

route_to_movement_mask(route, chip_dim, target_dim) → torch.Tensor

Convert a routing path to a movement mask for the phase optimizer.

Module Contents

class MaskState[source]

Bases: enum.IntEnum

State codes for every (mode, layer) cell of the movement mask.

The movement mask guides the phase optimizer: cells in routing layers are forced to implement bar or cross operations, while cells in the computation zone are free optimization parameters.

Initialize self. See help(type(self)) for accurate signature.

get_best_route(graph: rustworkx.PyDiGraph, layers: list) → tuple[list[int], float][source]

Find the minimum-cost route through the layered photonic DAG.

The routing graph carries all photonic semantics in its edge weights (-log fidelities set during graph.construct_graph()), so finding the placement is a plain shortest-path problem. Edge weights are >= 0 but include -log(1.0) == -0.0, which Dijkstra’s non-negativity check rejects, so Bellman-Ford is used.

Parameters:
  • graph – Weighted directed acyclic graph as produced by graph.construct_graph().

  • layers – Per-layer node index arrays as returned by graph.construct_graph().

Returns:

A tuple (relative_path_indices, final_cost) where relative_path_indices is the list of within-layer positions of each chosen node and final_cost is the total accumulated path cost. Returns ([], inf) if the sink is unreachable from the source.

infer_input_and_output_ports(route: list[int], target_dim: int) → tuple[list[int], list[int]][source]

Infer the physical dual-rail input modes and output window from a route.

Parameters:
  • route – Relative node indices from source to sink.

  • target_dim – Width of the computation zone.

Returns:

Input mode indices and output window indices.

Raises:

ValueError – If the route lacks input or output nodes.

route_to_movement_mask(route: list[int], chip_dim: int, target_dim: int) → torch.Tensor[source]

Convert a routing path to a movement mask for the phase optimizer.

The mask encodes the state of each (mode, layer) cell on the chip using MaskState values.

Parameters:
  • route – Relative-index path as returned by get_best_route().

  • chip_dim – Total number of spatial modes on the chip.

  • target_dim – Dimension of the target unitary.

Returns:

Integer tensor of shape (chip_dim, chip_dim) containing MaskState codes for every (mode, layer) position.

Raises:

ValueError – If the route contains a non-adjacent transition between consecutive layers (a step that is neither straight-through nor a move to an immediate neighbor), which cannot correspond to a valid routing-graph edge.