InflationLP Class
- class inflation.InflationLP(inflationproblem: InflationProblem, nonfanout: bool = True, local_level: int | None = None, supports_problem: bool = False, default_non_negative: bool = True, include_all_outcomes: bool = False, verbose: int | None = None)[source]
- _generate_lp() None [source]
Creates the LP associated with the inflation problem.
In the inflated graph there are many symmetries coming from invariance under swaps of the copied sources, which are used to remove variables from the LP.
- certificate_as_dict(clean: bool = True, chop_tol: float = 1e-10, round_decimals: int = 3) dict [source]
Give certificate as dictionary with monomials as keys and their coefficients in the certificate as the values. 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 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 of probabilities and marginals. The certificate of incompatibility is
cert < 0
.- Return type:
dict
- 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 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 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 thanchop_tol
, normalise and round to the number of decimals specified byround_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 theorder
parameter in theInflationProblem
used to instantiateInflationLP
.- Returns:
The evaluation of the certificate of infeasibility in prob_array.
- Return type:
float
- reset(which: str | List[str] = 'all') None [source]
Reset the various user-specifiable objects in the inflation LP.
- 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 LP relaxation. The bounds are at the level of the LP 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
>>> self.set_bounds({"pAB(00|00)": 0.2}, "lo")
- set_distribution(prob_array: ndarray | None, use_lpi_constraints: bool = False, shared_randomness: bool = 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 instantiateInflationLP
.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 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: Dict[CompoundMoment | InternalAtomicMonomial | Symbol | str, float | Expr] | None, **kwargs)[source]
Exactly like update_values, except it resets all known values to zero as an intermediate step.
- Parameters:
values (Union[None, Dict[Union[CompoundMoment, 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).
- solve(relax_known_vars: bool = False, relax_inequalities: bool = False, solve_dual: bool = True, solverparameters: dict | None = None, verbose: int | None = None, default_non_negative: bool | None = None, **solver_arguments) None [source]
Call a solver on the LP relaxation. Upon successful solution, it returns the primal and dual objective values along with the solution matrices.
- Parameters:
relax_known_vars (bool, optional) – Do feasibility as optimization where each known value equality becomes two relaxed inequality constraints. E.g., P(A) = 0.7 becomes P(A) + lambda >= 0.7 and P(A) - lambda <= 0.7, where lambda is a slack variable. By default,
False
.relax_inequalities (bool, optional) – Do feasibility as optimization where each inequality is relaxed by the non-negative slack variable lambda. By default,
False
.solve_dual (bool, optional) – Optimize the dual problem (recommended). By default
False
.solverparameters (dict, optional) – Extra parameters to be sent to the solver. By default
None
.verbose (int, optional) – Verbosity level.
default_non_negative (bool, optional) – If
True
, all variables are set to be non-negative by default.solver_arguments (dict, optional) – By default, solve will use the dictionary of LP keyword arguments given by
_prepare_solver_arguments()
. However, a user may manually override these arguments by passing their own here.
- update_values(values: Dict[CompoundMoment | InternalAtomicMonomial | Symbol | str, float | Expr] | None, use_lpi_constraints: bool = False, only_specified_values: bool = False) None [source]
Directly assign numerical values to variables in the generating set. 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 generating set), and the values are the corresponding numerical quantities.
- Parameters:
values (Union[None, Dict[Union[CompoundMoment, 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. By default
False
.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.