Skip to content

Commit b7d10c5

Browse files
Replace backend comparison test with comparison of backend attributes (backport #1510) (#1519)
Starting with qiskit-ibm-runtime 0.35, running circuits with `qiskit_ibm_runtime.SamplerV2` produces jobs whose `backend()` method returns a deepcopy of the original backend object passed to the sampler. Since `BackendV2` does not override `__eq__`, it does not compare equal to a copy of itself and the test that checks that the original backend equals the backend in the experiment data started to fail. Here the test code is updated to check that the main properties of the backend compare equal rather than comparing the backend objects directly.<hr>This is an automatic backport of pull request #1510 done by [Mergify](https://mergify.com). Co-authored-by: Will Shanks <[email protected]>
1 parent cae2473 commit b7d10c5

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/framework/test_composite.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,30 @@ def check_attributes(self, expdata):
200200
"""
201201
Recursively traverse the tree to verify attributes
202202
"""
203-
self.assertEqual(expdata.backend, self.backend)
203+
# qiskit-ibm-runtime deepcopies the backend and BackendV2 does not
204+
# define a custom __eq__ so we just check the important properties
205+
backend_attrs = (
206+
"name",
207+
"options",
208+
"instructions",
209+
"operations",
210+
"operation_names",
211+
"num_qubits",
212+
"coupling_map",
213+
"dt",
214+
)
215+
for attr in backend_attrs:
216+
self.assertEqual(getattr(expdata.backend, attr), getattr(self.backend, attr))
217+
try:
218+
self.backend.qubit_properties(list(range(self.backend.num_qubits)))
219+
except NotImplementedError:
220+
# qubit properties not set
221+
pass
222+
else:
223+
self.assertEqual(
224+
expdata.backend.qubit_properties(list(range(self.backend.num_qubits))),
225+
self.backend.qubit_properties(list(range(self.backend.num_qubits))),
226+
)
204227
self.assertEqual(expdata.share_level, self.share_level)
205228

206229
components = expdata.child_data()

0 commit comments

Comments
 (0)