BSDistribution

class exqalibur.BSDistribution

Basic state distribution holding measured states (i.e. perfect Fock states), of the same size (number of modes).

The BSDistribution can be build via any of the following parameters:

Parameters:
  • fs – (optional) build from a single state which gets a probability of 1.

  • bsd – (optional) build from an existing dictionary or distribution. Keys have to be perfect Fock states.

  • fsa – (optional) a FSArray requiring a same size probability vector

  • probs – (optional) the probability vector working with parameter fsa

add(self: exqalibur.BSDistribution, fs: exqalibur.FockState, value: SupportsFloat) None

Increment the probability of a given state. If the state doesn’t exist beforehand, use the given probability. Probabilities that are too low (1e-16) are discarded.

Parameters:
  • fs – Fock state

  • value – Probability

get(self: exqalibur.BSDistribution, fs: exqalibur.FockState, default: SupportsFloat | None = None) float | None

Retrieve the probability for a given state, with a default value if the state doesn’t exist in the distribution.

Parameters:
  • fs – State to search

  • default – Default probability value (defaults to None)

Returns:

The state probability if found, the default value otherwise

group_modes_simplification(self: exqalibur.BSDistribution, group_size: SupportsInt) exqalibur.BSDistribution

Group modes by merging their contents in shorter states within the whole distribution.

This call can be used to perform coarse grain comparison between two very large distributions

Parameters:

group_size – Size of mode groups to consider (e.g. if 2, |1,1,3,4> gives |2,7>)

Returns:

The resulting distribution

items(self: exqalibur.BSDistribution) collections.abc.Iterator[tuple[exqalibur.FockState, float]]

Iterate over tuples of (Fock states, probability) contained in the distribution

keys(self: exqalibur.BSDistribution) collections.abc.Iterator[exqalibur.FockState]

Iterate over Fock states contained in the distribution

static list_tensor_product(distributions: collections.abc.Sequence[exqalibur.BSDistribution], merge_modes: bool = False, prob_threshold: SupportsFloat = 0.0) exqalibur.BSDistribution

Compute a series of tensor product between distributions

Parameters:
  • distributions – List of distributions

  • merge_modes – If True, resulting states will merge their modes (both distribution must contain states of the same size). Apply a standard tensor product otherwise (defaults to False)

  • prob_threshold – Threshold under which probabilities are discarded during the tensor product (defaults to 0., i.e. no probability is discarded).

Returns:

The result of the tensor product

property m
Returns:

The number of modes of all states in the distribution

normalize(self: exqalibur.BSDistribution) None

Normalize the probabilities in place (i.e. their sum is equal to 1)

photon_threshold_simplification(self: exqalibur.BSDistribution, photon_threshold: SupportsInt) exqalibur.BSDistribution

Applies a maximum photon per mode threshold to all states in the distribution.

Parameters:

photon_threshold – Max number of photons allowed per mode. Any bigger value will be changed to photon_threshold

Returns:

The thresholded distribution

sample(self: exqalibur.BSDistribution, count: SupportsInt, non_null: bool = True) exqalibur.BSSamples

Generate an ordered list of samples from the distribution.

Parameters:
  • count – Number of expected samples

  • non_null – If True avoids returning in void state (i.e. state containing 0 photon). Defaults to True.

Returns:

A list of samples following the probability distribution

static tensor_product(bsd1: exqalibur.BSDistribution, bsd2: exqalibur.BSDistribution, merge_modes: bool = False, prob_threshold: SupportsFloat = 0.0) exqalibur.BSDistribution

Compute the tensor product of two distributions

Parameters:
  • bsd1 – Left hand-side distribution

  • bsd2 – Right hand-side distribution

  • merge_modes – If True, resulting states will merge their modes (both distribution must contain states of the same size). Apply a standard tensor product otherwise (defaults to False)

  • prob_threshold – Threshold under which probabilities are discarded during the tensor product (defaults to 0., i.e. no probability is discarded).

Returns:

The result of the tensor product

values(self: exqalibur.BSDistribution) collections.abc.Iterator[float]

Iterate over the probabilities contained in the distribution

BSCount

class exqalibur.BSCount

Measured sample count data structure. For given states, holds a positive number of occurrence.

Parameters:

bscount – (optional) can be initialised from another BSCount or a dictionary in which all keys are of type FockState and all values are positive integers

add(self: exqalibur.BSCount, fs: exqalibur.FockState, value: SupportsInt) None

Increment the count of a given state. Zeroes are discarded.

Parameters:
  • fs – Fock state

  • value – Count to add

items(self: exqalibur.BSCount) exqalibur.ItemsView
keys(self: exqalibur.BSCount) exqalibur.KeysView
total(self: exqalibur.BSCount) int

Compute the total number of samples.

Returns:

the sum of occurrence of all contained states

values(self: exqalibur.BSCount) exqalibur.ValuesView

BSSamples

class exqalibur.BSSamples

Measured samples ordered container, suited to save a sample stream data acquisition.

It basically acts like a list.

append(self: exqalibur.BSSamples, x: exqalibur.FockState) None

Add an item to the end of the list

clear(self: exqalibur.BSSamples) None

Clear the contents

count(self: exqalibur.BSSamples, x: exqalibur.FockState) int

Return the number of times x appears in the list

extend(*args, **kwargs)

Overloaded function.

  1. extend(self: exqalibur.BSSamples, L: exqalibur.BSSamples) -> None

Extend the list by appending all the items in the given list

  1. extend(self: exqalibur.BSSamples, L: collections.abc.Iterable) -> None

Extend the list by appending all the items in the given list

insert(self: exqalibur.BSSamples, i: SupportsInt, x: exqalibur.FockState) None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: exqalibur.BSSamples) -> exqalibur.FockState

Remove and return the last item

  1. pop(self: exqalibur.BSSamples, i: typing.SupportsInt) -> exqalibur.FockState

Remove and return the item at index i

remove(self: exqalibur.BSSamples, x: exqalibur.FockState) None

Remove the first item from the list whose value is x. It is an error if there is no such item.