Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing redundant note for doctest. #651

Merged
merged 12 commits into from
Jul 10, 2024
13 changes: 3 additions & 10 deletions docs/intro_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,15 @@ fidelity function between quantum states that happen to be identical.

>>> from toqito.states import bell
>>> from toqito.state_metrics import fidelity
>>> import numpy as np
>>>
>>> # Define two identical density operators.
>>> rho = bell(0)*bell(0).conj().T
>>> sigma = bell(0)*bell(0).conj().T
>>>
>>> # Calculate the fidelity between `rho` and `sigma`
>>> '%.2f' % fidelity(rho, sigma)
'1.00'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(fidelity(rho, sigma), decimals=2)
1.0

There are a number of other metrics one can compute on two density matrices
including the trace norm, trace distance. These and others are also available
Expand Down
127 changes: 30 additions & 97 deletions docs/tutorials.extended_nonlocal_games.rst
Original file line number Diff line number Diff line change
Expand Up @@ -316,21 +316,14 @@ This can be verified in :code:`toqito` as follows.

>>> # Calculate the unentangled value of the BB84 extended nonlocal game.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # 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
>>> '%.2f' % bb84.unentangled_value()
'0.85'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(bb84.unentangled_value(), decimals=2)
0.85

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
Expand All @@ -340,21 +333,14 @@ example of two parallel repetitions for the BB84 game.

>>> # The unentangled value of BB84 under parallel repetition.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # 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
>>> '%.2f' % bb84_2_reps.unentangled_value()
'0.73'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(bb84_2_reps.unentangled_value(), decimals=2)
0.73

It was shown in :cite:`Johnston_2016_Extended` that the BB84 game possesses the property of strong
parallel repetition. That is,
Expand All @@ -374,21 +360,14 @@ using :code:`toqito` as well.

>>> # Calculate lower bounds on the standard quantum value of the BB84 extended nonlocal game.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # 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
>>> '%.2f' % bb84_lb.quantum_value_lower_bound()
'0.85'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(bb84_lb.quantum_value_lower_bound(), decimals=2)
0.85

From :cite:`Johnston_2016_Extended`, it is known that :math:`\omega(G_{BB84}) =
\omega^*(G_{BB84})`, however, if we did not know this beforehand, we could
Expand All @@ -409,20 +388,14 @@ Using :code:`toqito`, we can see that :math:`\omega_{ns}(G) = \cos^2(\pi/8)`.

>>> # Calculate the non-signaling value of the BB84 extended nonlocal game.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # 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
>>> '%.2f' % bb84.nonsignaling_value()
'0.85'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(bb84.nonsignaling_value(), decimals=2)
0.85

So we have the relationship that

Expand All @@ -437,20 +410,14 @@ can observe this by the following snippet.

>>> # The non-signaling value of BB84 under parallel repetition.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # 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
>>> '%.2f' % bb84_2_reps.nonsignaling_value()
'0.74'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(bb84_2_reps.nonsignaling_value(), decimals=2)
0.74

Note that :math:`0.73825 \geq \cos(\pi/8)^4 \approx 0.72855` and therefore we
have that
Expand Down Expand Up @@ -554,42 +521,29 @@ the unentangled value of :math:`G_{CHSH}`.

>>> # Calculate the unentangled value of the CHSH extended nonlocal game
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # Define an ExtendedNonlocalGame object based on the CHSH game.
>>> chsh = ExtendedNonlocalGame(chsh_prob_mat, chsh_pred_mat)
>>>
>>> # The unentangled value is 3/4 = 0.75
>>> '%.2f' % chsh.unentangled_value()
'0.75'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(chsh.unentangled_value(), decimals=2)
0.75

We can also run multiple repetitions of :math:`G_{CHSH}`.

.. code-block:: python

>>> # The unentangled value of CHSH under parallel repetition.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # Define the CHSH game for two parallel repetitions.
>>> chsh_2_reps = ExtendedNonlocalGame(chsh_prob_mat, chsh_pred_mat, 2)
>>>
>>> # The unentangled value for two parallel repetitions is (3/4)**2 \approx 0.5625
>>> '%.2f' % chsh_2_reps.unentangled_value()
'0.56'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(chsh_2_reps.unentangled_value(), decimals=2)
0.56

Note that strong parallel repetition holds as

Expand All @@ -606,21 +560,14 @@ non-signaling value.

>>> # Calculate the non-signaling value of the CHSH extended nonlocal game.
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
>>> import numpy as np
>>>
>>> # Define an ExtendedNonlocalGame object based on the CHSH game.
>>> chsh = ExtendedNonlocalGame(chsh_prob_mat, chsh_pred_mat)
>>>
>>> # The non-signaling value is 3/4 = 0.75
>>> '%.2f' % chsh.nonsignaling_value()
'0.75'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.

>>> np.around(chsh.nonsignaling_value(), decimals=2)
0.75

As we know that :math:`\omega(G_{CHSH}) = \omega_{ns}(G_{CHSH}) = 3/4` and that

Expand Down Expand Up @@ -739,18 +686,11 @@ Now that we have encoded :math:`G_{MUB}`, we can calculate the unentangled value

.. code-block:: python

>>> import numpy as np
>>> g_mub = ExtendedNonlocalGame(prob_mat, pred_mat)
>>> unent_val = g_mub.unentangled_value()
>>> '%.2f' % unent_val
'0.65'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(unent_val, decimals=2)
0.65

That is, we have that

Expand All @@ -763,18 +703,11 @@ obtain.

.. code-block:: python

>>> import numpy as np
>>> g_mub = ExtendedNonlocalGame(prob_mat, pred_mat)
>>> q_val = g_mub.quantum_value_lower_bound()
>>> '%.2f' % q_val
'0.66'


.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(q_val, decimals=2)
0.66

Note that as we are calculating a lower bound, it is possible that a value this
high will not be obtained, or in other words, the algorithm can get stuck in a
Expand Down
27 changes: 7 additions & 20 deletions docs/tutorials.nonlocal_games.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,17 +343,11 @@ use :code:`toqito` to determine the lower bound on the quantum value.

.. code-block:: python

>>> import numpy as np
>>> from toqito.nonlocal_games.nonlocal_game import NonlocalGame
>>> chsh = NonlocalGame(prob_mat, pred_mat)
>>> '%.2f' % chsh.quantum_value_lower_bound()
'0.85'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(chsh.quantum_value_lower_bound(), decimals=2)
0.85

In this case, we can see that the quantum value of the CHSH game is in fact
attained as :math:`\cos^2(\pi/8) \approx 0.85355`.
Expand Down Expand Up @@ -419,17 +413,10 @@ value and calculate lower bounds on the quantum value of the FFL game.
... pred_mat[a_alice, b_bob, x_alice, y_bob] = 1
>>> # Define the FFL game object.
>>> ffl = NonlocalGame(prob_mat, pred_mat)
>>> '%.2f' % ffl.classical_value()
'0.67'
>>> '%.2f' % ffl.quantum_value_lower_bound()
'0.22'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(ffl.classical_value(), decimals=2)
0.67
>>> np.around(ffl.quantum_value_lower_bound(), decimals=2)
0.22

In this case, we obtained the correct quantum value of :math:`2/3`, however,
the lower bound technique is not guaranteed to converge to the true quantum
Expand Down
23 changes: 5 additions & 18 deletions docs/tutorials.state_distinguishability.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ Using :code:`toqito`, we can calculate this probability directly as follows:

.. code-block:: python

>>> import numpy as np
>>> from toqito.states import basis
>>> from toqito.state_opt import state_distinguishability
>>>
Expand All @@ -132,15 +133,8 @@ Using :code:`toqito`, we can calculate this probability directly as follows:
>>>
>>> # Calculate the probability with which Bob can
>>> # distinguish the state he is provided.
>>> '%.2f' % state_distinguishability(states, probs)[0]
'1.00'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(state_distinguishability(states, probs)[0], decimals=2)
1.0

Specifying similar state distinguishability problems can be done so using this
general pattern.
Expand Down Expand Up @@ -235,15 +229,8 @@ via PPT measurements in the following manner.
>>>
>>> states = [rho_1, rho_2, rho_3, rho_4]
>>> probs = [1 / 4, 1 / 4, 1 / 4, 1 / 4]
>>> '%.2f' % ppt_distinguishability(vectors=states, probs=probs, dimensions=[2, 2, 2, 2], subsystems=[0, 2])[0]
'0.87'

.. note::
You do not need to use `'%.2f' %` when you use this function.
We use this to format our output such that `doctest` compares the calculated output to the
expected output upto two decimal points only. The accuracy of the solvers can calculate the
`float` output to a certain amount of precision such that the value deviates after a few digits
of accuracy.
>>> np.around(ppt_distinguishability(vectors=states, probs=probs, dimensions=[2, 2, 2, 2], subsystems=[0, 2])[0], decimals=2)
0.87

Probability of distinguishing a state via separable measurements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Loading