-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from vprusso/bb84-states
Adding BB84 states.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |