diff --git a/qiskit_ibm_runtime/estimator.py b/qiskit_ibm_runtime/estimator.py index aa571622a..18daa09fd 100644 --- a/qiskit_ibm_runtime/estimator.py +++ b/qiskit_ibm_runtime/estimator.py @@ -189,7 +189,12 @@ def run( Returns: Submitted job. + Raises: + ValueError: if precision value is not strictly greater than 0. """ + if precision is not None: + if precision <= 0: + raise ValueError("The precision value must be strictly greater than 0.") coerced_pubs = [EstimatorPub.coerce(pub, precision) for pub in pubs] validate_estimator_pubs(coerced_pubs) return self._run(coerced_pubs) # type: ignore[arg-type] diff --git a/test/unit/test_estimator.py b/test/unit/test_estimator.py index e9fb10d21..723507f4c 100644 --- a/test/unit/test_estimator.py +++ b/test/unit/test_estimator.py @@ -112,6 +112,17 @@ def test_unsupported_values_for_estimator_options(self): inst.options.update(**bad_opt) self.assertIn(list(bad_opt.keys())[0], str(exc.exception)) + def test_invalid_estimator_precision_option(self): + """Test exception when precision is invalid.""" + + backend = get_mocked_backend() + backend.configuration().simulator = True + + estimator = EstimatorV2(backend=backend) + with self.assertRaises(ValueError) as exc: + estimator.run(**get_primitive_inputs(estimator), precision=0) + self.assertIn("The precision value must be strictly greater than 0", str(exc.exception)) + def test_pec_simulator(self): """Test error is raised when using pec on simulator without coupling map.""" backend = get_mocked_backend()