Skip to content

Commit

Permalink
Address NumPy and NotImplemented deprecation warnings (#6465)
Browse files Browse the repository at this point in the history
* Replace deprecated numpy aliases for dtype-s
  `np.int0` --> `np.intp` and `np.uint0` --> `np.uintp`

* Address deprecation warning about NotImplemented used as boolean
  • Loading branch information
pavoljuhas authored Feb 16, 2024
1 parent a8bd9a5 commit a4ec796
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def test_approx_eq_mixed_primitives():

def test_numpy_dtype_compatibility():
i_a, i_b, i_c = 0, 1, 2
i_types = [np.intc, np.intp, np.int0, np.int8, np.int16, np.int32, np.int64]
i_types = [np.intc, np.intp, np.int8, np.int16, np.int32, np.int64]
for i_type in i_types:
assert cirq.approx_eq(i_type(i_a), i_type(i_b), atol=1)
assert not cirq.approx_eq(i_type(i_a), i_type(i_c), atol=1)
u_types = [np.uint, np.uint0, np.uint8, np.uint16, np.uint32, np.uint64]
u_types = [np.uint, np.uintp, np.uint8, np.uint16, np.uint32, np.uint64]
for u_type in u_types:
assert cirq.approx_eq(u_type(i_a), u_type(i_b), atol=1)
assert not cirq.approx_eq(u_type(i_a), u_type(i_c), atol=1)
Expand Down
6 changes: 4 additions & 2 deletions cirq-core/cirq/protocols/resolve_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,10 @@ def resolve_parameters(
if isinstance(val, (list, tuple)):
return cast(T, type(val)(resolve_parameters(e, param_resolver, recursive) for e in val))

is_parameterized = getattr(val, '_is_parameterized_', None)
if is_parameterized is not None and not is_parameterized():
is_parameterized = (
val._is_parameterized_() if hasattr(val, '_is_parameterized_') else NotImplemented
)
if is_parameterized is not NotImplemented and not is_parameterized:
return val

getter = getattr(val, '_resolve_parameters_', None)
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/sim/simulation_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def _act_on_fallback_(
return True

def add_qubits(self, qubits):
ret = super().add_qubits(qubits)
return self if NotImplemented else ret
super().add_qubits(qubits)
return self


class DelegatingAncillaZ(cirq.Gate):
Expand Down

0 comments on commit a4ec796

Please sign in to comment.