Skip to content

Commit

Permalink
Modify some numpy types to be compatible with numpy>=1.20 (quantuml…
Browse files Browse the repository at this point in the history
  • Loading branch information
vtomole authored Jul 7, 2022
1 parent c4bac0e commit e794375
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cirq/experiments/qubit_characterizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def _measurement(two_qubit_circuit: circuits.Circuit) -> np.ndarray:

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

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

Expand Down
2 changes: 1 addition & 1 deletion cirq/linalg/combinators.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def kron(*factors: Union[np.ndarray, complex, float], shape_len: int = 2) -> np.
Returns:
The kronecker product of all the inputs.
"""
product = np.ones(shape=(1,) * shape_len)
product: np.ndarray = np.ones(shape=(1,) * shape_len)
for m in factors:
product = np.kron(product, m)
return np.array(product)
Expand Down
2 changes: 1 addition & 1 deletion cirq/protocols/kraus_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Sequence[np.ndarray] to ensure the method has the correct type signature in
# that case. It is checked for using `is`, so it won't have a false positive
# if the user provides a different (np.array([]),) value.
RaiseTypeErrorIfNotProvided = (np.array([]),)
RaiseTypeErrorIfNotProvided: Tuple[np.ndarray] = (np.array([]),)


TDefault = TypeVar('TDefault')
Expand Down
4 changes: 2 additions & 2 deletions cirq/protocols/kraus_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

"""Tests for kraus_protocol.py."""

from typing import Iterable, Sequence, Tuple
from typing import Iterable, List, Sequence, Tuple

import numpy as np
import pytest

import cirq


LOCAL_DEFAULT = [np.array([])]
LOCAL_DEFAULT: List[np.ndarray] = [np.array([])]


def test_kraus_no_methods():
Expand Down
2 changes: 1 addition & 1 deletion cirq/protocols/unitary_protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import cirq

m0 = np.array([])
m0: np.ndarray = np.array([])
# yapf: disable
# X on one qubit
m1 = np.array([[0, 1],
Expand Down
6 changes: 3 additions & 3 deletions cirq/qis/clifford_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import abc
from typing import Any, Dict, List, Sequence, TYPE_CHECKING
from typing import Any, Dict, List, Optional, Sequence, TYPE_CHECKING
import numpy as np

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

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

def measure(
self, axes: Sequence[int], seed: 'cirq.RANDOM_STATE_OR_SEED_LIKE' = None
self, axes: Sequence[int], seed: Optional['cirq.RANDOM_STATE_OR_SEED_LIKE'] = None
) -> List[int]:
return [self._measure(axis, seed) for axis in axes]
2 changes: 1 addition & 1 deletion cirq/testing/lin_alg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def assert_allclose_up_to_global_phase(
rtol: float = 1e-7,
atol: float, # Require atol to be specified
equal_nan: bool = True,
err_msg: Optional[str] = '',
err_msg: str = '',
verbose: bool = True,
) -> None:
"""Checks if a ~= b * exp(i t) for some t.
Expand Down
2 changes: 1 addition & 1 deletion cirq/vis/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def integrated_histogram(

if not show_zero:
bin_values = np.linspace(0, 1, n + 1)
parameter_values = sorted(np.concatenate(([0], float_data)))
parameter_values = sorted(np.concatenate((np.array([0]), np.array(float_data))))
else:
bin_values = np.linspace(0, 1, n)
parameter_values = sorted(float_data)
Expand Down

0 comments on commit e794375

Please sign in to comment.