Skip to content

Commit aa9e3b1

Browse files
vtomolerht
authored andcommitted
Modify some numpy types to be compatible with numpy>=1.20 (quantumlib#5668)
Part of quantumlib#3767
1 parent 5d7a30b commit aa9e3b1

File tree

8 files changed

+11
-11
lines changed

8 files changed

+11
-11
lines changed

cirq-core/cirq/experiments/qubit_characterizations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _measurement(two_qubit_circuit: circuits.Circuit) -> np.ndarray:
431431

432432
# Stores all 27 measured probabilities (P_00, P_01, P_10 after 9
433433
# different basis rotations).
434-
probs = np.array([])
434+
probs: np.ndarray = np.array([])
435435

436436
rots = [ops.X**0, ops.X**0.5, ops.Y**0.5]
437437

cirq-core/cirq/linalg/combinators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def kron(*factors: Union[np.ndarray, complex, float], shape_len: int = 2) -> np.
3939
Returns:
4040
The kronecker product of all the inputs.
4141
"""
42-
product = np.ones(shape=(1,) * shape_len)
42+
product: np.ndarray = np.ones(shape=(1,) * shape_len)
4343
for m in factors:
4444
product = np.kron(product, m)
4545
return np.array(product)

cirq-core/cirq/protocols/kraus_protocol.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# Sequence[np.ndarray] to ensure the method has the correct type signature in
3434
# that case. It is checked for using `is`, so it won't have a false positive
3535
# if the user provides a different (np.array([]),) value.
36-
RaiseTypeErrorIfNotProvided = (np.array([]),)
36+
RaiseTypeErrorIfNotProvided: Tuple[np.ndarray] = (np.array([]),)
3737

3838

3939
TDefault = TypeVar('TDefault')

cirq-core/cirq/protocols/kraus_protocol_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
"""Tests for kraus_protocol.py."""
1616

17-
from typing import Iterable, Sequence, Tuple
17+
from typing import Iterable, List, Sequence, Tuple
1818

1919
import numpy as np
2020
import pytest
2121

2222
import cirq
2323

2424

25-
LOCAL_DEFAULT = [np.array([])]
25+
LOCAL_DEFAULT: List[np.ndarray] = [np.array([])]
2626

2727

2828
def test_kraus_no_methods():

cirq-core/cirq/protocols/unitary_protocol_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import cirq
2020

21-
m0 = np.array([])
21+
m0: np.ndarray = np.array([])
2222
# yapf: disable
2323
# X on one qubit
2424
m1 = np.array([[0, 1],

cirq-core/cirq/qis/clifford_tableau.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
import abc
16-
from typing import Any, Dict, List, Sequence, TYPE_CHECKING
16+
from typing import Any, Dict, List, Optional, Sequence, TYPE_CHECKING
1717
import numpy as np
1818

1919
from cirq import protocols
@@ -441,7 +441,7 @@ def destabilizers(self) -> List['cirq.DensePauliString']:
441441
generators above generate the full Pauli group on n qubits."""
442442
return [self._row_to_dense_pauli(i) for i in range(self.n)]
443443

444-
def _measure(self, q, prng: np.random.RandomState) -> int:
444+
def _measure(self, q, prng: np.random.RandomState = np.random) -> int:
445445
"""Performs a projective measurement on the q'th qubit.
446446
447447
Returns: the result (0 or 1) of the measurement.
@@ -583,6 +583,6 @@ def apply_global_phase(self, coefficient: linear_dict.Scalar):
583583
pass
584584

585585
def measure(
586-
self, axes: Sequence[int], seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
586+
self, axes: Sequence[int], seed: Optional['cirq.RANDOM_STATE_OR_SEED_LIKE'] = None
587587
) -> List[int]:
588588
return [self._measure(axis, seed) for axis in axes]

cirq-core/cirq/testing/lin_alg_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def assert_allclose_up_to_global_phase(
164164
rtol: float = 1e-7,
165165
atol: float, # Require atol to be specified
166166
equal_nan: bool = True,
167-
err_msg: Optional[str] = '',
167+
err_msg: str = '',
168168
verbose: bool = True,
169169
) -> None:
170170
"""Checks if a ~= b * exp(i t) for some t.

cirq-core/cirq/vis/histogram.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def integrated_histogram(
9292

9393
if not show_zero:
9494
bin_values = np.linspace(0, 1, n + 1)
95-
parameter_values = sorted(np.concatenate(([0], float_data)))
95+
parameter_values = sorted(np.concatenate((np.array([0]), np.array(float_data))))
9696
else:
9797
bin_values = np.linspace(0, 1, n)
9898
parameter_values = sorted(float_data)

0 commit comments

Comments
 (0)