Skip to content

Commit f3490aa

Browse files
authored
Add measure to test circuit to avoid warnings (#1544)
Recently, qiskit-ibm-runtime's `SamplerV2.run` started warning about circuits that do not have any measurements. Here a measurement is added to the circuit of `FakeExperiment` so that all the tests using it do not issue warnings. Additionally, the number of qubits set on the test backend was corrected in a couple tests. The incorrect qubit number was exposed by transpiler errors after adding the `measure_all()` call that added measurements on higher index qubits than the backend was set to support.
1 parent a1056d6 commit f3490aa

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

test/fake_experiment.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@ def __init__(self, physical_qubits=None, backend=None, experiment_type=None):
8282

8383
def circuits(self):
8484
"""Fake circuits."""
85-
return [QuantumCircuit(len(self.physical_qubits))]
85+
circ = QuantumCircuit(len(self.physical_qubits))
86+
# Add measurement to avoid warnings about no measurements
87+
circ.measure_all()
88+
return [circ]

test/framework/test_composite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def test_nested_composite(self):
346346
exp4 = BatchExperiment([exp3, exp1], flatten_results=False)
347347
exp5 = ParallelExperiment([exp4, FakeExperiment([4])], flatten_results=False)
348348
nested_exp = BatchExperiment([exp5, exp3], flatten_results=False)
349-
expdata = nested_exp.run(FakeBackend(num_qubits=4))
349+
expdata = nested_exp.run(FakeBackend(num_qubits=5))
350350
self.assertExperimentDone(expdata)
351351

352352
def test_analysis_replace_results_true(self):

test/framework/test_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def fake_job_data(self):
6060

6161
def test_metadata(self):
6262
"""Test the metadata of a basic experiment."""
63-
backend = FakeBackend(num_qubits=2)
63+
backend = FakeBackend(num_qubits=3)
6464
exp = FakeExperiment((0, 2))
6565
expdata = exp.run(backend)
6666
self.assertExperimentDone(expdata)

0 commit comments

Comments
 (0)