Skip to content

Commit 603755a

Browse files
mhuckapavoljuhas
andauthored
In histogram.py, only apply log scale if data has positive values (#8032)
Running pytest in Python 3.11 on a Debian Linux system produces these warnings ```python cirq-core/cirq/experiments/single_qubit_readout_calibration_test.py::test_estimate_parallel_readout_errors_no_noise /usr/local/google/home/mhucka/projects/github/cirq-pr-warnings/cirq-core/cirq/vis/histogram.py:123: UserWarning: Data has no positive values, and therefore cannot be log-scaled. set_semilog() cirq-core/cirq/experiments/single_qubit_readout_calibration_test.py::test_estimate_parallel_readout_errors_no_noise /usr/local/google/home/mhucka/projects/github/cirq-pr-warnings/cirq-core/cirq/vis/histogram.py:124: UserWarning: Data has no positive values, and therefore cannot be log-scaled. set_lim(0, 1) ``` This PR modifies `integrated_histogram()` to only apply log scaling if the data contains positive values, avoiding the warning from Matplotlib. --------- Co-authored-by: Pavol Juhas <juhas@google.com>
1 parent a46677e commit 603755a

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

cirq-core/cirq/experiments/single_qubit_readout_calibration_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_estimate_single_qubit_readout_errors_with_noise() -> None:
9090

9191

9292
def test_estimate_parallel_readout_errors_no_noise() -> None:
93-
qubits = [cirq.GridQubit(i, 0) for i in range(10)]
93+
qubits = cirq.GridQubit.rect(10, 1)
9494
sampler = cirq.Simulator()
9595
repetitions = 1000
9696
result = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -100,8 +100,6 @@ def test_estimate_parallel_readout_errors_no_noise() -> None:
100100
assert result.one_state_errors == dict.fromkeys(qubits, 0)
101101
assert result.repetitions == repetitions
102102
assert isinstance(result.timestamp, float)
103-
_ = result.plot_integrated_histogram()
104-
_, _ = result.plot_heatmap()
105103

106104

107105
def test_estimate_parallel_readout_errors_all_zeros() -> None:
@@ -176,7 +174,7 @@ def test_estimate_parallel_readout_errors_batching() -> None:
176174

177175

178176
def test_estimate_parallel_readout_errors_with_noise() -> None:
179-
qubits = cirq.LineQubit.range(5)
177+
qubits = cirq.GridQubit.rect(5, 1)
180178
sampler = NoisySingleQubitReadoutSampler(p0=0.1, p1=0.2, seed=1234)
181179
repetitions = 1000
182180
result = cirq.estimate_parallel_single_qubit_readout_errors(
@@ -188,6 +186,8 @@ def test_estimate_parallel_readout_errors_with_noise() -> None:
188186
assert 0.07 < error < 0.13
189187
assert result.repetitions == repetitions
190188
assert isinstance(result.timestamp, float)
189+
result.plot_integrated_histogram()
190+
result.plot_heatmap()
191191

192192

193193
def test_estimate_parallel_readout_errors_missing_qubits() -> None:

0 commit comments

Comments
 (0)