Functions to operate on monomials

inflation.sdp.fast_npa.apply_source_perm(monomial: ndarray, source: int, permutation: ndarray) ndarray[source]

Apply a source swap to a monomial.

Parameters:
  • monomial (numpy.ndarray) – Input monomial in 2d array format.

  • source (int) – The source that is being swapped.

  • permutation (numpy.ndarray) – The permutation of the copies of the specified source. The format for the permutation here is to use indexing starting at one, so the permutation must be padded with a leading zero. The function inflation.sdp.quantum_tools.format_permutations converts a list of permutations to the necessary format.

Returns:

Input monomial with the specified source swapped.

Return type:

numpy.ndarray

inflation.sdp.fast_npa.dot_mon(mon1: ndarray, mon2: ndarray) ndarray[source]

Returns ((mon1)^dagger)*mon2.

For hermitian operators this is the same as reversed(mon1)*mon2. Since all parties commute, the output is ordered by parties. We do not assume any other commutation rules.

Parameters:
  • mon1 (numpy.ndarray) – Input monomial in 2d array format.

  • mon2 (numpy.ndarray) – Input monomial in 2d array format.

Returns:

The monomial ordered by parties.

Return type:

numpy.ndarray

Examples

>>> mon1 = np.array([[1,2,3],[4,5,6]])
>>> mon2 = np.array([[7,8,9]])
>>> dot_mon(mon1, mon2)
np.array([[4,5,6],[1,2,3],[7,8,9]])
inflation.sdp.fast_npa.nb_lexmon_to_canonical(lexmon: ndarray, notcomm: ndarray) ndarray[source]

Brings a monomial, input as the indices of the operators in the lexicographic ordering, to canonical form with respect to commutations.

Parameters:
  • lexmon (numpy.ndarray) – Monomial as an array of integers, where each integer represents the lexicographic order of an operator.

  • notcomm (numpy.ndarray) – Matrix of commutation relations, given in the format specified by inflation.sdp.fast_npa.commutation_matrix.

Returns:

Monomial in canonical form with respect to commutations.

Return type:

numpy.ndarray

inflation.sdp.fast_npa.mon_lexsorted(mon: ndarray, lexorder: ndarray) ndarray[source]

Sorts a monomial lexicographically.

Parameters:
  • mon (numpy.ndarray) – Input monomial in 2d array format.

  • lexorder (numpy.ndarray) – Matrix with rows as operators where the index of the row gives the lexicographic order of the operator.

Returns:

Sorted monomial.

Return type:

numpy.ndarray

inflation.sdp.fast_npa.reverse_mon(mon: ndarray) ndarray[source]

Return the reversed monomial.

This represents the Hermitian conjugate of the monomial, assuming that each operator is Hermitian.

Parameters:

mon (numpy.ndarray) – Input monomial in 2d array format.

Returns:

Reversed monomial.

Return type:

numpy.ndarray

Monomial properties

inflation.sdp.fast_npa.nb_is_knowable(monomial: ndarray) bool[source]

Determine whether a given atomic monomial admits an identification with a probability of the original scenario.

Parameters:

monomial (np.ndarray) – List of operators, denoted each by a list of indices

Returns:

Whether the monomial is knowable or not.

Return type:

bool

inflation.sdp.fast_npa.nb_is_physical(monomial_in: ndarray, sandwich_positivity=True) bool[source]

Determines whether a monomial is physical, this is, if it always has a non-negative expectation value.

This code also supports the detection of “sandwiches”, i.e., monomials of the form \(\langle \psi | A_1 A_2 A_1 | \psi \rangle\) where \(A_1\) and \(A_2\) do not commute. In principle we do not know the value of this term. However, note that \(A_1\) can be absorbed into \(| \psi \rangle\) forming an unnormalised quantum state \(| \psi' \rangle\), thus \(\langle\psi'|A_2|\psi'\rangle\). Note that while we know the value \(\langle\psi |A_2| \psi\rangle\), we do not know \(\langle \psi' | A_2 | \psi' \rangle\) because of the unknown normalisation, however we know it must be non-negative, \(\langle \psi | A_1 A_2 A_1 | \psi \rangle \geq 0\). This simple example can be extended to various layers of sandwiching.

Parameters:
  • monomial_in (numpy.ndarray) – Input monomial in 2d array format.

  • sandwich_positivity (bool, optional) – Whether to consider sandwiching. By default True.

Returns:

Whether the monomial has always non-negative expectation or not.

Return type:

bool

inflation.sdp.fast_npa.nb_all_commuting_q(mon: ndarray, lexorder: ndarray, notcomm: ndarray) bool[source]

Check if all operators in mon commute.

Parameters:
  • mon (numpy.ndarray) – Input monomial in 2d array format.

  • lexorder (numpy.ndarray) – A matrix where each row is an operator, and the i-th row stores the operator with lexicographic rank i.

  • notcomm (numpy.ndarray) – Matrix of commutation relations. Each operator can be identified by an integer i which also doubles as its lexicographic rank. Given two operators with ranks i, j, notcomm[i, j] is 1 if the operators do not commute, and 0 if they do.

Returns:

Return True if all operators commute, and False otherwise.

Return type:

bool

inflation.sdp.fast_npa.nb_exists_shared_source(inf_indices1: ndarray, inf_indices2: ndarray) bool[source]
Determine if there is any common source referred to by two

specifications of inflation (a.k.a. ‘copy’) indices.

Parameters:
  • inf_indices1 (numpy.ndarray) – An array of integers indicating which copy index of each source is being referenced.

  • inf_indices2 (numpy.ndarray) – An array of integers indicating which copy index of each source is being referenced.

Returns:

True if inf_indices1 and inf_indices2 share a source in common, False if they do not.

Return type:

bool

inflation.sdp.fast_npa.nb_lexorder_idx(operator: ndarray, lexorder: ndarray) int[source]

Return the unique integer corresponding to the lexicographic ordering of the operator. If operator is not found in lexorder, no value is returned.

Parameters:
  • operator (numpy.ndarray) – Array of integers representing the operator.

  • lexorder (numpy.ndarray) – Matrix with rows as operators where the index of the row gives the lexicographic ordering.

Returns:

The index of the operator in the lexorder matrix.

Return type:

int

Transformations of representation

inflation.sdp.fast_npa.nb_mon_to_lexrepr(mon: ndarray, lexorder: ndarray) array[source]

Convert a monomial to its lexicographic representation, in the form of an array of integers representing the lexicographic rank of each operator.

Parameters:
  • mon (numpy.ndarray) – Input monomial in 2d array format.

  • lexorder (numpy.ndarray) – Matrix with rows as operators where the index of the row gives the lexicographic order of the operator.

Returns:

Monomial as array of integers, where each integer is the hash of the corresponding operator.

Return type:

np.array

inflation.sdp.fast_npa.to_name(monomial: ndarray, names: List[str]) str[source]

Convert the 2d array representation of a monomial to a string.

Parameters:
  • monomial (numpy.ndarray) – Monomial as a matrix with each row being an integer array representing an operators.

  • names (List[str]) – List of party names.

Returns:

The string representation of the monomial.

Return type:

str

Examples

>>> to_name([[1 1,0,3], [4,1,2,6], [2,3,3,4]], ['a','bb','x','Z'])
'a_1_0_3*Z_1_2_6*bb_3_3_4'

Other functions

inflation.sdp.fast_npa.remove_projector_squares(mon: ndarray) ndarray[source]

Simplify the monomial by removing operator powers. This is because we assume projectors, P**2=P. This corresponds to removing duplicates of rows which are adjacent.

Parameters:

mon (numpy.ndarray) – Input monomial in 2d array format.

Returns:

Monomial with powers of operators removed.

Return type:

bool

inflation.sdp.fast_npa.commutation_matrix(lexorder: ndarray, sources_to_check_for_pairwise: ndarray, commuting=False) ndarray[source]

Build a matrix encoding of which operators commute according to the function nb_operators_commute. Rows and columns are indexed by operators, and each element is a 0 if the operators in the row and in the column commute or 1 if they do not.

Parameters:
  • lexorder (numpy.ndarray) – Matrix with rows as operators where the index of the row gives the lexicographic order of the operator.

  • quantum_sources (numpy.ndarray) – List of integers denoting the columns that in the 2D array encoding corresponding to inflation indices of quantum sources (as opposed to classical sources). Example: np.array([1, 3]) implies that the 1st and 3rd columns of an operator in 2D array form correspond to inflation indices that act on quantum sources.

  • sources_to_check_for_pairwise (numpy.ndarray) – A 3-index tensor boolean array which keep track of which pairs of parties have which quantum sources in common via intermediate quantum latents.

  • commuting (bool) – Whether all the monomials commute. In such a case, the trivial all-zero array is returned.

Returns:

Matrix whose entry \((i,j)\) has value 1 if the operators with lexicographic ordering \(i\) and \(j\) do not commute, and value 0 if they commute.

Return type:

numpy.ndarray

inflation.sdp.fast_npa.nb_classify_disconnected_components(adj_mat: ndarray) ndarray[source]

Given a boolean matrix where each cell indicates whether the supports of the operator denoting the row and the operator denoting the column overlap, generate a list determining to which disconnected component each operator belongs to.

Parameters:

adj_mat (numpy.ndarray) – Boolean 2d array where each cell indicates whether the supports of the operator denoting the row and the operator denoting the column overlap.

Returns:

A list of integers of size the number of operators used for creating adj_mat, where each integer indexes the disconnected component the corresponding operator belongs to.

Return type:

numpy.ndarray

inflation.sdp.fast_npa.nb_overlap_matrix(inflation_indxs: ndarray) ndarray[source]

Given a list of inflation indices for a number of operators, generate a boolean matrix whose entries denote whether the supports of the operator indexed by the row and of the operator indexed by the column overlap.

Parameters:

inflation_indxs (numpy.ndarray) – A list of inflation indices for a collection of operators.

Returns:

The “adjacency matrix” whose entries denote whether the supports of the operator indexed by the row and of the operator indexed by the column overlap.

Return type:

numpy.ndarray