Skip to content

Commit c77ec5c

Browse files
authored
Merge pull request #651 from vprusso/650-remove-float-note
Removing redundant note for doctest.
2 parents d21f003 + c3111f3 commit c77ec5c

25 files changed

Lines changed: 118 additions & 419 deletions

docs/intro_tutorial.rst

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,22 +272,15 @@ fidelity function between quantum states that happen to be identical.
272272
273273
>>> from toqito.states import bell
274274
>>> from toqito.state_metrics import fidelity
275+
>>> import numpy as np
275276
>>>
276277
>>> # Define two identical density operators.
277278
>>> rho = bell(0)*bell(0).conj().T
278279
>>> sigma = bell(0)*bell(0).conj().T
279280
>>>
280281
>>> # Calculate the fidelity between `rho` and `sigma`
281-
>>> '%.2f' % fidelity(rho, sigma)
282-
'1.00'
283-
284-
285-
.. note::
286-
You do not need to use `'%.2f' %` when you use this function.
287-
We use this to format our output such that `doctest` compares the calculated output to the
288-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
289-
`float` output to a certain amount of precision such that the value deviates after a few digits
290-
of accuracy.
282+
>>> np.around(fidelity(rho, sigma), decimals=2)
283+
1.0
291284
292285
There are a number of other metrics one can compute on two density matrices
293286
including the trace norm, trace distance. These and others are also available

docs/tutorials.extended_nonlocal_games.rst

Lines changed: 30 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,14 @@ This can be verified in :code:`toqito` as follows.
316316
317317
>>> # Calculate the unentangled value of the BB84 extended nonlocal game.
318318
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
319+
>>> import numpy as np
319320
>>>
320321
>>> # Define an ExtendedNonlocalGame object based on the BB84 game.
321322
>>> bb84 = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat)
322323
>>>
323324
>>> # The unentangled value is cos(pi/8)**2 \approx 0.85356
324-
>>> '%.2f' % bb84.unentangled_value()
325-
'0.85'
326-
327-
328-
.. note::
329-
You do not need to use `'%.2f' %` when you use this function.
330-
We use this to format our output such that `doctest` compares the calculated output to the
331-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
332-
`float` output to a certain amount of precision such that the value deviates after a few digits
333-
of accuracy.
325+
>>> np.around(bb84.unentangled_value(), decimals=2)
326+
0.85
334327
335328
The BB84 game also exhibits strong parallel repetition. We can specify how many
336329
parallel repetitions for :code:`toqito` to run. The example below provides an
@@ -340,21 +333,14 @@ example of two parallel repetitions for the BB84 game.
340333
341334
>>> # The unentangled value of BB84 under parallel repetition.
342335
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
336+
>>> import numpy as np
343337
>>>
344338
>>> # Define the bb84 game for two parallel repetitions.
345339
>>> bb84_2_reps = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat, 2)
346340
>>>
347341
>>> # The unentangled value for two parallel repetitions is cos(pi/8)**4 \approx 0.72855
348-
>>> '%.2f' % bb84_2_reps.unentangled_value()
349-
'0.73'
350-
351-
352-
.. note::
353-
You do not need to use `'%.2f' %` when you use this function.
354-
We use this to format our output such that `doctest` compares the calculated output to the
355-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
356-
`float` output to a certain amount of precision such that the value deviates after a few digits
357-
of accuracy.
342+
>>> np.around(bb84_2_reps.unentangled_value(), decimals=2)
343+
0.73
358344
359345
It was shown in :cite:`Johnston_2016_Extended` that the BB84 game possesses the property of strong
360346
parallel repetition. That is,
@@ -374,21 +360,14 @@ using :code:`toqito` as well.
374360
375361
>>> # Calculate lower bounds on the standard quantum value of the BB84 extended nonlocal game.
376362
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
363+
>>> import numpy as np
377364
>>>
378365
>>> # Define an ExtendedNonlocalGame object based on the BB84 game.
379366
>>> bb84_lb = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat)
380367
>>>
381368
>>> # The standard quantum value is cos(pi/8)**2 \approx 0.85356
382-
>>> '%.2f' % bb84_lb.quantum_value_lower_bound()
383-
'0.85'
384-
385-
386-
.. note::
387-
You do not need to use `'%.2f' %` when you use this function.
388-
We use this to format our output such that `doctest` compares the calculated output to the
389-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
390-
`float` output to a certain amount of precision such that the value deviates after a few digits
391-
of accuracy.
369+
>>> np.around(bb84_lb.quantum_value_lower_bound(), decimals=2)
370+
0.85
392371
393372
From :cite:`Johnston_2016_Extended`, it is known that :math:`\omega(G_{BB84}) =
394373
\omega^*(G_{BB84})`, however, if we did not know this beforehand, we could
@@ -409,20 +388,14 @@ Using :code:`toqito`, we can see that :math:`\omega_{ns}(G) = \cos^2(\pi/8)`.
409388
410389
>>> # Calculate the non-signaling value of the BB84 extended nonlocal game.
411390
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
391+
>>> import numpy as np
412392
>>>
413393
>>> # Define an ExtendedNonlocalGame object based on the BB84 game.
414394
>>> bb84 = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat)
415395
>>>
416396
>>> # The non-signaling value is cos(pi/8)**2 \approx 0.85356
417-
>>> '%.2f' % bb84.nonsignaling_value()
418-
'0.85'
419-
420-
.. note::
421-
You do not need to use `'%.2f' %` when you use this function.
422-
We use this to format our output such that `doctest` compares the calculated output to the
423-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
424-
`float` output to a certain amount of precision such that the value deviates after a few digits
425-
of accuracy.
397+
>>> np.around(bb84.nonsignaling_value(), decimals=2)
398+
0.85
426399
427400
So we have the relationship that
428401

@@ -437,20 +410,14 @@ can observe this by the following snippet.
437410
438411
>>> # The non-signaling value of BB84 under parallel repetition.
439412
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
413+
>>> import numpy as np
440414
>>>
441415
>>> # Define the bb84 game for two parallel repetitions.
442416
>>> bb84_2_reps = ExtendedNonlocalGame(bb84_prob_mat, bb84_pred_mat, 2)
443417
>>>
444418
>>> # The non-signaling value for two parallel repetitions is cos(pi/8)**4 \approx 0.73825
445-
>>> '%.2f' % bb84_2_reps.nonsignaling_value()
446-
'0.74'
447-
448-
.. note::
449-
You do not need to use `'%.2f' %` when you use this function.
450-
We use this to format our output such that `doctest` compares the calculated output to the
451-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
452-
`float` output to a certain amount of precision such that the value deviates after a few digits
453-
of accuracy.
419+
>>> np.around(bb84_2_reps.nonsignaling_value(), decimals=2)
420+
0.74
454421
455422
Note that :math:`0.73825 \geq \cos(\pi/8)^4 \approx 0.72855` and therefore we
456423
have that
@@ -554,42 +521,29 @@ the unentangled value of :math:`G_{CHSH}`.
554521
555522
>>> # Calculate the unentangled value of the CHSH extended nonlocal game
556523
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
524+
>>> import numpy as np
557525
>>>
558526
>>> # Define an ExtendedNonlocalGame object based on the CHSH game.
559527
>>> chsh = ExtendedNonlocalGame(chsh_prob_mat, chsh_pred_mat)
560528
>>>
561529
>>> # The unentangled value is 3/4 = 0.75
562-
>>> '%.2f' % chsh.unentangled_value()
563-
'0.75'
564-
565-
.. note::
566-
You do not need to use `'%.2f' %` when you use this function.
567-
We use this to format our output such that `doctest` compares the calculated output to the
568-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
569-
`float` output to a certain amount of precision such that the value deviates after a few digits
570-
of accuracy.
530+
>>> np.around(chsh.unentangled_value(), decimals=2)
531+
0.75
571532
572533
We can also run multiple repetitions of :math:`G_{CHSH}`.
573534

574535
.. code-block:: python
575536
576537
>>> # The unentangled value of CHSH under parallel repetition.
577538
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
539+
>>> import numpy as np
578540
>>>
579541
>>> # Define the CHSH game for two parallel repetitions.
580542
>>> chsh_2_reps = ExtendedNonlocalGame(chsh_prob_mat, chsh_pred_mat, 2)
581543
>>>
582544
>>> # The unentangled value for two parallel repetitions is (3/4)**2 \approx 0.5625
583-
>>> '%.2f' % chsh_2_reps.unentangled_value()
584-
'0.56'
585-
586-
587-
.. note::
588-
You do not need to use `'%.2f' %` when you use this function.
589-
We use this to format our output such that `doctest` compares the calculated output to the
590-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
591-
`float` output to a certain amount of precision such that the value deviates after a few digits
592-
of accuracy.
545+
>>> np.around(chsh_2_reps.unentangled_value(), decimals=2)
546+
0.56
593547
594548
Note that strong parallel repetition holds as
595549

@@ -606,21 +560,14 @@ non-signaling value.
606560
607561
>>> # Calculate the non-signaling value of the CHSH extended nonlocal game.
608562
>>> from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
563+
>>> import numpy as np
609564
>>>
610565
>>> # Define an ExtendedNonlocalGame object based on the CHSH game.
611566
>>> chsh = ExtendedNonlocalGame(chsh_prob_mat, chsh_pred_mat)
612567
>>>
613568
>>> # The non-signaling value is 3/4 = 0.75
614-
>>> '%.2f' % chsh.nonsignaling_value()
615-
'0.75'
616-
617-
.. note::
618-
You do not need to use `'%.2f' %` when you use this function.
619-
We use this to format our output such that `doctest` compares the calculated output to the
620-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
621-
`float` output to a certain amount of precision such that the value deviates after a few digits
622-
of accuracy.
623-
569+
>>> np.around(chsh.nonsignaling_value(), decimals=2)
570+
0.75
624571
625572
As we know that :math:`\omega(G_{CHSH}) = \omega_{ns}(G_{CHSH}) = 3/4` and that
626573

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

740687
.. code-block:: python
741688
689+
>>> import numpy as np
742690
>>> g_mub = ExtendedNonlocalGame(prob_mat, pred_mat)
743691
>>> unent_val = g_mub.unentangled_value()
744-
>>> '%.2f' % unent_val
745-
'0.65'
746-
747-
748-
.. note::
749-
You do not need to use `'%.2f' %` when you use this function.
750-
We use this to format our output such that `doctest` compares the calculated output to the
751-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
752-
`float` output to a certain amount of precision such that the value deviates after a few digits
753-
of accuracy.
692+
>>> np.around(unent_val, decimals=2)
693+
0.65
754694
755695
That is, we have that
756696

@@ -763,18 +703,11 @@ obtain.
763703

764704
.. code-block:: python
765705
706+
>>> import numpy as np
766707
>>> g_mub = ExtendedNonlocalGame(prob_mat, pred_mat)
767708
>>> q_val = g_mub.quantum_value_lower_bound()
768-
>>> '%.2f' % q_val
769-
'0.66'
770-
771-
772-
.. note::
773-
You do not need to use `'%.2f' %` when you use this function.
774-
We use this to format our output such that `doctest` compares the calculated output to the
775-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
776-
`float` output to a certain amount of precision such that the value deviates after a few digits
777-
of accuracy.
709+
>>> np.around(q_val, decimals=2)
710+
0.66
778711
779712
Note that as we are calculating a lower bound, it is possible that a value this
780713
high will not be obtained, or in other words, the algorithm can get stuck in a

docs/tutorials.nonlocal_games.rst

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,11 @@ use :code:`toqito` to determine the lower bound on the quantum value.
343343

344344
.. code-block:: python
345345
346+
>>> import numpy as np
346347
>>> from toqito.nonlocal_games.nonlocal_game import NonlocalGame
347348
>>> chsh = NonlocalGame(prob_mat, pred_mat)
348-
>>> '%.2f' % chsh.quantum_value_lower_bound()
349-
'0.85'
350-
351-
.. note::
352-
You do not need to use `'%.2f' %` when you use this function.
353-
We use this to format our output such that `doctest` compares the calculated output to the
354-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
355-
`float` output to a certain amount of precision such that the value deviates after a few digits
356-
of accuracy.
349+
>>> np.around(chsh.quantum_value_lower_bound(), decimals=2)
350+
0.85
357351
358352
In this case, we can see that the quantum value of the CHSH game is in fact
359353
attained as :math:`\cos^2(\pi/8) \approx 0.85355`.
@@ -419,17 +413,10 @@ value and calculate lower bounds on the quantum value of the FFL game.
419413
... pred_mat[a_alice, b_bob, x_alice, y_bob] = 1
420414
>>> # Define the FFL game object.
421415
>>> ffl = NonlocalGame(prob_mat, pred_mat)
422-
>>> '%.2f' % ffl.classical_value()
423-
'0.67'
424-
>>> '%.2f' % ffl.quantum_value_lower_bound()
425-
'0.22'
426-
427-
.. note::
428-
You do not need to use `'%.2f' %` when you use this function.
429-
We use this to format our output such that `doctest` compares the calculated output to the
430-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
431-
`float` output to a certain amount of precision such that the value deviates after a few digits
432-
of accuracy.
416+
>>> np.around(ffl.classical_value(), decimals=2)
417+
0.67
418+
>>> np.around(ffl.quantum_value_lower_bound(), decimals=2)
419+
0.22
433420
434421
In this case, we obtained the correct quantum value of :math:`2/3`, however,
435422
the lower bound technique is not guaranteed to converge to the true quantum

docs/tutorials.state_distinguishability.rst

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Using :code:`toqito`, we can calculate this probability directly as follows:
114114

115115
.. code-block:: python
116116
117+
>>> import numpy as np
117118
>>> from toqito.states import basis
118119
>>> from toqito.state_opt import state_distinguishability
119120
>>>
@@ -132,15 +133,8 @@ Using :code:`toqito`, we can calculate this probability directly as follows:
132133
>>>
133134
>>> # Calculate the probability with which Bob can
134135
>>> # distinguish the state he is provided.
135-
>>> '%.2f' % state_distinguishability(states, probs)[0]
136-
'1.00'
137-
138-
.. note::
139-
You do not need to use `'%.2f' %` when you use this function.
140-
We use this to format our output such that `doctest` compares the calculated output to the
141-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
142-
`float` output to a certain amount of precision such that the value deviates after a few digits
143-
of accuracy.
136+
>>> np.around(state_distinguishability(states, probs)[0], decimals=2)
137+
1.0
144138
145139
Specifying similar state distinguishability problems can be done so using this
146140
general pattern.
@@ -235,15 +229,8 @@ via PPT measurements in the following manner.
235229
>>>
236230
>>> states = [rho_1, rho_2, rho_3, rho_4]
237231
>>> probs = [1 / 4, 1 / 4, 1 / 4, 1 / 4]
238-
>>> '%.2f' % ppt_distinguishability(vectors=states, probs=probs, dimensions=[2, 2, 2, 2], subsystems=[0, 2])[0]
239-
'0.87'
240-
241-
.. note::
242-
You do not need to use `'%.2f' %` when you use this function.
243-
We use this to format our output such that `doctest` compares the calculated output to the
244-
expected output upto two decimal points only. The accuracy of the solvers can calculate the
245-
`float` output to a certain amount of precision such that the value deviates after a few digits
246-
of accuracy.
232+
>>> np.around(ppt_distinguishability(vectors=states, probs=probs, dimensions=[2, 2, 2, 2], subsystems=[0, 2])[0], decimals=2)
233+
0.87
247234
248235
Probability of distinguishing a state via separable measurements
249236
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)