Skip to content

Commit b8ff93e

Browse files
mhuckapavoljuhas
andauthored
Wrap calls to deprecated functions in qubit_characterizations_test.py (#8031)
Running `check/pytest` in Python 3.11 on a Debian Linux system produced a few warnings similar to this: ``` cirq-core/cirq/experiments/qubit_characterizations_test.py::test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking /usr/local/google/home/mhucka/projects/github/cirq-pr-warnings/cirq-core/cirq/experiments/qubit_characterizations_test.py:130: DeprecationWarning: parallel_single_qubit_randomized_benchmarking was used but is deprecated. It will be removed in cirq v2.0. please use parallel_single_qubit_rb instead results = parallel_single_qubit_randomized_benchmarking( ``` These are not critical, but it is a little bit surprising to see them in Cirq's own unit tests. This wraps the relevant calls in `qubit_characterizations_test.py` with the `cirq.testing.assert_deprecated(…)` context manager to indicate that the deprecation messages are known and expected, and keep them from bubbling up to developers. --------- Co-authored-by: Pavol Juhas <juhas@google.com>
1 parent 603755a commit b8ff93e

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

cirq-core/cirq/experiments/qubit_characterizations_test.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
from __future__ import annotations
1616

17-
import os
18-
from unittest import mock
19-
2017
import matplotlib.pyplot as plt
2118
import numpy as np
2219
import pytest
@@ -107,29 +104,31 @@ def check_distinct(unitaries):
107104
assert num_x <= 1
108105

109106

110-
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
111107
def test_single_qubit_randomized_benchmarking() -> None:
112108
# Check that the ground state population at the end of the Clifford
113109
# sequences is always unity.
114110
simulator = sim.Simulator()
115111
qubit = GridQubit(0, 0)
116112
num_cfds = tuple(np.logspace(np.log10(5), 3, 5, dtype=int))
117-
results = single_qubit_randomized_benchmarking(simulator, qubit, num_clifford_range=num_cfds)
113+
with cirq.testing.assert_deprecated('use single_qubit_rb instead', deadline='v2.0'):
114+
results = single_qubit_randomized_benchmarking(
115+
simulator, qubit, num_clifford_range=num_cfds
116+
)
118117
g_pops = np.asarray(results.data)[:, 1]
119118
assert np.isclose(np.mean(g_pops), 1.0)
120119
assert np.isclose(results.pauli_error(), 0.0, atol=1e-7) # warning is expected
121120

122121

123-
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
124122
def test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking() -> None:
125123
# Check that the ground state population at the end of the Clifford
126124
# sequences is always unity.
127125
simulator = sim.Simulator()
128126
qubits = (GridQubit(0, 0), GridQubit(0, 1))
129127
num_cfds = range(5, 20, 5)
130-
results = parallel_single_qubit_randomized_benchmarking(
131-
simulator, num_clifford_range=num_cfds, repetitions=100, qubits=qubits
132-
)
128+
with cirq.testing.assert_deprecated('use parallel_single_qubit_rb instead', deadline='v2.0'):
129+
results = parallel_single_qubit_randomized_benchmarking(
130+
simulator, num_clifford_range=num_cfds, repetitions=100, qubits=qubits
131+
)
133132
for qubit in qubits:
134133
g_pops = np.asarray(results.results_dictionary[qubit].data)[:, 1]
135134
assert np.isclose(np.mean(g_pops), 1.0)
@@ -140,14 +139,14 @@ def test_parallel_single_qubit_parallel_single_qubit_randomized_benchmarking() -
140139
_ = results.plot_integrated_histogram()
141140

142141

143-
@mock.patch.dict(os.environ, clear='CIRQ_TESTING')
144142
def test_parallel_single_qubit_randomized_benchmarking_with_noise() -> None:
145143
simulator = sim.Simulator(noise=cirq.depolarize(1e-3), seed=0)
146144
qubits = (GridQubit(0, 0), GridQubit(0, 1))
147145
num_cfds = range(5, 7, 1)
148-
results = parallel_single_qubit_randomized_benchmarking(
149-
simulator, num_clifford_range=num_cfds, repetitions=10, qubits=qubits
150-
)
146+
with cirq.testing.assert_deprecated('use parallel_single_qubit_rb instead', deadline='v2.0'):
147+
results = parallel_single_qubit_randomized_benchmarking(
148+
simulator, num_clifford_range=num_cfds, repetitions=10, qubits=qubits
149+
)
151150
for qubit in qubits:
152151
g_pops = np.asarray(results.results_dictionary[qubit].data)[:, 1]
153152
assert np.isclose(np.mean(g_pops), 0.99, atol=1e-2)

0 commit comments

Comments
 (0)