Utils module
Module description
This module contains all the useful functions in contextuality scenarios. There are functions which allow to compute the NC and signalling polytope. Some more functions are defined, some experimental some useful. Various optimizations are to be made.
Module documentation
Set of utilitary functions and constants used across the project
- contextuality.utils.compatibility_of_marginals_constraints(MS, EM_vector)
Generate compatibility of marginals constraints on an empirical model vector as a Variable of cvxpy.
- Parameters:
MS (MeasurementScenario) – Measurement scenario associated to the empirical model vector.
EM_vector (cp.Variable) – Empirical Model vectorial representation.
- Returns:
A list of constraints on EM_vector to respect the compatibility of marginals.
- Return type:
List
- contextuality.utils.compute_deterministic_fraction(empirical_model, solver='MOSEK', verbose=False)
The compute_deterministic_fraction function computes the deterministic fraction of a given empirical model. The function takes as input an EmpiricalModel object and returns the value of its deterministic fraction.
- Parameters:
empirical_model (EmpiricalModel) – The empirical model that describes the experiment.
solver (str) – Used to Specify the solver to be used. Defaults to Mosek.
verbose (bool) – Used to Display the computation details. Defaults to False.
- Returns:
The value of the deterministic fraction and its opposite
- Return type:
Dict[str, float]
- contextuality.utils.compute_max_cf(MS, sigma, eta, big_m=2, solver='MOSEK', verbose=False)
LP to find the maximum distance between two empirical models.
- Parameters:
MS (MeasurementScenario) – The measurement scenario in which we try to find the maximum CF.
sigma (float) – Parameter dependence fraction.
eta (float) – Outcome nondeterminism fraction.
big_m (float) – Parameter for the big M method in LP.
solver (str) – The solver used for the LP. Defaults to ‘MOSEK’.
verbose (bool) – Whether the solver should verbose. Defaults to False.
- Returns:
The empirical model that violates at most the inequality and the violation.
- Return type:
Dict[str, Any]
- contextuality.utils.get_bound_winter(MS, lambdas=None, bound_type='classical', epsilon=0, solver='MOSEK', verbose=False)
Get the bound for the Winter model.
- Parameters:
MS (MeasurementScenario) – Measurement Scenario which we are considering.
lambdas (ndarray | None) – The lambdas used to compute the bound. If None, ones are used.
bound_type (str | None) – Which type of bound to compute.
epsilon (float | None) – The epsilon given in Winter’s paper.
solver (str | None) – Solver for the LP.
verbose (bool | None) – Whether to verbose the outputs.
- Returns:
The classical bound.
- Return type:
Dict[str, Any]
- contextuality.utils.nc_polytope(MS, representation='V')
Polytope for the Non-Contextual set.
- Parameters:
MS (MeasurementScenario) – Measurement Scenario that is associated to that polytope.
representation ("V", "H" or "BOTH") – Representation expected as a return.
- Returns:
The polytope in the form of a matrix representation H or V depending on the parameter representation.
- Return type:
np.ndarray
- contextuality.utils.polytope_to_h(D)
Converts a polytope in V representation to H representation.
- Parameters:
D (ndarray) – The polytope in V representation.
- Returns:
The polytope in H representation.
- Return type:
np.ndarray
- contextuality.utils.signalling_polytope(MS, include_NS_polytope=True)
Creates the signalling polytope in V mode. All the outcomes are maximally signalling or no-signalling and deterministic.
- Parameters:
MS (MeasurementScenario) – The measurement scenario
include_NS_polytope (bool) – Whether to return ONLY the signalling points or all the points.
- Returns:
The points of the Signalling polytope as rows
- Return type:
np.ndarray