Skip to content

Commit

Permalink
Add shots to QuasiDistributions in primitives.Sampler (#8791)
Browse files Browse the repository at this point in the history
* add shots to QuasiDistributions

* add tests

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
ikkoham and mergify[bot] committed Oct 7, 2022
1 parent b4b9332 commit 3936c43
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/primitives/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _call(
]
for metadatum in metadata:
metadatum["shots"] = shots
quasis = [QuasiDistribution(dict(enumerate(p))) for p in probabilities]
quasis = [QuasiDistribution(dict(enumerate(p)), shots=shots) for p in probabilities]

return SamplerResult(quasis, metadata)

Expand Down
2 changes: 2 additions & 0 deletions test/python/primitives/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ def test_with_shots_option(self):
sampler = Sampler(circuits=self._pqc)
result = sampler(circuits=[0], parameter_values=params, shots=1024, seed=15)
self._compare_probs(result.quasi_dists, target)
self.assertEqual(result.quasi_dists[0].shots, 1024)

def test_with_shots_option_none(self):
"""test with shots=None option. Seed is ignored then."""
Expand Down Expand Up @@ -739,6 +740,7 @@ def test_options(self):
params, target = self._generate_params_target([1])
result = sampler.run([self._pqc], parameter_values=params).result()
self._compare_probs(result.quasi_dists, target)
self.assertEqual(result.quasi_dists[0].shots, 1024)

def test_different_circuits(self):
"""Test collision of quantum circuits."""
Expand Down

0 comments on commit 3936c43

Please sign in to comment.