Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq-core/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-core/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-core/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-core/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-core/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-core/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]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would keep this None and then do a seed or np.random in the parameter in self._measure. That way we don't have to change the default here (though I don't think it will matter much). np.random might be considered mutable(?) since it changes when different people use it, so best to not put mutables as defaults.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want it as a parameter or like:

    def _measure(self, q, prng: Optional[np.random.RandomState]) -> int:
        if prng is None:
            prng = np.random

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that could also work, though this also does something I try to avoid which is re-assign a parameter. Mostly this doesn't ever hurt you, but there are cases where it does (mostly having to do with pytest, btw). It also sort of makes sense that the private method has a random state, but the public one has the default of None.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whichever way you want 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. Switched to param.

return [self._measure(axis, seed) for axis in axes]
2 changes: 1 addition & 1 deletion cirq-core/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-core/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