mqt.qmap.ph.subcircuit_compilation

Photonic MZI-mesh subcircuit compiler.

Classes

OptimizationConfig

Hyperparameters for the phase-shifter optimization.

CompilationResult

Output of a single compile_subcircuit() call.

Functions

compile_subcircuit(beam_splitter_reflectivities, ...) → CompilationResult

Compile a target unitary onto the chip and return the phases to program.

Module Contents

class OptimizationConfig[source]

Hyperparameters for the phase-shifter optimization.

lr

Initial Adam learning rate.

threshold

Fidelity-loss value below which optimization terminates early.

max_iterations

Maximum gradient steps.

exclude_edge_phase_shifters

If True, the two edge phase shifters are excluded from the parameter set.

optimize_routing_parameters

If True, routing MZI cells contribute a single trainable degree of freedom.

class CompilationResult[source]

Output of a single compile_subcircuit() call.

This is the end-user result of compiling a target unitary onto a physical chip. It carries everything needed to drive the hardware: the phase-shifter values to program, and the input/output ports the photons enter and leave on.

phases

Flat list of chip_dim ** 2 phase-shifter angles in column-major (layer-by-layer) order - every mode phase of layer 0, then every mode phase of layer 1, and so on. The value for spatial mode r in MZI layer c is at index c * chip_dim + r. These are the values to program onto the chip.

input_ports

Physical mode indices into which photons are injected (the lower mode of each dual-rail pair), length target_dim // 2.

output_ports

Physical mode indices of the computation zone where the output photons are measured, length target_dim.

loss

Fidelity loss of the returned phases.

compute_time

Elapsed seconds for routing and phase optimization.

compile_subcircuit(beam_splitter_reflectivities: list[float], input_transmissions: list[float], output_transmissions: list[float], target_unitary: torch.Tensor, config: OptimizationConfig | None = None) → CompilationResult[source]

Compile a target unitary onto the chip and return the phases to program.

chip_dim is derived from len(input_transmissions) and target_dim from target_unitary.shape[0].

The compiler searches for the optimal photon routing through the chip (the path minimizing overall photon loss, independent of the target operation) and then optimizes the phase-shifter parameters for that placement.

Parameters:
  • beam_splitter_reflectivities – Flat list of measured chip beam-splitter reflectivities ordered MZI-by-MZI as in/out pairs, layer by layer.

  • input_transmissions – Per-mode input transmission coefficients, a list of length chip_dim. Its length determines chip_dim.

  • output_transmissions – Per-mode output transmission coefficients, a list of length chip_dim.

  • target_unitary – Target unitary tensor of shape (target_dim, target_dim). Its first dimension determines target_dim.

  • config – Optimization hyperparameters. Defaults to OptimizationConfig with all defaults when None.

Returns:

A CompilationResult containing the flat phase-shifter list to program, the input/output ports, the final fidelity loss, and the compilation compute time.

Raises:

ValueError – If target_unitary is not a square, even-dimensioned, finite complex matrix with target_dim < chip_dim; if either transmission vector does not have exactly chip_dim finite values in [0, 1]; or if beam_splitter_reflectivities does not have exactly chip_dim * (chip_dim - 1) finite values in [0, 1]; or if no route has nonzero transmission.

Note

No hardware simulation is performed, so this step is suitable for chips too large to simulate classically.