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

PostSelect

class perceval.utils.postselect.PostSelect(str_repr=None)

PostSelect is a callable post-selection intended to filter out unwanted output states. It is designed to be a user-friendly description of any post-selection logic.

Parameters:

str_repr (Optional[str]) – string representation of the selection logic. The format is: “cond_1 & cond_2 & … & cond_n” where cond_i is “[mode list] <operator> <photon count>” (supported operators are ==, > and <)

Example:

>>> ps = PostSelect("[0,1] == 1 & [2] > 1") # Means "I want exactly one photon in mode 0 or 1, and at least one photon in mode 2"
>>> ps = PostSelect().eq([0,1], 1).gt(2, 1) # Same as above
>>> print(ps(BasicState([0, 1, 1])))
True
>>> print(ps(BasicState([1, 1, 1])))
False
__call__(state)

PostSelect is callable, with a post_select(BasicState) -> bool signature. Returns True if the input state validates all conditions, returns False otherwise.

Return type:

bool

apply_permutation(perm_vector, first_mode=0)

Apply a given permutation on the conditions.

Parameters:
  • perm_vector (List[int]) – Permutation vector to apply (as returned by PERM.perm_vector)

  • first_mode (int) – First mode of the permutation to apply (default 0)

Returns:

A PostSelect with the permutation applied

can_compose_with(modes)

Check if all conditions are compatible with a composition on given modes

Parameters:

modes (List[int]) – Modes used in the composition

Return type:

bool

Returns:

True if the composition is allowed without mixing conditions, False otherwise

clear()

Clear all existing conditions

eq(indexes, value)

Create a new “equals” condition for the current PostSelect instance

ge(indexes, value)

Create a new “greater or equal than” condition for the current PostSelect instance

gt(indexes, value)

Create a new “greater than” condition for the current PostSelect instance

property has_condition: bool

Returns True if at least one condition is defined

le(indexes, value)

Create a new “lower or equal than” condition for the current PostSelect instance

lt(indexes, value)

Create a new “lower than” condition for the current PostSelect instance

merge(other)

Merge with other PostSelect. Updates the current instance.

Parameters:

other – Another PostSelect instance

shift_modes(shift)

Shift all mode indexes inside this instance

Parameters:

shift (int) – Value to shift all mode indexes with