1515from __future__ import annotations
1616
1717from random import random
18- from typing import Callable
1918
2019import numpy as np
2120import pytest
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 )
7458def 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