Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace functions deprecated in NumPy 1.25 #6133

Merged
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
6 changes: 3 additions & 3 deletions cirq-core/cirq/ops/matrix_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def test_single_qubit_init():
m = np.array([[1, 1j], [1j, 1]]) * np.sqrt(0.5)
x2 = cirq.MatrixGate(m)
assert cirq.has_unitary(x2)
assert np.alltrue(cirq.unitary(x2) == m)
assert np.all(cirq.unitary(x2) == m)
assert cirq.qid_shape(x2) == (2,)

x2 = cirq.MatrixGate(PLUS_ONE, qid_shape=(3,))
assert cirq.has_unitary(x2)
assert np.alltrue(cirq.unitary(x2) == PLUS_ONE)
assert np.all(cirq.unitary(x2) == PLUS_ONE)
assert cirq.qid_shape(x2) == (3,)

with pytest.raises(ValueError, match='Not a .*unitary matrix'):
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_single_qubit_extrapolate():
def test_two_qubit_init():
x2 = cirq.MatrixGate(QFT2)
assert cirq.has_unitary(x2)
assert np.alltrue(cirq.unitary(x2) == QFT2)
assert np.all(cirq.unitary(x2) == QFT2)


def test_two_qubit_eq():
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/testing/circuit_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def assert_has_consistent_apply_unitary(val: Any, *, atol: float = 1e-8) -> None
# If you applied a unitary, it should match the one you say you have.
if actual is not None:
assert expected is not None
n = np.product([2, *qid_shape])
n = np.prod([2, *qid_shape])
np.testing.assert_allclose(actual.reshape(n, n), expected, atol=atol)


Expand Down Expand Up @@ -373,7 +373,7 @@ def assert_has_consistent_apply_channel(val: Any, *, atol: float = 1e-8) -> None
# If you applied a channel, it should match the superoperator you say you have.
if actual is not None:
assert expected is not None
n = np.product(qid_shape) ** 2
n = np.prod(qid_shape) ** 2
np.testing.assert_allclose(actual.reshape((n, n)), expected, atol=atol)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def kak_vector_infidelity(

if ignore_equivalent_vectors:
k_diff = k_vec_a - k_vec_b
out = 1 - np.product(np.cos(k_diff), axis=-1) ** 2
out -= np.product(np.sin(k_diff), axis=-1) ** 2
out = 1 - np.prod(np.cos(k_diff), axis=-1) ** 2
out -= np.prod(np.sin(k_diff), axis=-1) ** 2
return out

# We must take the minimum infidelity over all possible locally equivalent
Expand All @@ -181,8 +181,8 @@ def kak_vector_infidelity(

k_diff = k_vec_a - k_vec_b

out = 1 - np.product(np.cos(k_diff), axis=-1) ** 2
out -= np.product(np.sin(k_diff), axis=-1) ** 2 # (...,192)
out = 1 - np.prod(np.cos(k_diff), axis=-1) ** 2
out -= np.prod(np.sin(k_diff), axis=-1) ** 2 # (...,192)

return out.min(axis=-1)

Expand Down