InflationSDP Class

class inflation.InflationSDP(inflationproblem: InflationProblem, supports_problem: bool = False, include_all_outcomes: bool = False, commuting: bool = False, verbose: int | None = None)[source]

Class for generating and solving an SDP relaxation for quantum inflation.

build_columns(column_specification: str | List[List[int]] | List[Symbol], max_monomial_length: int = 0, symbolic: bool = False) List[ndarray][source]

Creates the objects indexing the columns of the moment matrix from a specification.

Parameters:
  • column_specification (Union[str, List[List[int]], List[sympy.core.symbol.Symbol]]) – See description in the self.generate_relaxation() method.

  • max_monomial_length (int, optional) – Maximum number of letters in a monomial in the generating set, By default 0. Example: if we choose "local1" for three parties, it gives the set \(\{1, A, B, C, AB, AC, BC, ABC\}\). If we set max_monomial_length=2, the generating set is instead \(\{1, A, B, C, AB, AC, BC\}\). By default 0 (no limit).

  • symbolic (bool, optional) – If True, it returns the columns as a list of sympy symbols parsable by InflationSDP.generate_relaxation(). By default False.

certificate_as_probs(clean: bool = True, chop_tol: float = 1e-10, round_decimals: int = 3) Add[source]

Give certificate as symbolic sum of probabilities. The certificate of incompatibility is cert < 0.

If the certificate is evaluated on a point giving a negative value, this guarantees that the compatibility test for the same point is infeasible provided the set of constraints of the program does not change. Warning: when using use_lpi_constraints=True the set of constraints depends on the specified distribution, thus the certificate is not guaranteed to apply.

Parameters:
  • clean (bool, optional) – If True, eliminate all coefficients that are smaller than chop_tol, normalise and round to the number of decimals specified by round_decimals. By default True.

  • chop_tol (float, optional) – Coefficients in the dual certificate smaller in absolute value are set to zero. By default 1e-10.

  • round_decimals (int, optional) – Coefficients that are not set to zero are rounded to the number of decimals specified. By default 3.

Returns:

The expression of the certificate in terms of probabilities and marginals. The certificate of incompatibility is cert < 0.

Return type:

sympy.core.add.Add

certificate_as_string(clean: bool = True, chop_tol: float = 1e-10, round_decimals: int = 3) str[source]

Give the certificate as a string of a sum of probabilities. The expression is in the form such that its satisfaction implies incompatibility.

If the certificate is evaluated on a point giving a negative value, this guarantees that the compatibility test for the same point is infeasible provided the set of constraints of the program does not change. Warning: when using use_lpi_constraints=True the set of constraints depends on the specified distribution, thus the certificate is not guaranteed to apply.

Parameters:
  • clean (bool, optional) – If True, eliminate all coefficients that are smaller than chop_tol, normalise and round to the number of decimals specified by round_decimals. By default, True.

  • chop_tol (float, optional) – Coefficients in the dual certificate smaller in absolute value are set to zero. By default, 1e-10.

  • round_decimals (int, optional) – Coefficients that are not set to zero are rounded to the number of decimals specified. By default, 3.

Returns:

The certificate in terms of probabilities and marginals. The certificate of incompatibility is cert < 0.

Return type:

str

evaluate_certificate(prob_array: ndarray) float[source]

Evaluate the certificate of infeasibility in a target probability distribution. If the evaluation is a negative value, the distribution is not compatible with the causal structure. Warning: when using use_lpi_constraints=True the set of constraints depends on the specified distribution, thus the certificate is not guaranteed to apply.

Parameters:

prob_array (numpy.ndarray) – Multidimensional array encoding the distribution, which is called as prob_array[a,b,c,...,x,y,z,...] where \(a,b,c,\dots\) are outputs and \(x,y,z,\dots\) are inputs. Note: even if the inputs have cardinality 1 they must be specified, and the corresponding axis dimensions are 1. The parties’ outcomes and measurements must appear in the same order as specified by the order parameter in the InflationProblem used to instantiate InflationLP.

Returns:

The evaluation of the certificate of infeasibility in prob_array.

Return type:

float

generate_relaxation(column_specification: str | List[List[int]] | List[Symbol] = 'npa1') None[source]

Creates the SDP relaxation of the quantum inflation problem using the NPA hierarchy and applies the symmetries inferred from inflation.

It takes as input the generating set of monomials \(\{M_i\}_i\). The moment matrix \(\Gamma\) is defined by all the possible inner products between these monomials:

\[\Gamma[i, j] := \operatorname{tr} (\rho \cdot M_i^\dagger M_j).\]

The set \(\{M_i\}_i\) is specified by the parameter column_specification.

In the inflated graph there are many symmetries coming from invariance under swaps of the copied sources, which are used to remove variables in the moment matrix.

Parameters:

column_specification (Union[str, List[List[int]], List[sympy.core.symbol.Symbol]]) –

Describes the generating set of monomials \(\{M_i\}_i\).

  • (str) "npaN": where N is an integer. This represents level N in the Navascues-Pironio-Acin hierarchy (arXiv:quant-ph/0607119). For example, level 3 with measurements \(\{A, B\}\) will give the set \(\{1, A, B, AA, AB, BB, AAA, AAB, ABB, BBB\}\) for all inflation, input and output indices. This hierarchy is known to converge to the quantum set for \(N\rightarrow\infty\).

  • (str) "localN": where N is an integer. Local level N considers monomials that have at most N measurement operators per party. For example, local1 is a subset of npa2; for two parties, npa2 is \(\{1, A, B, AA, AB, BB\}\) while local1 is \(\{1, A, B, AB\}\).

  • (str) "physicalN": The subset of local level N with only operators that have non-negative expectation values with any state. N cannot be greater than the smallest number of copies of a source in the inflated graph. For example, in the scenario A-source-B-source-C with 2 outputs and no inputs, physical2 only gives 5 possibilities for B: \(\{1, B^{1,1}_{0|0}, B^{2,2}_{0|0}, B^{1,1}_{0|0}B^{2,2}_{0|0}, B^{1,2}_{0|0}B^{2,1}_{0|0}\}\). There are no other products where all operators commute. The full set of physical generating monomials is built by taking the cartesian product between all possible physical monomials of each party.

  • List[List[int]]: This encodes a party block structure. Each integer encodes a party. Within a party block, all missing input, output and inflation indices are taken into account. For example, [[], [0], [1], [0, 1]] gives the set \(\{1, A, B, AB\}\), which is the same as local1. The set [[], [0], [1], [2], [0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]] is the same as \(\{1, A, B, C, AA, AB, AC, BB, BC, CC\}\), which is the same as npa2 for three parties. [[]] encodes the identity element.

  • List[sympy.core.symbol.Symbol]: one can also fully specify the generating set by giving a list of symbolic operators built from the measurement operators in InflationSDP.measurements. This list needs to have the identity sympy.S.One as the first element.

reset(which: str | List[str] = 'all') None[source]

Reset the various user-specifiable objects in the inflation SDP.

Parameters:

which (Union[str, List[str]]) – The objects to be reset. It can be fed as a single string or a list of them. Options include "bounds", "lowerbounds", "upperbounds", "objective", "values", and "all".

set_bounds(bounds: dict | None, bound_type: str = 'up') None[source]

Set numerical lower or upper bounds on the moments generated in the SDP relaxation. The bounds are at the level of the SDP variables, and do not take into consideration non-convex constraints. E.g., two individual lower bounds, \(p_A(0|0) \geq 0.1\) and \(p_B(0|0) \geq 0.1\) do not directly impose the constraint \(p_A(0|0)*p_B(0|0) \geq 0.01\), which should be set manually if needed.

Parameters:
  • bounds (Union[dict, None]) – A dictionary with keys as monomials and values being the bounds. The keys can be either CompoundMonomial objects, or names (str) of Monomial objects.

  • bound_type (str, optional) – Specifies whether we are setting upper ("up") or lower ("lo") bounds, by default “up”.

Examples

>>> set_bounds({"pAB(00|00)": 0.2}, "lo")
set_distribution(prob_array: ndarray | None, use_lpi_constraints=False, shared_randomness=False) None[source]

Set numerically all the knowable (and optionally semiknowable) moments according to the probability distribution specified.

Parameters:
  • prob_array (numpy.ndarray) – Multidimensional array encoding the distribution, which is called as prob_array[a,b,c,...,x,y,z,...] where \(a,b,c,\dots\) are outputs and \(x,y,z,\dots\) are inputs. Note: even if the inputs have cardinality 1 they must be specified, and the corresponding axis dimensions are 1. The parties’ outcomes and measurements must be appear in the same order as specified by the order parameter in the InflationProblem used to instantiate InflationSDP.

  • use_lpi_constraints (bool, optional) – Specification whether linearized polynomial constraints (see, e.g., Eq. (D6) in arXiv:2203.16543) will be imposed or not. By default False.

  • shared_randomness (bool, optional) – Specification whether higher order monomials may be calculated. If universal shared randomness is present (i.e., the flag is True), only atomic monomials are assigned numerical values.

set_objective(objective: Expr | dict | None, direction: str = 'max') None[source]

Set or change the objective function of the polynomial optimization problem.

Parameters:
  • objective (Union[sp.core.expr.Expr, dict, None]) – The objective function, either as a combination of sympy symbols, as a dictionary with keys the moments or their names, and as values the corresponding coefficients, or None for clearing a previous objective.

  • direction (str, optional) – Direction of the optimization ("max"/"min"). By default "max".

set_values(values, **kwargs)[source]

Exactly like update_values, except it resets all known values to zero as an intermediate step

solve(interpreter='MOSEKFusion', feas_as_optim=False, solve_dual=True, solverparameters=None, solver_arguments={}, verbose: int = -1) None[source]

Call a solver on the SDP relaxation. Upon successful solution, it returns the primal and dual objective values along with the solution matrices.

Parameters:
  • interpreter (str, optional) – The solver to be called. By default "MOSEKFusion".

  • feas_as_optim (bool, optional) –

    Instead of solving the feasibility problem

    \((1) \text{ find vars such that } \Gamma \succeq 0\)

    setting this label to True solves instead the problem

    \((2) \text{ max }\lambda\text{ such that } \Gamma - \lambda\cdot 1 \succeq 0.\)

    The correspondence is that the result of (2) is positive if (1) is feasible, and negative otherwise. By default False.

  • solve_dual (bool, optional) – Optimize the dual problem (recommended). By default True.

  • solverparameters (dict, optional) – Extra parameters to be sent to the solver. By default None.

  • solver_arguments (dict, optional) – By default, solve will use the dictionary of SDP keyword arguments given by _prepare_solver_arguments(). However, a user may manually override these arguments by passing their own here.

  • verbose (int, optional) – How much information to display to the user. By default, -1 (which sets it to self.verbose).

write_to_file(filename: str) None[source]

Exports the problem to a file.

Parameters:

filename (str) – Name of the exported file. If no file format is specified, it defaults to sparse SDPA format. Supported formats are .mat (MATLAB), .dat-s (SDPA), and .csv (human-readable).