Skip to content

Commit 4b118d0

Browse files
authored
Remove dead code for scipy<=1.5 (#7410)
We require scipy>=1.11 so any special code for earlier scipy is dead.
1 parent d1d25f8 commit 4b118d0

File tree

2 files changed

+2
-39
lines changed

2 files changed

+2
-39
lines changed

cirq-core/cirq/transformers/analytical_decompositions/three_qubit_decomposition.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Sequence
2020

2121
import numpy as np
22+
import scipy.linalg
2223

2324
import cirq
2425
from cirq import ops, transformers as opt
@@ -47,24 +48,13 @@ def three_qubit_matrix_to_operations(
4748
4849
Raises:
4950
ValueError: If the u matrix is non-unitary or not of shape (8,8).
50-
ImportError: If the decomposition cannot be done because the SciPy version is less than
51-
1.5.0 and so does not contain the required `cossin` method.
5251
"""
5352
if np.shape(u) != (8, 8):
5453
raise ValueError(f"Expected unitary matrix with shape (8,8) got {np.shape(u)}")
5554
if not cirq.is_unitary(u, atol=atol):
5655
raise ValueError(f"Matrix is not unitary: {u}")
5756

58-
try:
59-
from scipy.linalg import cossin
60-
except ImportError: # pragma: no cover
61-
raise ImportError(
62-
"cirq.three_qubit_unitary_to_operations requires "
63-
"SciPy 1.5.0+, as it uses the cossin function. Please"
64-
" upgrade scipy in your environment to use this "
65-
"function!"
66-
)
67-
(u1, u2), theta, (v1h, v2h) = cossin(u, 4, 4, separate=True)
57+
(u1, u2), theta, (v1h, v2h) = scipy.linalg.cossin(u, 4, 4, separate=True)
6858

6959
cs_ops = _cs_to_ops(q0, q1, q2, theta)
7060
if len(cs_ops) > 0 and cs_ops[-1] == cirq.CZ(q2, q0):

cirq-core/cirq/transformers/analytical_decompositions/three_qubit_decomposition_test.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from __future__ import annotations
1616

1717
from random import random
18-
from typing import Callable
1918

2019
import numpy as np
2120
import pytest
@@ -31,20 +30,6 @@
3130
)
3231

3332

34-
def _skip_if_scipy(*, version_is_greater_than_1_5_0: bool) -> Callable[[Callable], Callable]:
35-
def decorator(func): # pragma: no cover
36-
try:
37-
# pylint: disable=unused-import
38-
from scipy.linalg import cossin
39-
40-
return None if version_is_greater_than_1_5_0 else func
41-
except ImportError:
42-
return func if version_is_greater_than_1_5_0 else None
43-
44-
return decorator
45-
46-
47-
@_skip_if_scipy(version_is_greater_than_1_5_0=False)
4833
@pytest.mark.parametrize(
4934
"u",
5035
[
@@ -70,7 +55,6 @@ def test_three_qubit_matrix_to_operations(u) -> None:
7055
assert num_two_qubit_gates <= 20, f"expected at most 20 CZ/CNOTs got {num_two_qubit_gates}"
7156

7257

73-
@_skip_if_scipy(version_is_greater_than_1_5_0=False)
7458
def test_three_qubit_matrix_to_operations_errors() -> None:
7559
a, b, c = cirq.LineQubit.range(3)
7660
with pytest.raises(ValueError, match="(8,8)"):
@@ -79,17 +63,6 @@ def test_three_qubit_matrix_to_operations_errors() -> None:
7963
cirq.three_qubit_matrix_to_operations(a, b, c, cirq.unitary(cirq.CCX) * 2)
8064

8165

82-
# on environments with scipy <1.5.0 this will not be sufficient to cover the
83-
# full three_qubit_matrix_to_operations method. In case we ever introduce a CI
84-
# environment like that, we'll need to ignore the coverage somehow conditionally on
85-
# the scipy version.
86-
@_skip_if_scipy(version_is_greater_than_1_5_0=True)
87-
def test_three_qubit_matrix_to_operations_scipy_error() -> None: # pragma: no cover
88-
a, b, c = cirq.LineQubit.range(3)
89-
with pytest.raises(ImportError, match="three_qubit.*1.5.0+"):
90-
cirq.three_qubit_matrix_to_operations(a, b, c, np.eye(8))
91-
92-
9366
@pytest.mark.parametrize(
9467
["theta", "num_czs"],
9568
[

0 commit comments

Comments
 (0)