From ba9eb905ff5a109d56262dc15079b739496d9252 Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Fri, 24 May 2024 14:53:05 +0900 Subject: [PATCH] Add simulator_metadata in metadata of SamplerV2 (#2109) Co-authored-by: Hiroshi Horii --- qiskit_aer/primitives/sampler_v2.py | 4 +++- .../add_sampler_v2_simulator_metadata-e17850d483439f9a.yaml | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/add_sampler_v2_simulator_metadata-e17850d483439f9a.yaml diff --git a/qiskit_aer/primitives/sampler_v2.py b/qiskit_aer/primitives/sampler_v2.py index 4f8c8f52a2..006fd1a5ff 100644 --- a/qiskit_aer/primitives/sampler_v2.py +++ b/qiskit_aer/primitives/sampler_v2.py @@ -156,6 +156,7 @@ def _run_pub(self, pub: SamplerPub) -> PubResult: for item in meas_info } + metadata = {"shots": pub.shots} if qargs: circuit.measure_all() result = self._backend.run( @@ -181,6 +182,7 @@ def _run_pub(self, pub: SamplerPub) -> PubResult: for item in meas_info: ary = _samples_to_packed_array(samples_array, item.num_bits, item.qreg_indices) arrays[item.creg_name][index] = ary + metadata["simulator_metadata"] = result.metadata else: for index in np.ndenumerate(parameter_values.shape): samples = [""] * pub.shots @@ -199,7 +201,7 @@ def _run_pub(self, pub: SamplerPub) -> PubResult: item.creg_name: BitArray(arrays[item.creg_name], item.num_bits) for item in meas_info } data_bin = data_bin_cls(**meas) - return PubResult(data_bin, metadata={"shots": pub.shots}) + return PubResult(data_bin, metadata=metadata) def _preprocess_circuit(circuit: QuantumCircuit): diff --git a/releasenotes/notes/add_sampler_v2_simulator_metadata-e17850d483439f9a.yaml b/releasenotes/notes/add_sampler_v2_simulator_metadata-e17850d483439f9a.yaml new file mode 100644 index 0000000000..5fb206b528 --- /dev/null +++ b/releasenotes/notes/add_sampler_v2_simulator_metadata-e17850d483439f9a.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + This fix adds `simulator_metadata` in the `metadata` of `PubResults` + for SamplerV2 primitive as similar to EstimatorV2 primitive