Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default_shots in EstimatorV2 local mode #1773

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions qiskit_ibm_runtime/fake_provider/local_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from __future__ import annotations

import math
import copy
import logging
import warnings
Expand Down Expand Up @@ -326,6 +327,8 @@ def _run_backend_primitive_v2(
prim_options["default_shots"] = default_shots
primitive_inst = BackendSamplerV2(backend=backend, options=prim_options)
else:
if default_shots := options_copy.pop("default_shots", None):
inputs["precision"] = 1 / math.sqrt(default_shots)
if default_precision := options_copy.pop("default_precision", None):
prim_options["default_precision"] = default_precision
primitive_inst = BackendEstimatorV2(backend=backend, options=prim_options)
Expand Down
2 changes: 2 additions & 0 deletions release-notes/unreleased/1773.feat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``default_shots`` are now a supported option when using ``EstimatorV2`` in
local testing mode.
11 changes: 10 additions & 1 deletion test/unit/test_local_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,23 @@ def test_v2_sampler_with_accepted_options(self, backend):

@data(FakeManila(), FakeManilaV2(), AerSimulator.from_backend(FakeManila()))
def test_v2_estimator_with_accepted_options(self, backend):
"""Test V1 estimator with accepted options."""
"""Test V2 estimator with accepted options."""
options = {"default_precision": 0.03125, "simulator": {"seed_simulator": 42}}
inst = EstimatorV2(backend=backend, options=options)
job = inst.run(**get_primitive_inputs(inst, backend=backend))
pub_result = job.result()[0]
self.assertDictEqual(pub_result.metadata, {"target_precision": 0.03125})
self.assertEqual(pub_result.data.evs[0], 0.056640625)

@data(FakeManila(), FakeManilaV2(), AerSimulator.from_backend(FakeManila()))
def test_v2_estimator_with_default_shots_option(self, backend):
"""Test V2 estimator with default shots converted to precision."""
options = {"default_shots": 100}
inst = EstimatorV2(backend=backend, options=options)
job = inst.run(**get_primitive_inputs(inst, backend=backend))
pub_result = job.result()[0]
self.assertDictEqual(pub_result.metadata, {"target_precision": 0.1})

@combine(
primitive=[SamplerV2, EstimatorV2], backend=[FakeManila(), FakeManilaV2(), AerSimulator()]
)
Expand Down