.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/extended_nonlocal_games/enlg_bb84.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_extended_nonlocal_games_enlg_bb84.py: The BB84 extended nonlocal game ===================================== In our :ref:`sphx_glr_auto_examples_extended_nonlocal_games_enlg_introduction.py` tutorial, we introduced the framework for extended nonlocal games. Now, we will construct our first concrete example, the *BB84 extended nonlocal game*. .. GENERATED FROM PYTHON SOURCE LINES 10-44 The *BB84 extended nonlocal game* is defined as follows. Let :math:`\Sigma_A = \Sigma_B = \Gamma_A = \Gamma_B = \{0,1\}`, define .. math:: \begin{aligned} V(0,0|0,0) = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, &\quad V(1,1|0,0) = \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix}, \\ V(0,0|1,1) = \frac{1}{2}\begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix}, &\quad V(1,1|1,1) = \frac{1}{2}\begin{pmatrix} 1 & -1 \\ -1 & 1 \end{pmatrix}, \end{aligned} define .. math:: V(a,b|x,y) = \begin{pmatrix} 0 & 0 \\ 0 & 0 \end{pmatrix} for all :math:`a \not= b` or :math:`x \not= y`, define :math:`\pi(0,0) = \pi(1,1) = 1/2`, and define :math:`\pi(x,y) = 0` if :math:`x \not=y`. We can encode the BB84 game, :math:`G_{BB84} = (\pi, V)`, in :code:`numpy` arrays where :code:`prob_mat` corresponds to the probability distribution :math:`\pi` and where :code:`pred_mat` corresponds to the operator :math:`V`. .. GENERATED FROM PYTHON SOURCE LINES 44-79 .. code-block:: Python :lineno-start: 45 # Define the BB84 extended nonlocal game. import numpy as np from toqito.states import basis # The basis: {|0>, |1>}: e_0, e_1 = basis(2, 0), basis(2, 1) # The basis: {|+>, |->}: e_p = (e_0 + e_1) / np.sqrt(2) e_m = (e_0 - e_1) / np.sqrt(2) # The dimension of referee's measurement operators: dim = 2 # The number of outputs for Alice and Bob: a_out, b_out = 2, 2 # The number of inputs for Alice and Bob: a_in, b_in = 2, 2 # Define the predicate matrix V(a,b|x,y) \in Pos(R) bb84_pred_mat = np.zeros([dim, dim, a_out, b_out, a_in, b_in]) # V(0,0|0,0) = |0><0| bb84_pred_mat[:, :, 0, 0, 0, 0] = e_0 @ e_0.conj().T # V(1,1|0,0) = |1><1| bb84_pred_mat[:, :, 1, 1, 0, 0] = e_1 @ e_1.conj().T # V(0,0|1,1) = |+><+| bb84_pred_mat[:, :, 0, 0, 1, 1] = e_p @ e_p.conj().T # V(1,1|1,1) = |-><-| bb84_pred_mat[:, :, 1, 1, 1, 1] = e_m @ e_m.conj().T # The probability matrix encode \pi(0,0) = \pi(1,1) = 1/2 bb84_prob_mat = 1 / 2 * np.identity(2) .. GENERATED FROM PYTHON SOURCE LINES 83-92 The unentangled value of the BB84 extended nonlocal game ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It was shown in :footcite:`Tomamichel_2013_AMonogamy` and :footcite:`Johnston_2016_Extended` that .. math:: \omega(G_{BB84}) = \cos^2(\pi/8). This can be verified in :code:`|toqito⟩` as follows. .. GENERATED FROM PYTHON SOURCE LINES 92-105 .. code-block:: Python :lineno-start: 94 # Calculate the unentangled value of the BB84 extended nonlocal game. import numpy as np from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame # Define an ExtendedNonlocalGame object based on the BB84 game. bb84 = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat) # The unentangled value is cos(pi/8)**2 \approx 0.85356 print("The unentangled value is ", np.around(bb84.unentangled_value(), decimals=2)) .. rst-class:: sphx-glr-script-out .. code-block:: none The unentangled value is 0.85 .. GENERATED FROM PYTHON SOURCE LINES 106-109 The BB84 game also exhibits strong parallel repetition. We can specify how many parallel repetitions for :code:`|toqito⟩` to run. The example below provides an example of two parallel repetitions for the BB84 game. .. GENERATED FROM PYTHON SOURCE LINES 109-121 .. code-block:: Python :lineno-start: 110 # The unentangled value of BB84 under parallel repetition. import numpy as np from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame # Define the bb84 game for two parallel repetitions. bb84_2_reps = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat, 2) # The unentangled value for two parallel repetitions is cos(pi/8)**4 \approx 0.72855 print("The unentangled value for two parallel repetitions is ", np.around(bb84_2_reps.unentangled_value(), decimals=2)) .. rst-class:: sphx-glr-script-out .. code-block:: none The unentangled value for two parallel repetitions is 0.73 .. GENERATED FROM PYTHON SOURCE LINES 122-135 It was shown in :footcite:`Johnston_2016_Extended` that the BB84 game possesses the property of strong parallel repetition. That is, .. math:: \omega(G_{BB84}^r) = \omega(G_{BB84})^r for any integer :math:`r`. The standard quantum value of the BB84 extended nonlocal game ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We can calculate lower bounds on the standard quantum value of the BB84 game using :code:`|toqito⟩` as well. .. GENERATED FROM PYTHON SOURCE LINES 135-147 .. code-block:: Python :lineno-start: 136 # Calculate lower bounds on the standard quantum value of the BB84 extended nonlocal game. import numpy as np from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame # Define an ExtendedNonlocalGame object based on the BB84 game. bb84_lb = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat) # The standard quantum value is cos(pi/8)**2 \approx 0.85356 print("The standard quantum value is ", np.around(bb84_lb.quantum_value_lower_bound(), decimals=2)) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/toqito/envs/latest/lib/python3.11/site-packages/scs/__init__.py:83: UserWarning: Converting A to a CSC (compressed sparse column) matrix; may take a while. warn( The standard quantum value is 0.85 .. GENERATED FROM PYTHON SOURCE LINES 148-162 From :footcite:`Johnston_2016_Extended`, it is known that :math:`\omega(G_{BB84}) = \omega^*(G_{BB84})`, however, if we did not know this beforehand, we could attempt to calculate upper bounds on the standard quantum value. There are a few methods to do this, but one easy way is to simply calculate the non-signaling value of the game as this provides a natural upper bound on the standard quantum value. Typically, this bound is not tight and usually not all that useful in providing tight upper bounds on the standard quantum value, however, in this case, it will prove to be useful. The non-signaling value of the BB84 extended nonlocal game ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Using :code:`|toqito⟩`, we can see that :math:`\omega_{ns}(G) = \cos^2(\pi/8)`. .. GENERATED FROM PYTHON SOURCE LINES 162-174 .. code-block:: Python :lineno-start: 163 # Calculate the non-signaling value of the BB84 extended nonlocal game. import numpy as np from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame # Define an ExtendedNonlocalGame object based on the BB84 game. bb84 = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat) # The non-signaling value is cos(pi/8)**2 \approx 0.85356 print("The non-signaling value is ", np.around(bb84.nonsignaling_value(), decimals=2)) .. rst-class:: sphx-glr-script-out .. code-block:: none The non-signaling value is 0.85 .. GENERATED FROM PYTHON SOURCE LINES 175-183 So we have the relationship that .. math:: \omega(G_{BB84}) = \omega^*(G_{BB84}) = \omega_{ns}(G_{BB84}) = \cos^2(\pi/8). It turns out that strong parallel repetition does *not* hold in the non-signaling scenario for the BB84 game. This was shown in :footcite:`Russo_2017_Extended`, and we can observe this by the following snippet. .. GENERATED FROM PYTHON SOURCE LINES 183-197 .. code-block:: Python :lineno-start: 184 # The non-signaling value of BB84 under parallel repetition. import numpy as np from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame # Define the bb84 game for two parallel repetitions. bb84_2_reps = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat, 2) # The non-signaling value for two parallel repetitions is cos(pi/8)**4 \approx 0.73825 print( "The non-signaling value for two parallel repetitions is ", np.around(bb84_2_reps.nonsignaling_value(), decimals=2) ) .. rst-class:: sphx-glr-script-out .. code-block:: none The non-signaling value for two parallel repetitions is 0.74 .. GENERATED FROM PYTHON SOURCE LINES 198-207 Note that :math:`0.73825 \geq \cos(\pi/8)^4 \approx 0.72855` and therefore we have that .. math:: \omega_{ns}(G^r_{BB84}) \not= \omega_{ns}(G_{BB84})^r for :math:`r = 2`. Next, we will explore another well-known example, :ref:`sphx_glr_auto_examples_extended_nonlocal_games_enlg_chsh.py`, and see how its properties compare. .. GENERATED FROM PYTHON SOURCE LINES 209-213 References ---------- .. footbibliography:: .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.039 seconds) .. _sphx_glr_download_auto_examples_extended_nonlocal_games_enlg_bb84.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: enlg_bb84.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: enlg_bb84.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: enlg_bb84.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_