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/linalg/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def match_global_phase(a: np.ndarray, b: np.ndarray) -> tuple[np.ndarray, np.nda
return np.copy(a), np.copy(b)

# Find the entry with the largest magnitude in one of the matrices.
k = max(np.ndindex(*a.shape), key=lambda t: abs(b[t]))
k = max(np.ndindex(*a.shape), key=lambda t: abs(b[t].item()))

def dephase(v):
r = np.real(v)
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/clifford_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def from_unitary_with_global_phase(
return None
# Find the entry with the largest magnitude in the input unitary, to find
# the global phase difference between the input unitary and the gate unitary.
k = max(np.ndindex(*u.shape), key=lambda t: abs(u[t]))
k = max(np.ndindex(*u.shape), key=lambda t: abs(u[t].item()))
return gate, u[k] / protocols.unitary(gate)[k]

def pauli_tuple(self, pauli: Pauli) -> tuple[Pauli, bool]:
Expand Down
8 changes: 4 additions & 4 deletions cirq-core/cirq/sim/clifford/stabilizer_state_ch_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ def reindex(self, axes: Sequence[int]) -> cirq.StabilizerStateChForm:
copy = StabilizerStateChForm(self.n)
copy.G = self.G[axes][:, axes]
copy.F = self.F[axes][:, axes]
copy.M = self.M[axes][:, axes] # type: ignore[assignment]
copy.gamma = self.gamma[axes] # type: ignore[assignment]
copy.v = self.v[axes] # type: ignore[assignment]
copy.s = self.s[axes] # type: ignore[assignment]
copy.M = self.M[axes][:, axes]
copy.gamma = self.gamma[axes]
copy.v = self.v[axes]
copy.s = self.s[axes]
Comment on lines +291 to +294
Copy link
Contributor

@mhucka mhucka Sep 23, 2025

Choose a reason for hiding this comment

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

These fail for me locally with Python 3.11, Numpy 2.2.6, and mypy 1.17.1.

# ./check/mypy
cirq-core/cirq/sim/clifford/stabilizer_state_ch_form.py:291: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[Any]]", variable has type "ndarray[tuple[int, int], dtype[Any]]")  [assignment]
cirq-core/cirq/sim/clifford/stabilizer_state_ch_form.py:292: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[Any]]", variable has type "ndarray[tuple[int], dtype[Any]]")  [assignment]
cirq-core/cirq/sim/clifford/stabilizer_state_ch_form.py:293: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[Any]]", variable has type "ndarray[tuple[int], dtype[Any]]")  [assignment]
cirq-core/cirq/sim/clifford/stabilizer_state_ch_form.py:294: error: Incompatible types in assignment (expression has type "ndarray[tuple[int, ...], dtype[Any]]", variable has type "ndarray[tuple[int], dtype[Any]]")  [assignment]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ack. Please update to numpy>=2.3 in your development environment. These lines were decorated with # type: ignore comments which became unnecessary after typing enhancements in numpy-2.3. Testing with numpy-2.2 exposes the ignored errors.

For type checking we can require the latest numpy version (as installed in the CI job) so that type checks have the most up-to-date numpy annotations.

copy.omega = self.omega
return copy

Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/sim/state_vector_simulation_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create(
*,
initial_state: np.ndarray | cirq.STATE_VECTOR_LIKE = 0,
qid_shape: tuple[int, ...] | None = None,
dtype: type[np.complexfloating] | None = None,
dtype: type[np.complexfloating] | np.dtype[np.complexfloating] | None = None,
buffer: np.ndarray | None = None,
):
"""Initializes the object with the inputs.
Expand Down Expand Up @@ -324,7 +324,7 @@ def __init__(
prng: np.random.RandomState | None = None,
qubits: Sequence[cirq.Qid] | None = None,
initial_state: np.ndarray | cirq.STATE_VECTOR_LIKE = 0,
dtype: type[np.complexfloating] = np.complex64,
dtype: type[np.complexfloating] | np.dtype[np.complexfloating] = np.complex64,
classical_data: cirq.ClassicalDataStore | None = None,
):
"""Inits StateVectorSimulationState.
Expand Down
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 @@ -28,7 +28,7 @@

def random_superposition(
dim: int, *, random_state: cirq.RANDOM_STATE_OR_SEED_LIKE = None
) -> np.ndarray:
) -> np.ndarray[tuple[int], np.dtype[np.complex128]]:
"""Returns a random unit-length vector from the uniform distribution.

Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def compile_two_qubit_gate(self, unitary: np.ndarray) -> TwoQubitGateTabulationR
success = infidelities[nearest_ind] < self.max_expected_infidelity

# shape (n,2,2,2)
inner_gates = np.array(self.single_qubit_gates[nearest_ind])
inner_gates: np.ndarray = np.array(self.single_qubit_gates[nearest_ind])

if inner_gates.size == 0: # Only need base gate
kR, kL, actual = _outer_locals_for_unitary(unitary, self.base_gate)
Expand Down
3 changes: 0 additions & 3 deletions dev_tools/requirements/mypy.env.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

-r deps/cirq-all.txt
-r deps/mypy.txt

# TODO: #7657 - remove after fixing type annotations for NumPy-2.3
numpy<2.3