DensityMatrix

An other way of representing mixed states is through the Density Matrices formalism. You can create a density matrix from any 2-D array-like object and a mapping between the BasicStates and the indices of your array. Otherwise you can give a number of modes and photons and a mapping will be generated according to the FockBasis object. The easiest way to generate Density matrices remains to give any other quantum state class instance to the method from_svd().

Many of the above methods extends to Density Matrices, such as sample and measure. This class is also suited for non unitary evolution of the state. For example, the apply_loss method is already build-in to simulate the probabilistic loss of photons. It is also handled by the simulator for unitary evolutions with the method evolve_density_matrix.

The pdisplay() function also allows to easily see the coherence of your state by highlighting the non diagonal coefficients. For example, here is the resulting density matrix when we try to create a bell state with a Post-Selected CNOT:

../../_images/bell.svg

And below, the result of the same circuit, but with a noisy Source. We can see the presence of FockStates with a smaller number of photons.

../../_images/bell_noisy.svg
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.

Parameters:

modes (list[int] | int) – 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.