From 7ad05e76fe0158b412d3a3c3718e92fb82331daa Mon Sep 17 00:00:00 2001 From: vrusso Date: Sun, 3 Dec 2023 21:47:49 -0500 Subject: [PATCH 1/4] Adding BB84 states. --- docs/articles.bib | 8 ++++++ toqito/states/bb84.py | 43 ++++++++++++++++++++++++++++++++ toqito/states/tests/test_bb84.py | 17 +++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 toqito/states/bb84.py create mode 100644 toqito/states/tests/test_bb84.py diff --git a/docs/articles.bib b/docs/articles.bib index 42def0879..9f507dd74 100644 --- a/docs/articles.bib +++ b/docs/articles.bib @@ -745,6 +745,14 @@ @misc{WikiAsymmOp } +@misc{WikiBB84, + author = "Wikipedia", + title = "BB84", + howpublished = {https://en.wikipedia.org/wiki/BB84} + +} + + @misc{WikiBellSt, author = "Wikipedia", title = "Bell State", diff --git a/toqito/states/bb84.py b/toqito/states/bb84.py new file mode 100644 index 000000000..9962479e6 --- /dev/null +++ b/toqito/states/bb84.py @@ -0,0 +1,43 @@ +"""BB84 basis states""" +import numpy as np +from toqito.matrices import standard_basis + + +def bb84() -> np.ndarray: + r"""Obtain the BB84 basis states :cite:`WikiBB84`. + + The BB84 basis states are defined as + + .. math:: + |0\rangle := \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad \\ + |1\rangle := \begin{pmatrix} 0 \\ 1 \end{pmatrix}, \quad \\ + |+\rangle := \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ 1 \end{pmatrix}, \quad \\ + |-\rangle := \frac{1}{\sqrt{2}} \begin{pmatrix} 1 \\ -1 \end{pmatrix}. + + Examples + ========== + The BB84 basis states can be obtained in :code:`toqito` as follows. + + >>> from toqito.states import bb84 + >>> states = bb84() + >>> print(f"|0> = {x[0][0].T}, \n |1> = {x[0][1].T}") + >>> print(f"|+> = {x[1][0].T}, \n |-> = {x[1][1].T}") + |0> = [[1. 0.]], + |1> = [[0. 1.]] + |+> = [[0.70710678 0.70710678]], + |-> = [[ 0.70710678 -0.70710678]] + + References + ========== + .. bibliography:: + :filter: docname in docnames + + + :return: The four BB84 basis states. + """ + # Computational basis states |0>, |1>: + e_0, e_1 = standard_basis(2) + # Plus/minus basis |+>, |-> + e_p, e_m = (e_0 + e_1) / np.sqrt(2), (e_0 - e_1) / np.sqrt(2) + return [[e_0, e_1], [e_p, e_m]] + \ No newline at end of file diff --git a/toqito/states/tests/test_bb84.py b/toqito/states/tests/test_bb84.py new file mode 100644 index 000000000..70b472638 --- /dev/null +++ b/toqito/states/tests/test_bb84.py @@ -0,0 +1,17 @@ +"""Test BB84.""" +import numpy as np + +from toqito.states import bb84 + + +def test_bb84(): + """Test function generates the correct BB84 states.""" + e_0, e_1 = np.array([[1], [0]]), np.array([[0], [1]]) + e_p, e_m = (e_0 + e_1) / np.sqrt(2), (e_0 - e_1) / np.sqrt(2) + + states = bb84() + + np.testing.assert_array_equal(states[0][0], e_0) + np.testing.assert_array_equal(states[0][1], e_1) + np.testing.assert_array_equal(states[1][0], e_p) + np.testing.assert_array_equal(states[1][1], e_m) From ff0329a492828b7e8186d99280894dad390067d0 Mon Sep 17 00:00:00 2001 From: vrusso Date: Sun, 3 Dec 2023 21:55:37 -0500 Subject: [PATCH 2/4] Fixing failing test. --- toqito/states/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/toqito/states/__init__.py b/toqito/states/__init__.py index e8d018aab..c6614dffd 100644 --- a/toqito/states/__init__.py +++ b/toqito/states/__init__.py @@ -1,5 +1,6 @@ """Quantum states.""" from toqito.states.basis import basis +from toqito.states.bb84 import bb84 from toqito.states.bell import bell from toqito.states.chessboard import chessboard from toqito.states.domino import domino From 9bec85b9848dec86cd68a2eb302a1a6434e309f9 Mon Sep 17 00:00:00 2001 From: vrusso Date: Sun, 3 Dec 2023 22:17:04 -0500 Subject: [PATCH 3/4] fixing failing test. --- toqito/states/bb84.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/toqito/states/bb84.py b/toqito/states/bb84.py index 9962479e6..3518611da 100644 --- a/toqito/states/bb84.py +++ b/toqito/states/bb84.py @@ -1,4 +1,4 @@ -"""BB84 basis states""" +"""BB84 basis states.""" import numpy as np from toqito.matrices import standard_basis @@ -22,10 +22,10 @@ def bb84() -> np.ndarray: >>> states = bb84() >>> print(f"|0> = {x[0][0].T}, \n |1> = {x[0][1].T}") >>> print(f"|+> = {x[1][0].T}, \n |-> = {x[1][1].T}") - |0> = [[1. 0.]], + |0> = [[1. 0.]], |1> = [[0. 1.]] - |+> = [[0.70710678 0.70710678]], - |-> = [[ 0.70710678 -0.70710678]] + |+> = [[0.70710678 0.70710678]], + |-> = [[ 0.70710678 -0.70710678]] References ========== @@ -40,4 +40,3 @@ def bb84() -> np.ndarray: # Plus/minus basis |+>, |-> e_p, e_m = (e_0 + e_1) / np.sqrt(2), (e_0 - e_1) / np.sqrt(2) return [[e_0, e_1], [e_p, e_m]] - \ No newline at end of file From be349bb1927b44bfade0a835f7d231a6da6b47f4 Mon Sep 17 00:00:00 2001 From: vrusso Date: Sun, 3 Dec 2023 22:31:21 -0500 Subject: [PATCH 4/4] fixing failing test. --- toqito/states/bb84.py | 1 + 1 file changed, 1 insertion(+) diff --git a/toqito/states/bb84.py b/toqito/states/bb84.py index 3518611da..40ab38172 100644 --- a/toqito/states/bb84.py +++ b/toqito/states/bb84.py @@ -1,5 +1,6 @@ """BB84 basis states.""" import numpy as np + from toqito.matrices import standard_basis