toqito.nonlocal_games.nonlocal_game¶
Two-player nonlocal game.
Module Contents¶
- class toqito.nonlocal_games.nonlocal_game.NonlocalGame(prob_mat, pred_mat, reps=1)[source]¶
Create two-player nonlocal game object.
Nonlocal games are a mathematical framework that abstractly models a physical system. This game is played between two players, Alice and Bob, who are not allowed to communicate with each other once the game has started and who play cooperative against an adversary referred to as the referee.
The nonlocal game framework was originally introduced in [@Cleve_2010_Consequences].
A tutorial is available in the documentation. For more info, see [Nonlocal Games](../../../generated/gallery/nonlocal_games/index.md).
- Parameters:
prob_mat (numpy.ndarray)
pred_mat (numpy.ndarray)
reps (int)
- classmethod from_bcs_game(constraints, reps=1)[source]¶
Convert constraints that specify a binary constraint system game to a nonlocal game.
Binary constraint system games (BCS) games were originally defined in [@Cleve_2014_Characterization].
- Parameters:
constraints (list[numpy.ndarray]) – List of binary constraints that define the game.
reps (int) – Number of parallel repetitions to perform. Default is 1.
- Returns:
A NonlocalGame object arising from the variables and constraints that define the game.
- Return type:
- is_bcs_perfect_commuting_strategy()[source]¶
Determine if the BCS game admits a perfect commuting-operator strategy.
This method checks whether the binary constraint system game, from which the current nonlocal game was constructed, has a perfect quantum strategy in the commuting-operator model. It converts the raw BCS tensor constraints (if needed) into matrix form and evaluates their satisfiability using a helper function.
- Raises:
If no constraints are stored (i.e., if the game was not created from a BCS game). –
- Returns:
True if a perfect commuting-operator strategy exists; False otherwise.
- Return type:
bool
- classical_value()[source]¶
Compute the classical value of the nonlocal game using Numba acceleration.
- Return type:
float
- quantum_value_lower_bound(dim=2, iters=5, tol=1e-05)[source]¶
Compute a lower bound on the quantum value of a nonlocal game [@Liang_2007_Bounds].
Calculates a lower bound on the maximum value that the specified nonlocal game can take on in quantum mechanical settings where Alice and Bob each have access to dim-dimensional quantum system.
This function works by starting with a randomly-generated POVM for Bob, and then optimizing Alice’s POVM and the shared entangled state. Then Alice’s POVM and the entangled state are fixed, and Bob’s POVM is optimized. And so on, back and forth between Alice and Bob until convergence is reached.
Note that the algorithm is not guaranteed to obtain the optimal local bound and can get stuck in local minimum values. The alleviate this, the iter parameter allows one to run the algorithm some pre-specified number of times and keep the highest value obtained.
The algorithm is based on the alternating projections algorithm as it can be applied to Bell inequalities as shown in [@Liang_2007_Bounds].
The alternating projection algorithm has also been referred to as the “see-saw” algorithm as it goes back and forth between the following two semidefinite programs:
- [
- begin{equation}
- begin{aligned}
textbf{SDP-1:} quad & \ text{maximize:} quad & sum_{(x,y in Sigma)} pi(x,y)
sum_{(a,b) in Gamma} V(a,b|x,y) langle B_b^y, A_a^x rangle \
- text{subject to:} quad & sum_{a in Gamma_{mathsf{A}}}=
tau, qquad qquad forall x in Sigma_{mathsf{A}}, \
- quad & A_a^x in text{Pos}(mathcal{A}),
qquad forall x in Sigma_{mathsf{A}}, forall a in Gamma_{mathsf{A}}, \ & tau in text{D}(mathcal{A}).
end{aligned}
end{equation}
]
- [
- begin{equation}
- begin{aligned}
textbf{SDP-2:} quad & \ text{maximize:} quad & sum_{(x,y in Sigma)} pi(x,y)
sum_{(a,b) in Gamma} V(a,b|x,y) langle B_b^y, A_a^x rangle \
- text{subject to:} quad & sum_{b in Gamma_{mathsf{B}}}=
mathbb{I}, qquad qquad forall y in Sigma_{mathsf{B}}, \
quad & B_b^y in text{Pos}(mathcal{B}), qquad forall y in Sigma_{mathsf{B}}, forall b in Gamma_{mathsf{B}}.
end{aligned}
end{equation}
]
Examples
The CHSH game
The CHSH game is a two-player nonlocal game with the following probability distribution and question and answer sets.
- [
begin{equation} begin{aligned}
pi(x,y) = frac{1}{4}, qquad (x,y) in Sigma_A times Sigma_B, qquad text{and} qquad (a, b) in Gamma_A times Gamma_B,
end{aligned} end{equation}
]
where
- [
begin{equation} Sigma_A = {0, 1}, quad Sigma_B = {0, 1}, quad Gamma_A = {0,1}, quad text{and} quad Gamma_B = {0, 1}. end{equation}
]
Alice and Bob win the CHSH game if and only if the following equation is satisfied.
- [
begin{equation} a oplus b = x land y. end{equation}
]
Recall that (oplus) refers to the XOR operation.
The optimal quantum value of CHSH is (cos(pi/8)^2 approx 0.8536) where the optimal classical value is (3/4).
```python exec=”1” source=”above” import numpy as np from toqito.nonlocal_games.nonlocal_game import NonlocalGame
dim = 2 num_alice_inputs, num_alice_outputs = 2, 2 num_bob_inputs, num_bob_outputs = 2, 2 prob_mat = np.array([[1 / 4, 1 / 4], [1 / 4, 1 / 4]]) pred_mat = np.zeros((num_alice_outputs, num_bob_outputs, num_alice_inputs, num_bob_inputs))
- for a_alice in range(num_alice_outputs):
- for b_bob in range(num_bob_outputs):
- for x_alice in range(num_alice_inputs):
- for y_bob in range(num_bob_inputs):
- if np.mod(a_alice + b_bob + x_alice * y_bob, dim) == 0:
pred_mat[a_alice, b_bob, x_alice, y_bob] = 1
chsh = NonlocalGame(prob_mat, pred_mat)
print(chsh.quantum_value_lower_bound()) ```
- Parameters:
dim (int) – The dimension of the quantum system that Alice and Bob have access to (default = 2).
iters (int) – The number of times to run the alternating projection algorithm.
tol (float) – The tolerance before quitting out of the alternating projection semidefinite program.
- Returns:
The lower bound on the quantum value of a nonlocal game.
- nonsignaling_value()[source]¶
Compute the non-signaling value of the nonlocal game.
- Returns:
A value between [0, 1] representing the non-signaling value.
- Return type:
float
- commuting_measurement_value_upper_bound(k=1)[source]¶
Compute an upper bound on the commuting measurement value of the nonlocal game.
- This function calculates an upper bound on the commuting measurement value by
using k-levels of the NPA hierarchy [@Navascues_2008_AConvergent]. The NPA hierarchy is a uniform family of semidefinite programs that converges to the commuting measurement value of any nonlocal game.
- You can determine the level of the hierarchy by a positive integer or a string
of a form like ‘1+ab+aab’, which indicates that an intermediate level of the hierarchy should be used, where this example uses all products of one measurement, all products of one Alice and one Bob measurement, and all products of two Alice and one Bob measurements.
- Parameters:
k (int | str) – The level of the NPA hierarchy to use (default=1).
- Returns:
The upper bound on the commuting strategy value of a nonlocal game.
- Return type:
float