Skip to content

Commit de255e2

Browse files
authored
Update NumPy APIs that will be removed in numpy-2.0 (quantumlib#6693)
Executed ruff check --select NPY201 --fix ./ Incorporate fix from exported cirq sources, cl/658064952. Ref: https://numpy.org/doc/stable/numpy_2_0_migration_guide.html
1 parent 6abbd16 commit de255e2

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

cirq/contrib/quantum_volume/quantum_volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def sample_heavy_set(
147147

148148
results = results.agg(lambda meas: cirq.value.big_endian_bits_to_int(meas), axis=1)
149149
# Compute the number of outputs that are in the heavy set.
150-
num_in_heavy_set = np.sum(np.in1d(results, heavy_set)).item()
150+
num_in_heavy_set = np.sum(np.isin(results, heavy_set)).item()
151151

152152
# Return the number of Heavy outputs over the number of valid runs.
153153
return num_in_heavy_set / len(results)

cirq/protocols/apply_unitary_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def apply_unitary(
390390
# Try each strategy, stopping if one works.
391391
# Also catch downcasting warnings and throw an error: #2041
392392
with warnings.catch_warnings():
393-
warnings.filterwarnings(action="error", category=np.ComplexWarning)
393+
warnings.filterwarnings(action="error", category=np.exceptions.ComplexWarning)
394394
for strat in strats:
395395
result = strat(unitary_value, args)
396396
if result is None:

cirq/protocols/apply_unitary_protocol_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ def test_cast_to_complex():
714714
)
715715

716716
with pytest.raises(
717-
np.ComplexWarning, match='Casting complex values to real discards the imaginary part'
717+
np.exceptions.ComplexWarning,
718+
match='Casting complex values to real discards the imaginary part',
718719
):
719720
cirq.apply_unitary(y0, args)
720721

0 commit comments

Comments
 (0)