diff --git a/qiskit_ibm_runtime/fake_provider/local_service.py b/qiskit_ibm_runtime/fake_provider/local_service.py index d8ba49724..350c622c3 100644 --- a/qiskit_ibm_runtime/fake_provider/local_service.py +++ b/qiskit_ibm_runtime/fake_provider/local_service.py @@ -14,6 +14,7 @@ from __future__ import annotations +import math import copy import logging import warnings @@ -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) diff --git a/release-notes/unreleased/1773.feat.rst b/release-notes/unreleased/1773.feat.rst new file mode 100644 index 000000000..258ff0b6b --- /dev/null +++ b/release-notes/unreleased/1773.feat.rst @@ -0,0 +1,2 @@ +``default_shots`` are now a supported option when using ``EstimatorV2`` in +local testing mode. \ No newline at end of file diff --git a/test/unit/test_local_mode.py b/test/unit/test_local_mode.py index a3302f4bf..d0736eaa5 100644 --- a/test/unit/test_local_mode.py +++ b/test/unit/test_local_mode.py @@ -173,7 +173,7 @@ 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)) @@ -181,6 +181,15 @@ def test_v2_estimator_with_accepted_options(self, backend): 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()] )