InflationSDP Class
- class inflation.InflationSDP(inflationproblem: InflationProblem, commuting: bool = False, supports_problem: bool = False, verbose=None)[source]
Class for generating and solving an SDP relaxation for quantum inflation.
- Parameters
inflationproblem (InflationProblem) – Details of the scenario.
commuting (bool, optional) – Whether variables in the problem are going to be commuting (classical problem) or non-commuting (quantum problem). By default
False
.supports_problem (bool, optional) – Whether to consider feasibility problems with distributions, or just with the distribution’s support. By default
False
.verbose (int, optional) –
Optional parameter for level of verbose:
0: quiet (default),
1: monitor level: track program process and show warnings,
2: debug level: show properties of objects created.
- build_columns(column_specification: Union[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 setmax_monomial_length=2
, the generating set is instead \(\{1, A, B, C, AB, AC, BC\}\). By default0
(no limit).symbolic (bool, optional) – If
True
, it returns the columns as a list of sympy symbols parsable by InflationSDP.generate_relaxation(). By defaultFalse
.
- 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
.- Parameters
clean (bool, optional) – If
True
, eliminate all coefficients that are smaller thanchop_tol
, normalise and round to the number of decimals specified byround_decimals
. By defaultTrue
.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 or 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 with the notation of the operators in the moment matrix. The expression is in the form such that satisfaction implies incompatibility.
- Parameters
clean (bool, optional) – If
True
, eliminate all coefficients that are smaller thanchop_tol
, normalise and round to the number of decimals specified byround_decimals
. By defaultTrue
.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 symbols representing the monomials in the moment matrix. The certificate of incompatibility is
cert < 0
.- Return type
str
- generate_relaxation(column_specification: Union[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 ofnpa2
; for two parties,npa2
is \(\{1, A, B, AA, AB, BB\}\) whilelocal1
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 aslocal1
. 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 asnpa2
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 identitysympy.S.One
as the first element.
- reset(which: Union[str, List[str]]) 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: Optional[dict], 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: Optional[ndarray], 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 theorder
parameter in theInflationProblem
used to instantiateInflationSDP
.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: Optional[Union[Expr, dict]], 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 monomials 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: Optional[Dict[Union[CompoundMonomial, InternalAtomicMonomial, Symbol, str], Union[float, Expr]]], use_lpi_constraints: bool = False, only_specified_values: bool = False) None [source]
Directly assign numerical values to variables in the moment matrix. This is done via a dictionary where keys are the variables to have numerical values assigned (either in their operator form, in string form, or directly referring to the variable in the moment matrix), and the values are the corresponding numerical quantities.
- Parameters
values (Union[None, Dict[Union[CompoundMonomial, InternalAtomicMonomial, sympy.core.symbol.Symbol, str], float]]) – The description of the variables to be assigned numerical values and the corresponding values. The keys can be either of the Monomial class, symbols or strings (which should be the name of some Monomial).
use_lpi_constraints (bool) – Specification whether linearized polynomial constraints (see, e.g., Eq. (D6) in arXiv:2203.16543) will be imposed or not.
only_specified_values (bool) – Specifies whether one wishes to fix only the variables provided (
True
), or also the variables containing products of the monomials fixed (False
). Regardless of this flag, unknowable variables can also be fixed.
- solve(interpreter='MOSEKFusion', feas_as_optim=False, dualise=True, solverparameters=None, solver_arguments={}) 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
.dualise (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.
- write_to_file(filename: str) None [source]
Exports the problem to a file.
If the file format is .mat, the following variables are included in the file:
momentmatrix: the moment matrix, as a matrix of integers, where each integer indexes a different variable
moments_idx2name: a cell array where the \(i\)-th cell stores the index \(i\) of a variable \(x_i\) and its name as a string
objective: the objective function \(\sum_i c_i x_i\) as a an array where the first column encodes the indices \(i\) of the variables \(x_i\) with non-zero coefficient \(c_i\), and the second column encodes the coefficients \(c_i\)
known_moments: constant variable constraints, \(x_i = c_i\), encoded as an array where the first column stores the index \(i\) of the variable that is equal to the constant \(c_i\), and the second column stores the constant \(c_i\); note that the ‘1’ is another variable whose value is 1.0 and should be included in known_moments
semiknown_moments: semiknown constraints, namely, linear proportionality constraints of the form \(x_i = c_i x_j\), encoded as an array where the first column stores the index \(i\) of the variable, the second column stores the coefficient \(c_i\) of the constraint, and the third column stores the index \(j\) of the variable
moment_lowerbounds: lower bounds on the moments, \(x_i \geq c_i\), encoded as an array where the first column stores the index \(i\) of the variable, and the second column stores the lower bound \(c_i\)
moment_upperbounds: upper bounds on the moments, \(x_i \leq c_i\), encoded as an array where the first column stores the index \(i\) of the variable, and the second column stores the upper bound \(c_i\)
moment_equalities: linear equality constraints, \(\sum_j A_{ij} x_j = 0\) (note that the ‘1’ is treated as any variable \(x_j\) whose value is 1.0 and it must be included in known_moments), as a cell where the \(i\)-th cell stores the constraint as a structure with fields moments and coeffs, where moments is an array of indices \(j\) of the variables \(x_j\) and coeffs is an array of coefficients \(A_{ij}\) of the variables \(x_j\)
moment_inequalities: linear inequality constraints \(\sum_j A_{ij} x_j \geq 0\), with the same convention as for moment_equalities
- 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).