Skip to content
Open
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
8 changes: 7 additions & 1 deletion qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def _validate_options(self, options: dict) -> None:
"""Validate that primitive inputs (options) are valid

Raises:
ValidationError: if validation fails.
ValueError: if validation fails.
"""

Expand All @@ -168,6 +167,13 @@ def _validate_options(self, options: dict) -> None:
"a coupling map is required."
)

if isinstance(rep_delay := options.get("execution", {}).get("rep_delay"), (int, float)):
rep_delay_range = self._backend.configuration().rep_delay_range
if rep_delay < rep_delay_range[0] or rep_delay > rep_delay_range[1]:
raise ValueError(
f"rep_delay {rep_delay} is not in the backend rep_delay_range {rep_delay_range}"
)

@classmethod
def _program_id(cls) -> str:
"""Return the program ID."""
Expand Down
10 changes: 7 additions & 3 deletions qiskit_ibm_runtime/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ def _validate_options(self, options: dict) -> None:
"""Validate that primitive inputs (options) are valid

Raises:
ValidationError: if validation fails.
ValueError: if validation fails.
"""

pass
if isinstance(rep_delay := options.get("execution", {}).get("rep_delay"), (int, float)):
rep_delay_range = self._backend.configuration().rep_delay_range
if rep_delay < rep_delay_range[0] or rep_delay > rep_delay_range[1]:
raise ValueError(
f"rep_delay {rep_delay} is not in the backend rep_delay_range {rep_delay_range}"
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to repeat this code but I don't think there's a way to do this directly in the ExecutionOptions because we need to check the backend config for the rep_delay_range


@classmethod
def _program_id(cls) -> str:
Expand Down
2 changes: 2 additions & 0 deletions release-notes/unreleased/2389.feat.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added client side validation to check if a given ``rep_delay`` is within the backend's
``rep_delay_range``.
16 changes: 13 additions & 3 deletions test/unit/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def test_unsupported_dynamical_decoupling_with_dynamic_circuits(self):

def test_run_default_options(self):
"""Test run using default options."""
session = MagicMock(spec=MockSession, _backend="common_backend")
backend = get_mocked_backend()
session = MagicMock(spec=MockSession, _backend=backend)
options_vars = [
(
SamplerOptions( # pylint: disable=unexpected-keyword-arg
Expand All @@ -119,10 +120,10 @@ def test_run_default_options(self):
),
(
{
"execution": {"init_qubits": True, "rep_delay": 0.01},
"execution": {"init_qubits": True, "rep_delay": 0.0001},
},
{
"execution": {"init_qubits": True, "rep_delay": 0.01},
"execution": {"init_qubits": True, "rep_delay": 0.0001},
},
),
]
Expand All @@ -136,6 +137,15 @@ def test_run_default_options(self):
f"{inputs} and {expected} not partially equal.",
)

def test_rep_delay_validation(self):
"""Test rep_delay_validation."""
backend = get_mocked_backend()
session = MagicMock(spec=MockSession, _backend=backend)
options = {"execution": {"init_qubits": True, "rep_delay": 0.1}}
inst = SamplerV2(mode=session, options=options)
with self.assertRaises(ValueError):
inst.run((self.circuit,))

def test_sampler_validations(self):
"""Test exceptions when failing client-side validations."""
backend = get_mocked_backend()
Expand Down
Loading