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