Empirical model module

Module description

This module contains the class EmpiricalModel which is focused on the implementation of an empirical model for a given measurement scenario. The class is fully developed with many magic commands for multiplication and addition, together with properties and methods.

Module documentation

class contextuality.empirical_model.EmpiricalModel(measurement_scenario, empirical_model=None)

Empirical model class, that is a simple holder for an array, and the way to generate them

Parameters:
  • measurement_scenario (MeasurementScenario)

  • empirical_model (List | ndarray[tuple[Any, ...], dtype[_ScalarT]] | None)

__init__(measurement_scenario, empirical_model=None)

Constructor for EmpiricalModel.

Parameters:
  • measurement_scenario (MeasurementScenario) – The measurement scenario associated to such a model.

  • empirical_model (List | ndarray[tuple[Any, ...], dtype[_ScalarT]] | None) – The empirical model vectorial representation. Defaults to None.

compute_cf(eta=0, solver='MOSEK', verbose=False)

Compute the Non-Contextual Fraction (NCF) of an empirical model.

Parameters:
  • eta (float) – Value of the non-determinism allowed.

  • solver (str) – The solver used for cvxpy. Defaults to “MOSEK”.

  • verbose (bool) – Whether the solver should verbose. Defaults to False.

Returns:

The NCF, CF and the optimal description by NC model.

Return type:

Dict[str, float]

compute_sf(solver='MOSEK', verbose=False)

Computes the signaling fraction from an empirical model and a MeasurementScenario.

Parameters:
  • solver (str) – Solver for cvxpy. Defaults to “MOSEK”.

  • verbose (bool) – Whether the solver should verbose. Defaults to False.

Returns:

Signalling and non-signalling fractions

Return type:

Dict[str, Any]

get_signalling_variables()

Get the signalling variables of a deterministic empirical model.

Raises:

ValueError – If the empirical model is not deterministic.

Returns:

A tuple containing a dictionary of signalling variables and an array of values per context.

Return type:

Tuple[dict, List | ndarray[tuple[Any, …], dtype[_ScalarT]]]

Example:

>>> from contextuality import MeasurementScenarioImplementations, EmpiricalModel
>>> ms = MeasurementScenarioImplementations.KCBS()
>>> em = EmpiricalModel(ms, [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0])
>>> signalling_vars, values_per_context = em.get_signalling_variables()
>>> print(signalling_vars)
{0: True, 1: False, 2: False, 3: False, 4: False}
>>> print(values_per_context)
[[0. 0.]
 [0. 0.]
 [0. 0.]
 [0. 0.]
 [0. 1.]]
property is_deterministic: bool

Boolean property that tell whether the empirical model is deterministic or not.

Raises:

AttributeError – When no vector has been attributed yet.

Returns:

True iff the empirical model is deterministic

property is_valid: bool

Boolean property to know whether the model is a valid probabilistic model.

Raises:

AttributeError – When no vector has been attributed yet.

Returns:

True iff the empirical model is a valid probabilistic model.

maximum_incompatibility_of_marginals()

Computes the maximum difference between the marginals in different contexts.

Returns:

max(p(outcome|ctx1, observable) - p(outcome|ctx2, observable))

Return type:

float

property mvector: ndarray[tuple[Any, ...], dtype[_ScalarT]]

Matrix version of the vector of the empirical model.

Returns:

matrix version of the vector

probability_outcome(outcome, ctx, observable)

Compute the probability of an outcome given a context and an observable.

Parameters:
  • outcome (int) – represents the outcome of the observable (p(outcome | observable_ctx1))

  • ctx (List[int]) – represents the context of the observable

  • observable (int) – represents the observable

Returns:

the probability of the outcome given the context and the observable

Return type:

float

quantum_realisation(rho, meas)

Compute an empirical model/behavior from a provided quantum realization.

Parameters:
  • rho (List | ndarray[tuple[Any, ...], dtype[_ScalarT]]) – The quantum state density matrix.

  • meas (List | ndarray[tuple[Any, ...], dtype[_ScalarT]]) – The measurements in an array. The indices are “measurement label”, “outcome” to access a specific measurement PVM. For instance, meas[0,0] accesses the PVM for measurement with label X[0] and outcome O[0] respectively.

Return type:

None

property vector: ndarray[tuple[Any, ...], dtype[_ScalarT]]

Accessor of the internal vectorial representation.

Raises:

AttributeError – When no vector has been attributed yet.

Returns:

The vector representation.