Skip to content

Commit

Permalink
Update documentation on bell_inequality.py example (#3281)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamarthVadia committed Sep 4, 2020
1 parent e04187c commit 0fc057a
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions examples/bell_inequality.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,56 @@
"""Creates and simulates a circuit equivalent to a Bell inequality test.
"""
Bell's theorem or inequality proves that entanglement based
observations can't be reproduced with any local realist theory [1].
This example shows Bell's inequality in form of CHSH game where two
players Alice and Bob receive an input bit x and y respectively and
produce an output a and b based on the input bit.
The goal is to maximize the probability to satisfy the condition [2]:
a XOR b = x AND y
In the classical deterministic case, the highest probability
achievable is 75%. While with quantum correlations, it can
achieve higher success probability. In the quantum case, two players
Alice and Bob start with a shared Bell-pair entangled state. The
random input x and y is provided by referee for Alice and Bob. The
success probability of satisfying the above condition will be
cos(theta/2)^2 if Alice and Bob measure their entangled qubit in
measurement basis V and W where angle between V and W is theta.
Therefore, maximum success probability is cos(pi/8)^2 ~ 85.3%
when theta = pi/4.
In the usual implementation [2], Alice and Bob share the Bell state
with the same value and opposite phase. If the input x (y) is 0, Alice (Bob)
rotates in Y-basis by angle -pi/16 and if the input is 1, Alice (Bob)
rotates by angle 3pi/16. Here, Alice and Bob start with the entangled
Bell state with same value and phase. The same success probability is
achieved by following procedure: Alice rotate in X-basis by angle
-pi/4 followed by controlled-rotation by angle pi/2 in X-basis for
Alice (Bob) based on input x (y).
[1] https://en.wikipedia.org/wiki/Bell%27s_theorem
[2] R. de Wolf. Quantum Computing: Lecture Notes
(arXiv:1907.09415, Section 15.2)
=== EXAMPLE OUTPUT ===
Circuit:
(0, 0): ───H───@───X^-0.25───────X^0.5───M───
(0, 1): ──────┼─────────────H───@───────M───
(0, 0): ───H───@───X^-0.25───X────────M('a')───
│ │
(0, 1): ───H───┼─────────────@^0.5────M('x')───
(1, 0): ───────X─────────────────X^0.5───M───
(1, 1): ─────────────────────H───@───────M───
(1, 0): ───────X───X─────────M('b')───────────
(1, 1): ───H───────@^0.5─────M('y')────────────
Simulating 75 repetitions...
Results
a: _1__11111___111111_1__1_11_11__111________1___1_111_111_____1111_1_111__1_1
b: _1__1__11_1_1_1__1_1_1_1_11____111_111__11_____1_1__1111_1_11___111_11_1__1
x: ____11______11111__1_1111111____1_111__1111___1111_1__11_1__11_11_11_1__11_
y: 11_111_____1_1_111__11111_111_1____1____11_____11___11_1_1___1_111111_1_1_1
a: _1___1_1_1111__11__11______11__1______111_______1_______11___11_11__1_1_1_1
b: _1_______11_1_1__1_1111_11_11_1_1_____11___1__111__1_1_1_1__111_11_11_1_1_1
x: 1_1____1______11_1_1_1_11111___111_1__1_1__11_111__1_11_11_11______1____1__
y: ____1__111_______1___11_111__1_111______111___11_11_11__1_1_1111_1111__1_11
(a XOR b) == (x AND y):
1111_1_111_11111111111111111_1111111__1111_111_111_11111111_11_11111111_111
11111_11111_11___11111_111_111_11_111111111_1111111_111_1111111111111111111
Win rate: 84.0%
"""

Expand Down Expand Up @@ -71,7 +102,6 @@ def make_bell_test_circuit():
circuit.append([
cirq.H(alice),
cirq.CNOT(alice, bob),
cirq.X(alice)**-0.25,
])

# Referees flip coins.
Expand All @@ -82,6 +112,7 @@ def make_bell_test_circuit():

# Players do a sqrt(X) based on their referee's coin.
circuit.append([
cirq.X(alice)**-0.25,
cirq.CNOT(alice_referee, alice)**0.5,
cirq.CNOT(bob_referee, bob)**0.5,
])
Expand Down

0 comments on commit 0fc057a

Please sign in to comment.