merlin.measurement.photon_loss module

Photon loss utilities let you incorporate Perceval NoiseModel instances directly inside a pcvl.Experiment. The resulting QuantumLayer automatically inserts a PhotonLossTransform before any detector mapping, expanding the classical basis with loss outcomes whilst keeping probability normalisation intact.

class merlin.measurement.photon_loss.PhotonLossTransform(simulation_keys, survival_probs, *, dtype=None, device=None)

Bases: Module

Linear map applying per-mode photon loss to a Fock probability vector.

Parameters:
  • simulation_keys (Sequence[Sequence[int]] | torch.Tensor) – Raw Fock states produced by the simulator.

  • survival_probs (Sequence[float]) – One survival probability per optical mode.

  • dtype (torch.dtype | None) – Torch dtype for the transform matrix. Defaults to torch.float32.

  • device (torch.device | str | None) – Device used to stage the transform matrix.

forward(distribution)

Apply the photon-loss transform to a Fock probability vector.

Parameters:

distribution (torch.Tensor) – Fock probability vector.

Returns:

Probability vector after photon loss as a 1D torch tensor.

Return type:

torch.Tensor

property is_identity: bool

Whether the transform corresponds to perfect transmission.

property output_keys: list[tuple[int, ...]]

Classical Fock keys after photon loss.

property output_size: int

Number of classical outcomes after photon loss.

Type:

int

to(*args, **kwargs)

Move the transform to a new device or dtype.

Parameters:
Returns:

Updated transform instance.

Return type:

PhotonLossTransform

merlin.measurement.photon_loss.resolve_photon_loss(experiment, n_modes)

Resolve photon loss from the experiment’s noise model.

Parameters:
  • experiment (pcvl.Experiment) – Quantum experiment carrying the noise model.

  • n_modes (int) – Number of photonic modes to cover.

Returns:

Per-mode survival probabilities and a flag indicating whether an effective noise model was provided.

Return type:

tuple[list[float], bool]