Skip to main content

A friendly API for simulating nonlocal no-signalling correlations

Project description

A friendly API for simulating nonlocal no-signalling correlations.

Installation

The easiest way to install NonlocalBox is to use the pip command:

python -m pip install nonlocalbox

You may need to replace python with the correct Python interpreter, e.g., python3.

Usage

The following example illustrates a simple game between Alice and Bob. First, we need to create two instances of NonlocalBox, one for Alice and one for Bob:

from os import environ
from nonlocalbox import NonlocalBox

alice_game = NonlocalBox(environ["ALICE_API_KEY"])
bob_game = NonlocalBox(environ["BOB_API_KEY"])

In the current state, neither of them are in any role. Suppose that Alice invites Bob for a simulation, whose username is known by Alice (which is ‘bob’ in this case). Alice wants to use Popescu-Rohrlich Box of box ID 1 and names it ‘hellothere’:

alice_game.invite("bob", 1, 'hellothere')
print(alice_game.box_id)  # this is arbitrary
4

In the server side, Bob is automatically added to this box. They both should initialize the newly created box with ID 4. This will set the role ‘Alice’ to Alice and ‘Bob’ to Bob (since there won’t be any box in Bob’s list with ID 4):

alice_game.initialize(4)
bob_game.initialize(4)

They can use the nonlocal boxes to run a simulation.

Suppose Alice sends x = 0 are her input to the box with transaction ID 20220311001 and Bob sends y = 0 with the same transaction ID. Note that for x = y = 0 the results should be correlated:

print(alice_game.use(0, "20220311001"))
0
print(bob_game.use(0, "20220311001"))
0

Now suppose Bob will be the first to send y = 1 with an incremented transaction ID, and Alice also sends x = 1. The results should be anticorrelated:

print(bob_game.use(1, "20220311002"))
1
print(alice_game.use(1, "20220311002"))
0

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

nonlocalbox-0.1.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

nonlocalbox-0.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file nonlocalbox-0.1.tar.gz.

File metadata

  • Download URL: nonlocalbox-0.1.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for nonlocalbox-0.1.tar.gz
Algorithm Hash digest
SHA256 349e4acb2646f34664bd15533e8d0c7665b9403949662081abadfa2758318816
MD5 04b35b6d5dd20f2c36402f8bbe983a48
BLAKE2b-256 2156d7f75ee369311683b98a939e02953d615fa40c2dd801b361f2ea38c5f471

See more details on using hashes here.

File details

Details for the file nonlocalbox-0.1-py3-none-any.whl.

File metadata

  • Download URL: nonlocalbox-0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for nonlocalbox-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 01da8926dbf1697336858bb7e36453e35203880287b1de1f3800d5d6e03cde4e
MD5 c2ed67764ca11a51778f38e6361a0088
BLAKE2b-256 0073499b9853251824762585c4a491189c8cac50ae5bba549deec370951cbe07

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