Boson Sampling State

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

A state dedicated for Boson Sampling (or related) simulations.

When using SamplingSimulator, the simulation results will contain an instance of this class, containing the input occupation numbers and the interferometer to be applied.

Example usage:

>>> import piquasso as pq
>>>
>>> from scipy.stats import unitary_group
>>>
>>> d = 7
>>>
>>> interferometer_matrix = unitary_group.rvs(d)
>>>
>>> with pq.Program() as program:
>>>     pq.Q(all) | pq.StateVector([1, 1, 1, 0, 0, 0, 0])
>>>     pq.Q(all) | pq.Interferometer(interferometer_matrix)
>>>     pq.Q(all) | pq.ParticleNumberMeasurement()
>>>
>>> simulator = pq.SamplingSimulator(d=d)
>>>
>>> result = simulator.execute(program, shots=3)
>>>
>>> result.samples
[(0, 0, 0, 0, 2, 1, 0), (3, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 0, 2, 1)]
Parameters:
  • d (int) – The number of modes.

  • connector (BaseConnector) – Instance containing calculation functions.

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

interferometer

The interferometer matrix corresponding to the circuit.

is_lossy

Returns True if the state is lossy, otherwise False.

validate() None

Validates the current state.

Raises:

InvalidState – If the interferometer matrix is non-unitary, or the input state is invalid.

property d

The number of modes.

property norm

The norm of the state.

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 state_vector

The state vector representation of this state.

This implementation follows Algorithm 1 (SLOS_full) from Strong Simulation of Linear Optical Processes.

property density_matrix: ndarray

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

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