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:
exception WrongMeasurementScenarioError(msg)
__init__(msg)
__init__(measurement_scenario, empirical_model=None)

Constructor for EmpiricalModel.

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

  • empirical_model (List | 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 | None) – 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]

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.

property mvector: ndarray

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 (np.ndarray) – The quantum state density matrix.

  • meas (np.ndarray) – The measurements in a ndarray. The index 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

Accessor of the internal vectorial representation.

Raises:

AttributeError – When no vector has been attributed yet.

Returns:

The vector representation.

Return type:

np.ndarray