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

Remove basis function in favor of standard_basis #936

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions docs/intro_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ can be defined in :code:`toqito` as such

.. code-block:: python

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> e_0, e_1 = standard_basis(2)
>>> # |0>
>>> basis(2, 0)
>>> e_0
array([[1],
[0]])

>>> # |1>
>>> basis(2, 1)
>>> e_1
array([[0],
[1]])

Expand All @@ -66,7 +67,8 @@ using :code:`toqito` as
.. code-block:: python

>>> import numpy as np
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> from toqito.matrices import standard_basis
>>> e_0, e_1 = standard_basis(2)
>>> u_0 = 1/np.sqrt(2) * (np.kron(e_0, e_0) + np.kron(e_1, e_1))
>>> u_0
array([[0.70710678],
Expand All @@ -91,7 +93,8 @@ In :code:`toqito`, that can be obtained as
.. code-block:: python

>>> import numpy as np
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> from toqito.matrices import standard_basis
>>> e_0, e_1 = standard_basis(2)
>>> u_0 = 1/np.sqrt(2) * (np.kron(e_0, e_0) + np.kron(e_1, e_1))
>>> rho_0 = u_0 @ u_0.conj().T
>>> rho_0
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials.extended_nonlocal_games.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,10 @@ arrays where :code:`prob_mat` corresponds to the probability distribution

>>> # Define the BB84 extended nonlocal game.
>>> import numpy as np
>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>>
>>> # The basis: {|0>, |1>}:
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis
>>>
>>> # The basis: {|+>, |->}:
>>> e_p = (e_0 + e_1) / np.sqrt(2)
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials.state_distinguishability.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ Using :code:`toqito`, we can calculate this probability directly as follows:
.. code-block:: python

>>> import numpy as np
>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.state_opt import state_distinguishability
>>>
>>> # Define the standard basis |0> and |1>
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>>
>>> # Define the corresponding density matrices of |0> and |1>
>>> # given as |0><0| and |1><1|, respectively.
Expand Down
5 changes: 3 additions & 2 deletions toqito/channel_metrics/fidelity_of_separability.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ def fidelity_of_separability(
>>> import numpy as np
>>> from toqito.state_metrics import fidelity_of_separability
>>> from toqito.matrix_ops import tensor
>>> from toqito.states import basis
>>> state = tensor(basis(2, 0), basis(2, 0))
>>> from toqito.matrices import standard_basis
>>> e_0, e_1 = standard_basis(2)
>>> state = tensor(e_0, e_1)
>>> rho = state @ state.conj().T
>>> np.around(fidelity_of_separability(rho, [2, 2]), decimals=2)
np.float64(1.0)
Expand Down
12 changes: 6 additions & 6 deletions toqito/matrix_ops/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ def tensor(*args) -> np.ndarray:

This can be accomplished in :code:`toqito` as follows.

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.matrix_ops import tensor
>>> e_0 = basis(2, 0)
>>> e_0, _ = standard_basis(2)
>>> tensor(e_0, e_0)
array([[1],
[0],
Expand All @@ -71,9 +71,9 @@ def tensor(*args) -> np.ndarray:

in :code:`toqito` as follows.

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.matrix_ops import tensor
>>> e_0 = basis(2, 0)
>>> e_0, _ = standard_basis(2)
>>> tensor(e_0, 3)
array([[1],
[0],
Expand All @@ -91,9 +91,9 @@ def tensor(*args) -> np.ndarray:
compute :math:`e_0 \otimes e_1 \otimes e_0`, we can do
so as follows.

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.matrix_ops import tensor
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>> tensor([e_0, e_1, e_0])
array([[0],
[0],
Expand Down
4 changes: 2 additions & 2 deletions toqito/matrix_ops/tests/test_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import pytest

from toqito.matrices import standard_basis
from toqito.matrix_ops import tensor
from toqito.states import basis

e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
matrix1 = np.array([[1, 2]])
matrix2 = np.array([[3], [4]])
matrix3 = np.array([[5, 6]])
Expand Down
4 changes: 2 additions & 2 deletions toqito/matrix_ops/tests/test_tensor_comb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import numpy as np
import pytest

from toqito.matrices import standard_basis
from toqito.matrix_ops import tensor_comb
from toqito.states import basis

e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)


@pytest.mark.parametrize(
Expand Down
7 changes: 3 additions & 4 deletions toqito/matrix_props/tests/test_sk_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import numpy as np
import pytest

from toqito.matrices import standard_basis
from toqito.matrix_props import sk_operator_norm
from toqito.states import basis, max_entangled, werner
from toqito.states import max_entangled, werner


def test_s1_norm_example():
Expand Down Expand Up @@ -60,10 +61,8 @@ def test_s1_norm_werner(n, a):

def test_sk_norm_hermitian_not_psd():
"""Test S(k) norm of a Hermitian but not PSD matrix."""
e_0 = basis(2, 0)
e_0, e_1 = standard_basis(2)
e_00 = np.kron(e_0, e_0)

e_1 = basis(2, 1)
e_11 = np.kron(e_1, e_1)

mat = e_00 @ e_11.T + e_11 @ e_00.T
Expand Down
4 changes: 2 additions & 2 deletions toqito/matrix_props/tests/test_trace_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import numpy as np

from toqito.matrices import standard_basis
from toqito.matrix_props import trace_norm
from toqito.states import basis


def test_trace_norm():
"""Test trace norm."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
e_00 = np.kron(e_0, e_0)
e_11 = np.kron(e_1, e_1)

Expand Down
4 changes: 2 additions & 2 deletions toqito/measurement_ops/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def measure(measurement: np.ndarray, state: np.ndarray) -> float:
.. math::
P_0 = e_0 e_0^* \quad \text{and} \quad P_1 = e_1 e_1^*.

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basi
>>> from toqito.measurement_ops import measure
>>> import numpy as np
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>>
>>> u = 1/np.sqrt(3) * e_0 + np.sqrt(2/3) * e_1
>>> rho = u @ u.conj().T
Expand Down
4 changes: 2 additions & 2 deletions toqito/measurement_ops/tests/test_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import numpy as np

from toqito.matrices import standard_basis
from toqito.measurement_ops import measure
from toqito.states import basis


def test_measure_state():
"""Test measure on quantum state."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
psi = 1 / np.sqrt(3) * e_0 + np.sqrt(2 / 3) * e_1
rho = psi @ psi.conj().T

Expand Down
4 changes: 2 additions & 2 deletions toqito/nonlocal_games/quantum_hedging.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class QuantumHedging:

>>> import numpy as np
>>> from numpy import kron, cos, sin, pi, sqrt, isclose
>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.nonlocal_games.quantum_hedging import QuantumHedging
>>>
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>> e_00, e_01 = kron(e_0, e_0), kron(e_0, e_1)
>>> e_10, e_11 = kron(e_1, e_0), kron(e_1, e_1)
>>>
Expand Down
6 changes: 3 additions & 3 deletions toqito/nonlocal_games/tests/test_extended_nonlocal_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import numpy as np

from toqito.matrices import standard_basis
from toqito.nonlocal_games.extended_nonlocal_game import ExtendedNonlocalGame
from toqito.states import basis


class TestExtendedNonlocalGame(unittest.TestCase):
Expand All @@ -14,7 +14,7 @@ class TestExtendedNonlocalGame(unittest.TestCase):
@staticmethod
def bb84_extended_nonlocal_game():
"""Define the BB84 extended nonlocal game."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
e_p = (e_0 + e_1) / np.sqrt(2)
e_m = (e_0 - e_1) / np.sqrt(2)

Expand Down Expand Up @@ -61,7 +61,7 @@ def moe_mub_4_in_3_out_game():
prob_mat = 1 / 4 * np.identity(4)

dim = 3
e_0, e_1, e_2 = basis(dim, 0), basis(dim, 1), basis(dim, 2)
e_0, e_1, e_2 = standard_basis(3)

eta = np.exp((2 * np.pi * 1j) / dim)
mub_0 = [e_0, e_1, e_2]
Expand Down
4 changes: 2 additions & 2 deletions toqito/nonlocal_games/tests/test_quantum_hedging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

from numpy import cos, isclose, kron, pi, sin, sqrt

from toqito.matrices import standard_basis
from toqito.nonlocal_games.quantum_hedging import QuantumHedging
from toqito.states import basis


class TestQuantumHedging(unittest.TestCase):
"""Unit test for hedging_value."""

e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
e_00, e_01 = kron(e_0, e_0), kron(e_0, e_1)
e_10, e_11 = kron(e_1, e_0), kron(e_1, e_1)

Expand Down
5 changes: 3 additions & 2 deletions toqito/state_metrics/fidelity_of_separability.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ def fidelity_of_separability(
>>> import numpy as np
>>> from toqito.state_metrics import fidelity_of_separability
>>> from toqito.matrix_ops import tensor
>>> from toqito.states import basis
>>> state = tensor(basis(2, 0), basis(2, 0))
>>> from toqito.matrices import standard_basis
>>> e_0, e_1 = standard_basis(2)
>>> state = tensor(e_0, e_1)
>>> rho = state @ state.conj().T
>>> np.around(fidelity_of_separability(rho, [2, 2]), decimals=2)
np.float64(1.0)
Expand Down
4 changes: 2 additions & 2 deletions toqito/state_metrics/helstrom_holevo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ def helstrom_holevo(rho: np.ndarray, sigma: np.ndarray) -> float:
Calculating the Helstrom-Holevo distance of states that are identical yield a value of
:math:`1/2`. This can be verified in :code:`toqito` as follows.

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.state_metrics import helstrom_holevo
>>> import numpy as np
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>> e_00 = np.kron(e_0, e_0)
>>> e_11 = np.kron(e_1, e_1)
>>>
Expand Down
8 changes: 4 additions & 4 deletions toqito/state_metrics/sub_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ def sub_fidelity(rho: np.ndarray, sigma: np.ndarray) -> float:
Calculating the fidelity between the states :math:`\rho` and :math:`\sigma` as :math:`F(\rho, \sigma) \approx
0.774`. This can be observed in :code:`toqito` as

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.state_metrics import fidelity
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>> rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
>>> sigma = 1/8 * e_0 @ e_0.conj().T + 7/8 * e_1 @ e_1.conj().T
>>> fidelity(rho, sigma)
Expand All @@ -46,9 +46,9 @@ def sub_fidelity(rho: np.ndarray, sigma: np.ndarray) -> float:
As the sub-fidelity is a lower bound on the fidelity, that is :math:`E(\rho, \sigma) \leq F(\rho, \sigma)`, we can
use :code:`toqito` to observe that :math:`E(\rho, \sigma) \approx 0.599\leq F(\rho, \sigma \approx 0.774`.

>>> from toqito.states import basis
>>> from toqito.matrices import standard_basis
>>> from toqito.state_metrics import sub_fidelity
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> e_0, e_1 = standard_basis(2)
>>> rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
>>> sigma = 1/8 * e_0 @ e_0.conj().T + 7/8 * e_1 @ e_1.conj().T
>>> sub_fidelity(rho, sigma)
Expand Down
8 changes: 4 additions & 4 deletions toqito/state_metrics/tests/test_bures_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np

from toqito.matrices import standard_basis
from toqito.state_metrics import bures_angle
from toqito.states import basis


def test_bures_angle_default():
Expand All @@ -17,7 +17,7 @@ def test_bures_angle_default():

def test_bures_angle_non_identical_states_1():
"""Test the bures_angle between two non-identical states."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 2 / 3 * e_0 @ e_0.conj().T + 1 / 3 * e_1 @ e_1.conj().T

Expand All @@ -27,7 +27,7 @@ def test_bures_angle_non_identical_states_1():

def test_bures_angle_non_identical_states_2():
"""Test the bures_angle between two non-identical states."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 1 / 8 * e_0 @ e_0.conj().T + 7 / 8 * e_1 @ e_1.conj().T

Expand All @@ -37,7 +37,7 @@ def test_bures_angle_non_identical_states_2():

def test_bures_angle_pure_states():
"""Test the bures_angle between two pure states."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
e_plus = (e_0 + e_1) / np.sqrt(2)
rho = e_plus @ e_plus.conj().T
sigma = e_0 @ e_0.conj().T
Expand Down
8 changes: 4 additions & 4 deletions toqito/state_metrics/tests/test_bures_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np

from toqito.matrices import standard_basis
from toqito.state_metrics import bures_distance
from toqito.states import basis


def test_bures_distance_default():
Expand All @@ -17,23 +17,23 @@ def test_bures_distance_default():

def test_bures_distance_non_identical_states_1():
"""Test the bures_distance between two non-identical states."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 2 / 3 * e_0 @ e_0.conj().T + 1 / 3 * e_1 @ e_1.conj().T
np.testing.assert_equal(np.isclose(bures_distance(rho, sigma), 0.0918, rtol=1e-03), True)


def test_bures_distance_non_identical_states_2():
"""Test the bures_distance between two non-identical states."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
rho = 3 / 4 * e_0 @ e_0.conj().T + 1 / 4 * e_1 @ e_1.conj().T
sigma = 1 / 8 * e_0 @ e_0.conj().T + 7 / 8 * e_1 @ e_1.conj().T
np.testing.assert_equal(np.isclose(bures_distance(rho, sigma), 0.6724, rtol=1e-03), True)


def test_bures_distance_pure_states():
"""Test the bures_distance between two pure states."""
e_0, e_1 = basis(2, 0), basis(2, 1)
e_0, e_1 = standard_basis(2)
e_plus = (e_0 + e_1) / np.sqrt(2)
rho = e_plus @ e_plus.conj().T
sigma = e_0 @ e_0.conj().T
Expand Down
Loading
Loading