You're reading the documentation of the v0.11. For the latest released version, please have a look at v0.12.

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 (np.ndarray | sparray) – 2d-array, SVDistribution, StateVector or Basic State representing a mixed state

  • index (FockBasis | None) – index of all BasicStates accessible from this mixed states through a unitary evolution

  • m (int | None) – optional number of modes if index is not given

  • n_max (int | None) – 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 (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 (SVDistribution | StateVector | BasicState) – 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: 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 (float | None) – 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.