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

Adding BB84 states. #327

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/articles.bib
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions toqito/states/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 43 additions & 0 deletions toqito/states/bb84.py
Original file line number Diff line number Diff line change
@@ -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]]
17 changes: 17 additions & 0 deletions toqito/states/tests/test_bb84.py
Original file line number Diff line number Diff line change
@@ -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)