Skip to content

Commit

Permalink
Add simulator_metadata in metadata of SamplerV2 (#2109)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroshi Horii <[email protected]>
  • Loading branch information
doichanj and hhorii authored May 24, 2024
1 parent b706ee1 commit ba9eb90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion qiskit_aer/primitives/sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
This fix adds `simulator_metadata` in the `metadata` of `PubResults`
for SamplerV2 primitive as similar to EstimatorV2 primitive

0 comments on commit ba9eb90

Please sign in to comment.