merlin.pcvl_pytorch.utils module

Utilities for converting between various perceval and torch representations.

merlin.pcvl_pytorch.utils.pcvl_to_tensor(state_vector, computation_space=ComputationSpace.FOCK, dtype=torch.complex64, device=device(type='cpu'))

Convert a Perceval StateVector into a torch tensor.

Parameters:
  • state_vector (pcvl.StateVector) – Perceval state vector.

  • computation_space (merlin.core.computation_space.ComputationSpace) – Computation space of the state vector following combinadics ordering. Default is ComputationSpace.FOCK

  • dtype (torch.dtype) – Desired torch dtype of the output tensor. Default is torch.complex64.

  • device (torch.device) – Desired torch device of the output tensor. Default is torch.device("cpu").

Returns:

Equivalent torch tensor.

Return type:

torch.Tensor

Raises:

ValueError – If the state vector includes states with incompatible photon number for the specified computation space, or inconsistent photon numbers across the states.