Skip to content

Commit 2f083f6

Browse files
pavoljuhasrht
authored andcommitted
Fix more numpy / mypy typing issues (quantumlib#5669)
- Fix type complaints for np.allclose arguments - Fix complaint about float-to-int assignment - Fix type-complaint about optional return value
1 parent 7655251 commit 2f083f6

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

cirq-core/cirq/circuits/circuit.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2623,9 +2623,11 @@ def on_stuck(bad_op):
26232623
on_stuck_raise=on_stuck,
26242624
)
26252625

2626-
return protocols.apply_unitaries(
2626+
result = protocols.apply_unitaries(
26272627
unitary_ops, qubits, protocols.ApplyUnitaryArgs(state, buffer, range(len(qubits)))
26282628
)
2629+
assert result is not None, "apply_unitaries() should raise TypeError instead"
2630+
return result
26292631

26302632

26312633
def _decompose_measurement_inversions(op: 'cirq.Operation') -> 'cirq.OP_TREE':

cirq-core/cirq/ops/kraus_channel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __eq__(self, other) -> bool:
6666
return NotImplemented
6767
if self._key != other._key:
6868
return False
69-
return np.allclose(self._kraus_ops, other._kraus_ops)
69+
return np.allclose(np.asarray(self._kraus_ops), np.asarray(other._kraus_ops))
7070

7171
def num_qubits(self) -> int:
7272
return self._num_qubits

cirq-core/cirq/ops/mixed_unitary_channel.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def __eq__(self, other) -> bool:
6969
return False
7070
if not np.allclose([m[0] for m in self._mixture], [m[0] for m in other._mixture]):
7171
return False
72-
return np.allclose([m[1] for m in self._mixture], [m[1] for m in other._mixture])
72+
return np.allclose(
73+
np.asarray([m[1] for m in self._mixture]), np.asarray([m[1] for m in other._mixture])
74+
)
7375

7476
def num_qubits(self) -> int:
7577
return self._num_qubits

cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,11 @@ def _decomp_3sqrt_iswap_matrices(
606606
if ieq1:
607607
if ieq2:
608608
# Non-canonical Weyl coordinates for the single sqrt-iSWAP
609-
x1, y1, z1 = 0, np.pi / 8, -np.pi / 8
609+
x1, y1, z1 = 0.0, np.pi / 8, -np.pi / 8
610610
else:
611-
x1, y1, z1 = 0, np.pi / 8, np.pi / 8
611+
x1, y1, z1 = 0.0, np.pi / 8, np.pi / 8
612612
else:
613-
x1, y1, z1 = -np.pi / 8, np.pi / 8, 0
613+
x1, y1, z1 = -np.pi / 8, np.pi / 8, 0.0
614614
# Non-canonical Weyl coordinates for the two sqrt-iSWAP decomposition
615615
x2, y2, z2 = x - x1, y - y1, z - z1
616616

0 commit comments

Comments
 (0)