Skip to content

Commit 613ebc7

Browse files
ihinckshhorii
authored andcommitted
Ensure QuantumCircuit.metadata is always a dict (Qiskit#1761)
* Ensure QuantumCircuit.metadata is always a dict This is for compatibility with Qiskit/qiskit#9849 * fix order * fix typo :( * revert object->object() change * make backportable
1 parent 7cfbc7c commit 613ebc7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

qiskit_aer/backends/aerbackend.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,13 @@ def _execute_circuits_job(self, circuits, noise_model, config, job_id="", format
426426
# Take metadata from headers of experiments to work around JSON serialization error
427427
metadata_list = []
428428
for idx, circ in enumerate(circuits):
429+
metadata_list.append(circ.metadata)
430+
# TODO: we test for True-like on purpose here to condition against both None and {},
431+
# which allows us to support versions of Terra before and after QuantumCircuit.metadata
432+
# accepts None as a valid value. This logic should be revisited after terra>=0.24.0 is
433+
# required.
429434
if circ.metadata:
430-
metadata = circ.metadata
431-
metadata_list.append(metadata)
432-
circ.metadata = {}
433-
circ.metadata["metadata_index"] = idx
434-
else:
435-
metadata_list.append(None)
435+
circ.metadata = {"metadata_index": idx}
436436

437437
# Run simulation
438438
aer_circuits = assemble_circuits(circuits)

0 commit comments

Comments
 (0)