Fock States

Warning

The ordering of the Fock basis is increasing with particle numbers, and in each particle number conserving subspace, lexicographic ordering is used.

Example for 3 modes:

\[| 000 \rangle, | 001 \rangle, | 010 \rangle, | 100 \rangle, | 002 \rangle, | 011 \rangle, | 020 \rangle, | 101 \rangle, | 110 \rangle, | 200 \rangle \dots\]

General Fock State

class FockState(*, d: int, connector: BaseConnector, config: Config | None = None)

Object to represent a general bosonic state in the Fock basis.

Note

If you only work with pure states, it is advised to use PureFockState instead.

Parameters:
  • d (int) – The number of modes.

  • connector (BaseConnector) – Instance containing calculation functions.

  • config (Config) – Instance containing constants for the simulation.

reset() None

Resets the Fock state to a vacuum state.

classmethod from_fock_state(state: BaseFockState) FockState

Instantiation using another BaseFockState instance.

Parameters:

state (BaseFockState) – The instance from which a FockState instance is created.

property nonzero_elements: Generator[Tuple[complex, Tuple], Any, None]

The nonzero contributions to the state representation in Fock basis.

property density_matrix: ndarray

The density matrix of the state in the truncated Fock space.

get_particle_detection_probability(occupation_number: ndarray) float

Returns the particle number detection probability using the occupation number specified as a parameter.

Parameters:

occupation_number (tuple) – Tuple of natural numbers representing the number of particles in each mode.

Returns:

The probability of detection.

Return type:

float

property fock_probabilities: ndarray

Returns the particle detection probabilities.

Note

The ordering of the Fock basis is increasing with particle numbers, and in each particle number conserving subspace, lexicographic ordering is used.

Returns:

The particle detection probabilities.

Return type:

numpy.ndarray

property fock_probabilities_map: Dict[Tuple[int, ...], float]

The particle number detection probabilities in a map.

reduced(modes: Tuple[int, ...]) FockState

Reduces the state to a subsystem corresponding to the specified modes.

normalize() None

Normalizes the density matrix to have a trace of 1.

Raises:

RuntimeError – Raised if the current norm of the state is too close to 0.

validate() None

Validates the represented state.

Raises:

InvalidState – Raised, if the density matrix is not positive semidefinite, not self-adjoint or the trace of the density matrix is not 1.

quadratures_mean_variance(modes: Tuple[int, ...], phi: float = 0) Tuple[float, float]

This method calculates the mean and the variance of the qudrature operators for a single qumode state. The quadrature operators \(x\) and \(p\) for a mode \(i\) can be calculated using the creation and annihilation operators as follows:

\[\begin{split}x_i &= \sqrt{\frac{\hbar}{2}} (a_i + a_i^\dagger) \\ p_i &= -i \sqrt{\frac{\hbar}{2}} (a_i - a_i^\dagger).\end{split}\]

Let \(\phi \in [ 0, 2 \pi )\), we can rotate the quadratures using the following transformation:

\[Q_{i, \phi} = \cos\phi~x_i + \sin\phi~p_i.\]

The expectation value \(\langle Q_{i, \phi}\rangle\) can be calculated as:

\[\operatorname{Tr}(\rho_i Q_{i, \phi}),\]

where \(\rho_i\) is the reduced density matrix of the mode \(i\) and \(Q_{i, \phi}\) is the rotated quadrature operator for a single mode and the variance is calculated as:

\[\operatorname{\textit{Var}(Q_{i,\phi})} = \langle Q_{i, \phi}^{2}\rangle - \langle Q_{i, \phi}\rangle^{2}.\]
Parameters:
  • phi (float) – The rotation angle. By default it is 0 which means that the mean of the position operator is being calculated. For \(\phi= \frac{\pi}{2}\) the mean of the momentum operator is being calculated.

  • modes (tuple[int]) – The correspoding mode at which the mean of the quadratures are being calculated.

Returns:

A tuple that contains the expectation value and the

varianceof of the quadrature operator respectively.

Return type:

(float, float)

get_purity()

The purity of the Fock state.

copy() Self

Returns an exact copy of this state.

Returns:

An exact copy of this state.

Return type:

State

property d: int

The number of modes.

fidelity(state: BaseFockState) float

Calculates the state fidelity between two quantum states.

The state fidelity \(F\) between two density matrices \(\rho_1, \rho_2\) is given by:

\[\operatorname{F}(\rho_1, \rho_2) = \operatorname{Tr}(\sqrt{\sqrt{\rho_1} \rho_2\sqrt{\rho_1}})^2 = \operatorname{Tr}(\sqrt{\rho_1 \rho_2})^2\]
Parameters:

state – Either a PureFockState or a FockState that can be used to calculate the fidelity aganist it.

Returns:

The calculated fidelity.

Return type:

float

property fock_amplitudes_map: DefaultDict[tuple, complex]

Probability amplitudes of Fock basis states representing the state.

get_marginal_fock_probabilities(modes: Tuple[int, ...]) Dict[Tuple[int, ...], float]

Return the particle number probabilities on a given subsystem.

Parameters:

modes (tuple[int, ...]) – The indices of the modes to keep.

Returns:

The marginal particle number detection

probabilities, mapping occupation number tuples to their probabilities.

Return type:

Dict[Tuple[int, …], float]

plot_wigner(positions: List[float], momentums: List[float], mode: int | None = None) None

Plots the Wigner function in phase space for a single mode using the given positions and momentums.

Parameters:
  • positions (List[float]) – List of position values (x-axis)

  • momentums (List[float]) – List of momentum values (p-axis)

  • mode (int, optional) – Mode where Wigner function should be calculcated.

Note

Only a single mode is supported.

Returns:

This method generates a plot and does not return a value.

Return type:

None

wigner_function(positions: List[float], momentums: List[float], modes: Tuple[int, ...] | None = None) ndarray

This method calculates the Wigner function values at the specified position and momentum vectors, according to the following equation:

\[W(r) = \frac{1}{\pi^d \sqrt{\mathrm{det} \sigma}} \exp \big ( - (r - \mu)^T \sigma^{-1} (r - \mu) \big ).\]

Note

The implementation is copied from QuTiP.

Note

Only single modes are supported.

Parameters:
  • positions (list[float]) – List of position vectors.

  • momentums (list[float]) – List of momentum vectors.

  • modes (tuple[int], optional) – Modes where Wigner function should be calculcated.

Returns:

The Wigner function values in the shape of a grid specified by the input.

Return type:

numpy.ndarray

Pure Fock State

class PureFockState(*, d: int, connector: BaseConnector, config: Config | None = None)

A simulated pure Fock state.

If no mixed states are needed for a Fock simulation, then this state is the most appropriate currently, since it does not store an entire density matrix, only a state vector with size

\[{d + c - 1 \choose c - 1},\]

where \(c \in \mathbb{N}\) is the Fock space cutoff.

You can index this state to obtain the Fock basis coefficients of its state vector, for example:

with pq.Program() as program:
    pq.Q() | pq.StateVector([0, 1]) / 2

    pq.Q() | pq.StateVector([0, 2]) / 2
    pq.Q() | pq.StateVector([1, 1]) / np.sqrt(2)

simulator = pq.PureFockSimulator(d=2, config=pq.Config(cutoff=3))
state = simulator.execute(program).state  # returns PureFockState instance

state[0, 1]  # returns 0.5
state[:, 1]  # returns [0.5, 0.70710678]
Variables:

state_vector – The state vector of the quantum state, where the ordering of the Fock basis is increasing with particle numbers, and in each particle number conserving subspace, lexicographic ordering is used.

Parameters:
  • d (int) – The number of modes.

  • connector (BaseConnector) – Instance containing calculation functions.

  • config (Config) – Instance containing constants for the simulation.

reset() None

Resets the Fock state to a vacuum state.

property nonzero_elements

The nonzero contributions to the state representation in Fock basis.

property density_matrix: ndarray

The density matrix of the state in the truncated Fock space.

reduced(modes: Tuple[int, ...]) FockState

Reduces the state to a subsystem corresponding to the specified modes.

get_particle_detection_probability(occupation_number: ndarray) float

Returns the particle number detection probability using the occupation number specified as a parameter.

Parameters:

occupation_number (tuple) – Tuple of natural numbers representing the number of particles in each mode.

Returns:

The probability of detection.

Return type:

float

property fock_probabilities: ndarray

Returns the particle detection probabilities.

Note

The ordering of the Fock basis is increasing with particle numbers, and in each particle number conserving subspace, lexicographic ordering is used.

Returns:

The particle detection probabilities.

Return type:

numpy.ndarray

property fock_probabilities_map: Dict[Tuple[int, ...], float]

The particle number detection probabilities in a map.

normalize() None

Normalizes the state to have norm 1.

validate() None

Validates the represented state.

Raises:

InvalidState – Raised, if the norm of the state vector is not close to 1.0.

quadratures_mean_variance(modes: Tuple[int, ...], phi: float = 0) Tuple[float, float]

This method calculates the mean and the variance of the qudrature operators for a single qumode state. The quadrature operators \(x\) and \(p\) for a mode \(i\) can be calculated using the creation and annihilation operators as follows:

\[\begin{split}x_i &= \sqrt{\frac{\hbar}{2}} (a_i + a_i^\dagger) \\ p_i &= -i \sqrt{\frac{\hbar}{2}} (a_i - a_i^\dagger).\end{split}\]

Let \(\phi \in [ 0, 2 \pi )\), we can rotate the quadratures using the following transformation:

\[Q_{i, \phi} = \cos\phi~x_i + \sin\phi~p_i.\]

The expectation value \(\langle Q_{i, \phi}\rangle\) can be calculated as:

\[\operatorname{Tr}(\rho_i Q_{i, \phi}),\]

where \(\rho_i\) is the reduced density matrix of the mode \(i\) and \(Q_{i, \phi}\) is the rotated quadrature operator for a single mode and the variance is calculated as:

\[\operatorname{\textit{Var}(Q_{i,\phi})} = \langle Q_{i, \phi}^{2}\rangle - \langle Q_{i, \phi}\rangle^{2}.\]
Parameters:
  • phi (float) – The rotation angle. By default it is 0 which means that the mean of the position operator is being calculated. For \(\phi= \frac{\pi}{2}\) the mean of the momentum operator is being calculated.

  • modes (tuple[int]) – The correspoding mode at which the mean of the quadratures are being calculated.

Returns:

A tuple that contains the expectation value and the

varianceof of the quadrature operator respectively.

Return type:

(float, float)

mean_photon_number()

Returns the mean photon number

\[\mathbb{E}_{\ket{\psi}}(\hat{n}) := \bra{\psi} \hat{n} \ket{\psi},\]

where \(\hat{n}\) is the total photon number operator.

variance_photon_number()

Returns the photon number variance

\[\operatorname{Var}_{\ket{\psi}}(\hat{n}) := \bra{\psi} (\hat{n} - \bar{n})^2 \ket{\psi},\]

where \(\hat{n}\) is the total photon number operator and \(\bar{n}\) is its expectation value given by mean_photon_number().

copy() PureFockState

Returns an exact copy of this state.

Returns:

An exact copy of this state.

Return type:

State

get_purity()

The purity of the Fock state.

property d: int

The number of modes.

fidelity(state: BaseFockState) float

Calculates the state fidelity between two quantum states.

The state fidelity \(F\) between two density matrices \(\rho_1, \rho_2\) is given by:

\[\operatorname{F}(\rho_1, \rho_2) = \operatorname{Tr}(\sqrt{\sqrt{\rho_1} \rho_2\sqrt{\rho_1}})^2 = \operatorname{Tr}(\sqrt{\rho_1 \rho_2})^2\]
Parameters:

state – Either a PureFockState or a FockState that can be used to calculate the fidelity aganist it.

Returns:

The calculated fidelity.

Return type:

float

property fock_amplitudes_map: DefaultDict[tuple, complex]

Probability amplitudes of Fock basis states representing the state.

get_marginal_fock_probabilities(modes: Tuple[int, ...]) Dict[Tuple[int, ...], float]

Return the particle number probabilities on a given subsystem.

Parameters:

modes (tuple[int, ...]) – The indices of the modes to keep.

Returns:

The marginal particle number detection

probabilities, mapping occupation number tuples to their probabilities.

Return type:

Dict[Tuple[int, …], float]

plot_wigner(positions: List[float], momentums: List[float], mode: int | None = None) None

Plots the Wigner function in phase space for a single mode using the given positions and momentums.

Parameters:
  • positions (List[float]) – List of position values (x-axis)

  • momentums (List[float]) – List of momentum values (p-axis)

  • mode (int, optional) – Mode where Wigner function should be calculcated.

Note

Only a single mode is supported.

Returns:

This method generates a plot and does not return a value.

Return type:

None

wigner_function(positions: List[float], momentums: List[float], modes: Tuple[int, ...] | None = None) ndarray

This method calculates the Wigner function values at the specified position and momentum vectors, according to the following equation:

\[W(r) = \frac{1}{\pi^d \sqrt{\mathrm{det} \sigma}} \exp \big ( - (r - \mu)^T \sigma^{-1} (r - \mu) \big ).\]

Note

The implementation is copied from QuTiP.

Note

Only single modes are supported.

Parameters:
  • positions (list[float]) – List of position vectors.

  • momentums (list[float]) – List of momentum vectors.

  • modes (tuple[int], optional) – Modes where Wigner function should be calculcated.

Returns:

The Wigner function values in the shape of a grid specified by the input.

Return type:

numpy.ndarray