mqt.qmap.ph.routing_to_phases¶
Utilities for converting routing masks to phase-shifter parameter grids.
Classes¶
Static routing constraints for a phase grid. |
Functions¶
|
Precompute phase sources and offsets from the mesh and routing states. |
|
Apply routing constraints while preserving gradients to their raw sources. |
|
Inflate a 1D parameter vector into a 2D phase-shifter grid. |
Module Contents¶
- class RoutingTransform[source]¶
Static routing constraints for a phase grid.
- source_mode¶
Raw phase source for each cell, including paired modes.
- offset¶
Fixed phase offset, either zero or pi.
- use_raw¶
Whether the effective phase includes a raw phase.
- precompute_routing_transform(movement_mask: torch.Tensor, optimize_routing_parameters: bool = False) RoutingTransform[source]¶
Precompute phase sources and offsets from the mesh and routing states.
A bar pair has phases differing by pi; a cross pair has equal phases. Routing pairs share one trainable phase when optimization is enabled. Virtual phase shifters use the raw phase of their active mode. Compute cells remain independent. Mixed pairs take the higher MaskState code.
- Parameters:
movement_mask – Integer grid of routing states, indexed by mode and layer.
optimize_routing_parameters – Whether routing pairs have a trainable phase.
- Returns:
Phase sources, offsets, and selectors to reuse during optimization.
- apply_routing_transform(raw_params: torch.Tensor, transform: RoutingTransform) torch.Tensor[source]¶
Apply routing constraints while preserving gradients to their raw sources.
- Parameters:
raw_params – Current phase grid.
transform – Precomputed routing constraints.
- Returns:
Effective phases. Autograd freezes constants and accumulates gradients from derived phases into their sources.
- reshape_flattened_params_to_grid(params_1d: torch.Tensor, num_modes: int, exclude_edge_phase_shifters: bool = False) torch.Tensor[source]¶
Inflate a 1D parameter vector into a 2D phase-shifter grid.
When
exclude_edge_phase_shiftersisTrue, the top-right and bottom-right corner positions are absent fromparams_1dand are padded with zero in the output grid.- Parameters:
params_1d – Flat parameter tensor of size
num_modes**2(ornum_modes**2 - 2when edge phase shifters are excluded).num_modes – Number of spatial modes on the chip.
exclude_edge_phase_shifters – If
True, the two corner entries are absent fromparams_1d.
- Returns:
Float tensor of shape
(num_modes, num_modes)with parameters placed at valid grid positions and zeros at excluded corners.- Raises:
ValueError – If the size of
params_1ddoes not match the expected count for the givennum_modesandexclude_edge_phase_shifterssetting.