Skip to main content

A package for computing contextuality related stuff

Project description

Contextuality package

Software License Version

This project is a starter project to have many tools to compute various quantities in measurement scenarios as defined by Abramsky and Brandenburger. It can be used in a variety of cases.

Install

To install the package from pypi you can simply run pip:

$ python -m pip install contextuality

Developers

If you wish to improve the package you can install from the sources with poetry:

$ poetry install --with dev

Documentation

The documentation can be compiled in the docs directory.

$ cd docs
$ make html

then navigate to docs/build/html and open index.html to access the documentation.

Usage example

from contextuality.measurement_scenario import MeasurementScenario
import numpy as np
from contextuality.empirical_model import EmpiricalModel
from contextuality.utils import compute_max_CF, compute_deterministic_fraction, compute_signaling_fraction, compute_NCF

X = [i for i in range(4)]
M = [[0, 2], [0, 3], [1, 2], [1, 3]]
O = [0, 1]
kcbs = MeasurementScenario(X, M, O)

meas = np.zeros((5, 2, 3, 3))  # shape = number mesurements, number of outcomes, dimension of state (d x d)
N = 1 / np.sqrt(1 + np.cos(np.pi / 5))
for i in range(5):
    vec = N * np.array([np.cos(4 * np.pi * i / 5), np.sin(4 * np.pi * i / 5), np.sqrt(np.cos(np.pi / 5))])
    meas[i][1] = np.outer(vec, vec)
    meas[i][0] = np.eye(3) - meas[i][1]

psi = np.array([0, 0, 1])
rho = np.outer(psi, psi)

empirical_model = EmpiricalModel(kcbs)
empirical_model.quantum_realisation(rho, meas)

result = compute_max_CF(kcbs, eta=0.3, sigma=0.5)

print(result['EmpiricalModel'].vector)

df = compute_deterministic_fraction(result["EmpiricalModel"], verbose=False)
print(df)
sf = compute_signaling_fraction(result["EmpiricalModel"], verbose=False)
print(sf)

CF_result = compute_NCF(result['EmpiricalModel'], verbose=False)

print(CF_result)

Notebooks

Examples in the form of notebooks can be found in the notebooks folder.

Credits

License

The CC BY-NC 4.0. Please see License File for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

contextuality-1.0.0.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

contextuality-1.0.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

Details for the file contextuality-1.0.0.tar.gz.

File metadata

  • Download URL: contextuality-1.0.0.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.0 Linux/6.12.43+deb12-amd64

File hashes

Hashes for contextuality-1.0.0.tar.gz
Algorithm Hash digest
SHA256 eb9f64db17b614c0a27cefad71c3897929deceef4d32519c19dbe042f892548d
MD5 6d47de01a8a701056e7bbc29d0d171eb
BLAKE2b-256 50596c2a05e9d6ce416d0978d871b8f558b496f9769bb5c3d7578296a59da482

See more details on using hashes here.

File details

Details for the file contextuality-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: contextuality-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.10.0 Linux/6.12.43+deb12-amd64

File hashes

Hashes for contextuality-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6434fea1c1f9c3eb5e30cb783e37886e63abae7aa9ca6e1c6bd4ab6f4ced95ff
MD5 bb409606f6be294c718e4b701021e7a8
BLAKE2b-256 5713e08c2276eb514a5b3b6f6b2f1f7a2bf79384c1ddfab9705122638b7c6c25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page