Skip to content

Commit

Permalink
Merge pull request #327 from vprusso/bb84-states
Browse files Browse the repository at this point in the history
Adding BB84 states.
  • Loading branch information
vprusso authored Dec 4, 2023
2 parents 2edcc71 + be349bb commit 8ec4bf3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
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)

0 comments on commit 8ec4bf3

Please sign in to comment.