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

Update numpy requirement from 1.26.4 to 2.0.0 #656

Closed
wants to merge 14 commits into from
Closed
6 changes: 4 additions & 2 deletions .github/workflows/build-test-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ jobs:
- name: Install toqito + dependencies
run: |
python -m pip install --upgrade pip
pip wheel --no-cache-dir --use-pep517 "cvxopt (==1.3.2)"
pip install poetry
poetry install --without docs --no-interaction
poetry install --without docs,cvxdep --no-interaction


toqito-pytest:
Expand Down Expand Up @@ -69,8 +70,9 @@ jobs:
- name: Install toqito + dependencies
run: |
python -m pip install --upgrade pip
pip wheel --no-cache-dir --use-pep517 "cvxopt (==1.3.2)"
pip install poetry
poetry install --with dev --without docs,lint --no-interaction
poetry install --with dev --without docs,lint,cvxdep --no-interaction
- name: Run tests
run: poetry run pytest -v --cov-config=.coveragerc --cov-report=xml --cov-report term-missing:skip-covered --cov=toqito
- name: Upload coverage information
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install toqito + dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade pip setuptools wheel
pip install poetry
poetry install --with docs --without dev,lint --no-interaction
python -m pip install --upgrade --no-cache-dir setuptools sphinx readthedocs-sphinx-ext
Expand All @@ -56,7 +56,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install toqito + dependencies
run: |
python -m pip install --upgrade --no-cache-dir pip
python -m pip install --upgrade --no-cache-dir pip setuptools wheel
pip install poetry
poetry install --with docs,dev --without lint --no-interaction
- name: Check docstring examples
Expand Down
2 changes: 1 addition & 1 deletion docs/intro_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fidelity function between quantum states that happen to be identical.
>>>
>>> # Calculate the fidelity between `rho` and `sigma`
>>> np.around(fidelity(rho, sigma), decimals=2)
1.0
np.float64(1.0)

There are a number of other metrics one can compute on two density matrices
including the trace norm, trace distance. These and others are also available
Expand Down
20 changes: 10 additions & 10 deletions docs/tutorials.extended_nonlocal_games.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ This can be verified in :code:`toqito` as follows.
>>>
>>> # The unentangled value is cos(pi/8)**2 \approx 0.85356
>>> np.around(bb84.unentangled_value(), decimals=2)
0.85
np.float64(0.85)

The BB84 game also exhibits strong parallel repetition. We can specify how many
parallel repetitions for :code:`toqito` to run. The example below provides an
Expand All @@ -340,7 +340,7 @@ example of two parallel repetitions for the BB84 game.
>>>
>>> # The unentangled value for two parallel repetitions is cos(pi/8)**4 \approx 0.72855
>>> np.around(bb84_2_reps.unentangled_value(), decimals=2)
0.73
np.float64(0.73)

It was shown in :cite:`Johnston_2016_Extended` that the BB84 game possesses the property of strong
parallel repetition. That is,
Expand All @@ -367,7 +367,7 @@ using :code:`toqito` as well.
>>>
>>> # The standard quantum value is cos(pi/8)**2 \approx 0.85356
>>> np.around(bb84_lb.quantum_value_lower_bound(), decimals=2)
0.85
np.float64(0.85)

From :cite:`Johnston_2016_Extended`, it is known that :math:`\omega(G_{BB84}) =
\omega^*(G_{BB84})`, however, if we did not know this beforehand, we could
Expand Down Expand Up @@ -395,7 +395,7 @@ Using :code:`toqito`, we can see that :math:`\omega_{ns}(G) = \cos^2(\pi/8)`.
>>>
>>> # The non-signaling value is cos(pi/8)**2 \approx 0.85356
>>> np.around(bb84.nonsignaling_value(), decimals=2)
0.85
np.float64(0.85)

So we have the relationship that

Expand All @@ -417,7 +417,7 @@ can observe this by the following snippet.
>>>
>>> # The non-signaling value for two parallel repetitions is cos(pi/8)**4 \approx 0.73825
>>> np.around(bb84_2_reps.nonsignaling_value(), decimals=2)
0.74
np.float64(0.74)

Note that :math:`0.73825 \geq \cos(\pi/8)^4 \approx 0.72855` and therefore we
have that
Expand Down Expand Up @@ -528,7 +528,7 @@ the unentangled value of :math:`G_{CHSH}`.
>>>
>>> # The unentangled value is 3/4 = 0.75
>>> np.around(chsh.unentangled_value(), decimals=2)
0.75
np.float64(0.75)

We can also run multiple repetitions of :math:`G_{CHSH}`.

Expand All @@ -543,7 +543,7 @@ We can also run multiple repetitions of :math:`G_{CHSH}`.
>>>
>>> # The unentangled value for two parallel repetitions is (3/4)**2 \approx 0.5625
>>> np.around(chsh_2_reps.unentangled_value(), decimals=2)
0.56
np.float64(0.56)

Note that strong parallel repetition holds as

Expand All @@ -567,7 +567,7 @@ non-signaling value.
>>>
>>> # The non-signaling value is 3/4 = 0.75
>>> np.around(chsh.nonsignaling_value(), decimals=2)
0.75
np.float64(0.75)

As we know that :math:`\omega(G_{CHSH}) = \omega_{ns}(G_{CHSH}) = 3/4` and that

Expand Down Expand Up @@ -690,7 +690,7 @@ Now that we have encoded :math:`G_{MUB}`, we can calculate the unentangled value
>>> g_mub = ExtendedNonlocalGame(prob_mat, pred_mat)
>>> unent_val = g_mub.unentangled_value()
>>> np.around(unent_val, decimals=2)
0.65
np.float64(0.65)

That is, we have that

Expand All @@ -707,7 +707,7 @@ obtain.
>>> g_mub = ExtendedNonlocalGame(prob_mat, pred_mat)
>>> q_val = g_mub.quantum_value_lower_bound()
>>> np.around(q_val, decimals=2)
0.66
np.float64(0.66)

Note that as we are calculating a lower bound, it is possible that a value this
high will not be obtained, or in other words, the algorithm can get stuck in a
Expand Down
6 changes: 3 additions & 3 deletions docs/tutorials.nonlocal_games.rst
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ use :code:`toqito` to determine the lower bound on the quantum value.
>>> from toqito.nonlocal_games.nonlocal_game import NonlocalGame
>>> chsh = NonlocalGame(prob_mat, pred_mat)
>>> np.around(chsh.quantum_value_lower_bound(), decimals=2)
0.85
np.float64(0.85)

In this case, we can see that the quantum value of the CHSH game is in fact
attained as :math:`\cos^2(\pi/8) \approx 0.85355`.
Expand Down Expand Up @@ -414,9 +414,9 @@ value and calculate lower bounds on the quantum value of the FFL game.
>>> # Define the FFL game object.
>>> ffl = NonlocalGame(prob_mat, pred_mat)
>>> np.around(ffl.classical_value(), decimals=2)
0.67
np.float64(0.67)
>>> np.around(ffl.quantum_value_lower_bound(), decimals=2)
0.22
np.float64(0.22)

In this case, we obtained the correct quantum value of :math:`2/3`, however,
the lower bound technique is not guaranteed to converge to the true quantum
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 @@ -134,7 +134,7 @@ Using :code:`toqito`, we can calculate this probability directly as follows:
>>> # Calculate the probability with which Bob can
>>> # distinguish the state he is provided.
>>> np.around(state_distinguishability(states, probs)[0], decimals=2)
1.0
np.float64(1.0)

Specifying similar state distinguishability problems can be done so using this
general pattern.
Expand Down Expand Up @@ -230,7 +230,7 @@ via PPT measurements in the following manner.
>>> states = [rho_1, rho_2, rho_3, rho_4]
>>> probs = [1 / 4, 1 / 4, 1 / 4, 1 / 4]
>>> np.around(ppt_distinguishability(vectors=states, probs=probs, dimensions=[2, 2, 2, 2], subsystems=[0, 2])[0], decimals=2)
0.87
np.float64(0.87)

Probability of distinguishing a state via separable measurements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 6 additions & 6 deletions docs/tutorials.xor_quantum_value.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ value of the CHSH game.
>>> from toqito.nonlocal_games.xor_game import XORGame
>>> chsh = XORGame(prob_mat, pred_mat)
>>> chsh.classical_value()
0.75
np.float64(0.75)

A quantum strategy for the CHSH game
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -290,7 +290,7 @@ follows:

>>> import numpy as np
>>> np.around(chsh.quantum_value(), decimals=2)
0.85
np.float64(0.85)

For reference, the complete code to calculate both the classical and quantum
values of the CHSH game is provided below.
Expand All @@ -305,9 +305,9 @@ values of the CHSH game is provided below.
... [0, 1]])
>>> chsh = XORGame(prob_mat, pred_mat)
>>> chsh.classical_value()
0.75
np.float64(0.75)
>>> np.around(chsh.quantum_value(), decimals=2)
0.85
np.float64(0.85)

The odd cycle game
------------------
Expand Down Expand Up @@ -350,9 +350,9 @@ the classical and quantum values of this game.
>>> # Compute the classical and quantum values.
>>> odd_cycle = XORGame(prob_mat, pred_mat)
>>> np.around(odd_cycle.classical_value(), decimals=2)
0.9
np.float64(0.9)
>>> np.around(odd_cycle.quantum_value(), decimals=2)
0.98
np.float64(0.98)

Note that the odd cycle game is another example of an XOR game where the
players are able to win with a strictly higher probability if they adopt a
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ scs = "3.2.6"
picos = "2.4.17"
qiskit = "1.2.0"

[tool.poetry.group.cvxdep.dependencies]
cvxopt = "1.3.2"

[tool.poetry.group.dev.dependencies]
pytest = "8.3.2"
pytest-cov = "5.0.0"
Expand Down
4 changes: 2 additions & 2 deletions toqito/channel_metrics/channel_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def channel_fidelity(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
>>> choi_1 = dephasing(4)
>>> choi_2 = dephasing(4)
>>> np.around(channel_fidelity(choi_1, choi_2), decimals=2)
1.0
np.float64(1.0)

We can also compute the channel fidelity between two different channels. For example, we can
compute the channel fidelity between the dephasing and depolarizing channels.
Expand All @@ -60,7 +60,7 @@ def channel_fidelity(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
>>> choi_1 = dephasing(4)
>>> choi_2 = depolarizing(4)
>>> np.around(channel_fidelity(choi_1, choi_2), decimals=2)
0.5
np.float64(0.5)

References
==========
Expand Down
4 changes: 2 additions & 2 deletions toqito/channel_metrics/diamond_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def diamond_norm(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
>>> choi_depolarizing = depolarizing(dim=2, param_p=0.2)
>>> choi_identity = np.identity(2**2)
>>> np.around(diamond_norm(choi_depolarizing, choi_identity), decimals=2)
-0.0
np.float64(-0.0)

Similarly, we can compute the diamond norm between the dephasing channel (with parameter 0.3) and the identity
channel:
Expand All @@ -38,7 +38,7 @@ def diamond_norm(choi_1: np.ndarray, choi_2: np.ndarray) -> float:
>>> choi_dephasing = dephasing(dim=2)
>>> choi_identity = np.identity(2**2)
>>> np.around(diamond_norm(choi_dephasing, choi_identity), decimals=2)
-0.0
np.float64(-0.0)

References
==========
Expand Down
2 changes: 1 addition & 1 deletion toqito/channel_metrics/fidelity_of_separability.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def fidelity_of_separability(
>>> state = tensor(basis(2, 0), basis(2, 0))
>>> rho = state @ state.conj().T
>>> np.around(fidelity_of_separability(rho, [2, 2]), decimals=2)
1.0
np.float64(1.0)

References
==========
Expand Down
4 changes: 2 additions & 2 deletions toqito/channel_props/choi_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def choi_rank(phi: np.ndarray | list[list[np.ndarray]]) -> int:

>>> from toqito.channel_props import choi_rank
>>> choi_rank(kraus_ops)
4
np.int64(4)

We can the verify the associated Choi representation (the SWAP gate)
gets the same Choi rank:

>>> choi_matrix = np.array([[1,0,0,0],[0,0,1,0],[0,1,0,0],[0,0,0,1]])
>>> choi_rank(choi_matrix)
4
np.int64(4)

References
==========
Expand Down
2 changes: 1 addition & 1 deletion toqito/matrix_ops/inner_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def inner_product(v1: np.ndarray, v2: np.ndarray) -> float:
>>> from toqito.matrix_ops import inner_product
>>> v1, v2 = np.array([1,2,3]), np.array([4,5,6])
>>> inner_product(v1,v2)
32
np.int64(32)

References
==========
Expand Down
2 changes: 1 addition & 1 deletion toqito/matrix_props/is_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def is_density(mat: np.ndarray) -> bool:
>>> import numpy as np
>>> rho = bell(0) * bell(0).conj().T
>>> is_density(rho)
True
np.True_

Alternatively, the following example matrix :math:`\sigma` defined as

Expand Down
4 changes: 2 additions & 2 deletions toqito/matrix_props/is_diagonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def is_diagonal(mat: np.ndarray) -> bool:
>>> import numpy as np
>>> A = np.array([[1, 0], [0, 1]])
>>> is_diagonal(A)
True
np.True_

Alternatively, the following example matrix

Expand All @@ -57,7 +57,7 @@ def is_diagonal(mat: np.ndarray) -> bool:
>>> import numpy as np
>>> B = np.array([[1, 2], [3, 4]])
>>> is_diagonal(B)
False
np.False_

References
==========
Expand Down
4 changes: 2 additions & 2 deletions toqito/matrix_props/is_diagonally_dominant.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def is_diagonally_dominant(mat: np.ndarray, is_strict: bool = True) -> bool:
>>> import numpy as np
>>> A = np.array([[2, -1, 0], [0, 2, -1], [0, -1, 2]])
>>> is_diagonally_dominant(A)
True
np.True_

Alternatively, the following example matrix :math:`B` defined as

Expand All @@ -46,7 +46,7 @@ def is_diagonally_dominant(mat: np.ndarray, is_strict: bool = True) -> bool:
>>> import numpy as np
>>> B = np.array([[-1, 2], [-1, -1]])
>>> is_diagonally_dominant(B)
False
np.False_

References
==========
Expand Down
2 changes: 1 addition & 1 deletion toqito/matrix_props/is_linearly_independent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def is_linearly_independent(vectors: list[np.ndarray]) -> bool:
>>> v_2 = np.array([[1], [1], [0]])
>>> v_3 = np.array([[0], [0], [1]])
>>> is_linearly_independent([v_1, v_2, v_3])
True
np.True_

References
==========
Expand Down
6 changes: 3 additions & 3 deletions toqito/matrix_props/is_nonnegative.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def is_nonnegative(input_mat: np.ndarray, mat_type: str = "nonnegative") -> bool
>>> import numpy as np
>>> from toqito.matrix_props import is_nonnegative
>>> is_nonnegative(np.identity(3))
True
np.True_
>>> is_nonnegative(np.identity(3), "doubly")
True
np.True_
>>> is_nonnegative(np.identity(3), "nonnegative")
True
np.True_

References
==========
Expand Down
Loading
Loading