DensityMatrix

class perceval.utils.density_matrix.DensityMatrix(mixed_state, index=None, m=None, n_max=None, check_hermitian=True, precision=1e-06)

Density operator representing a mixed state. Does not support annotations yet.

Parameters:
  • mixed_state (Union[array, sparray]) – 2d-array, SVDistribution, StateVector or Basic State representing a mixed state

  • index (Optional[FockBasis]) – index of all BasicStates accessible from this mixed states through a unitary evolution

  • m (Optional[int]) – optional number of modes if index is not given

  • n_max (Optional[int]) – optional maximum number of photon if index is not given

apply_loss(modes, prob)

Apply a loss on some mode according to some probability of losing a photon Everything works like if the mode was connected to some virtual mode with a beam splitter of reflectivity prob

Parameters:
  • modes (Union[int, list]) – the mode were you want to simulate a loss

  • prob (float) – the probability to lose a photon

static from_svd(svd, index=None)

Construct a Density matrix from a SVDistribution.

Parameters:

svd (Union[SVDistribution, StateVector, FockState]) – an SVDistribution object representing the mixed state :param index: the basis in which the density matrix is expressed. Self generated if incorrect :return: the DensityMatrix object corresponding to the SVDistribution given

measure(modes)

Makes a measure on a list of modes. :type modes: Union[List[int], int] :param modes: a list of integer for the modes you want to measure

normalize()

Normalize the density matrix so that Trace(rho) = 1

remove_low_amplitude(threshold=None)

Remove the lines and column where the amplitude is below a certain threshold

sample(count=1)

Sample a basic state on the density matrix

Return type:

BSSamples

to_svd(threshold=None, batch_size=1)

Gives back an SVDistribution from the density_matrix

Parameters:
  • threshold (Optional[float]) – the threshold when the search for eigen values is stopped.

  • batch_size (int) – the number of eigen values at each Arnoldi’s algorithm iteration. Only used if matrix is large enough.

Returns:

The SVD object corresponding to the DensityMatrix. The StateVector with probability < threshold are removed.