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

Remove deprecation warning for unsupported parameters of transpilation settings #866

Merged
merged 24 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5245ea8
Changed deprecation warning to error
merav-aharoni May 22, 2023
33ddcfd
Changed deprecation of transpilation_options to error
merav-aharoni May 22, 2023
343ae84
Merge branch 'main' into remove_deprecations
merav-aharoni May 22, 2023
0d9b6c7
Raise error if backend is passed through 'options'
merav-aharoni May 22, 2023
70001bc
Merge branch 'remove_deprecations' of github.com:merav-aharoni/qiskit…
merav-aharoni May 22, 2023
04fd3ca
black
merav-aharoni May 22, 2023
9d72ca8
Removed unused import
merav-aharoni May 22, 2023
0b73417
Reverted changes related to deprecating backend in optios
merav-aharoni May 23, 2023
93b5ac5
Merge branch 'main' into remove_deprecations
merav-aharoni May 25, 2023
ad76b12
Removed specific error message for 'timing_constraints' and 'translat…
merav-aharoni May 25, 2023
a4946cf
Added checks for unsupported options
merav-aharoni May 25, 2023
5341abd
Added calls to specific validation methods from main validation
merav-aharoni May 25, 2023
70bece2
Added test
merav-aharoni May 25, 2023
78ba594
Release notes
merav-aharoni May 25, 2023
cdcdc54
Merge branch 'remove_deprecations' of github.com:merav-aharoni/qiskit…
merav-aharoni May 25, 2023
3018ad3
typo
merav-aharoni May 25, 2023
5a3f45e
Attempting to fix documentation error
merav-aharoni May 28, 2023
3b55f0e
Merge branch 'main' into remove_deprecations
merav-aharoni May 28, 2023
f134b6b
Merge branch 'main' into remove_deprecations
kt474 May 30, 2023
b182cd7
Merge branch 'main' into remove_deprecations
merav-aharoni Jun 4, 2023
3706fb7
Merge branch 'main' into remove_deprecations
merav-aharoni Jul 30, 2023
ee951de
Merge branch 'main' into remove_deprecations
kt474 Aug 7, 2023
f49d185
fix lint
kt474 Aug 10, 2023
a0baa0e
Merge branch 'main' into remove_deprecations
kt474 Aug 10, 2023
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
16 changes: 16 additions & 0 deletions qiskit_ibm_runtime/options/execution_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
"""Execution options."""

from dataclasses import dataclass
from typing import Literal, get_args

from .utils import _flexible

ExecutionSupportedOptions = Literal[
"shots",
"init_qubits",
]


@_flexible
@dataclass
Expand All @@ -31,3 +37,13 @@ class ExecutionOptions:

shots: int = 4000
init_qubits: bool = True

@staticmethod
def validate_execution_options(execution_options: dict) -> None:
"""Validate that execution options are legal.
Raises:
ValueError: if any execution option is not supported
"""
for opt in execution_options:
if not opt in get_args(ExecutionSupportedOptions):
raise ValueError(f"Unsupported value '{opt}' for execution.")
11 changes: 2 additions & 9 deletions qiskit_ibm_runtime/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from .transpilation_options import TranspilationOptions
from .resilience_options import ResilienceOptions
from ..runtime_options import RuntimeOptions
from ..utils.deprecation import issue_deprecation_msg


@_flexible
Expand Down Expand Up @@ -143,14 +142,6 @@ def _get_program_inputs(options: dict) -> dict:
}
)

for deprecated in ["translation_method", "timing_constraints"]:
if deprecated in inputs["transpilation_settings"]:
issue_deprecation_msg(
msg=f"The {deprecated} transpilation option has been deprecated",
version="0.8",
remedy="",
)

known_keys = list(Options.__dataclass_fields__.keys())
known_keys.append("image")
# Add additional unknown keys.
Expand Down Expand Up @@ -188,6 +179,8 @@ def validate_options(options: dict) -> None:
)

EnvironmentOptions.validate_environment_options(options.get("environment"))
ExecutionOptions.validate_execution_options(options.get("execution"))
SimulatorOptions.validate_simulator_options(options.get("simulator"))

@staticmethod
def _get_runtime_options(options: dict) -> dict:
Expand Down
9 changes: 9 additions & 0 deletions qiskit_ibm_runtime/options/resilience_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

from .utils import _flexible

ResilienceSupportedOptions = Literal[
"noise_amplifier",
"noise_factors",
"extrapolator",
]
NoiseAmplifierType = Literal[
"TwoQubitAmplifier",
"GlobalFoldingAmplifier",
Expand Down Expand Up @@ -63,11 +68,15 @@ class ResilienceOptions:
def validate_resilience_options(resilience_options: dict) -> None:
"""Validate that resilience options are legal.
Raises:
ValueError: if any resilience option is not supported
ValueError: if noise_amplifier is not in NoiseAmplifierType.
ValueError: if extrapolator is not in ExtrapolatorType.
ValueError: if extrapolator == "QuarticExtrapolator" and number of noise_factors < 5.
ValueError: if extrapolator == "CubicExtrapolator" and number of noise_factors < 4.
"""
for opt in resilience_options:
if not opt in get_args(ResilienceSupportedOptions):
raise ValueError(f"Unsupported value '{opt}' for resilience.")
noise_amplifier = resilience_options.get("noise_amplifier")
if not noise_amplifier in get_args(NoiseAmplifierType):
raise ValueError(
Expand Down
20 changes: 19 additions & 1 deletion qiskit_ibm_runtime/options/simulator_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@

"""Simulator options."""


from typing import Optional, List, Union, Literal, get_args, TYPE_CHECKING
from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Optional, Union

from qiskit.exceptions import MissingOptionalLibraryError
from qiskit.providers import BackendV1, BackendV2
Expand All @@ -26,6 +27,13 @@
if TYPE_CHECKING:
import qiskit_aer

SimulatorSupportedOptions = Literal[
"noise_model",
"seed_simulator",
"coupling_map",
"basis_gates",
]


@_flexible
@dataclass()
Expand Down Expand Up @@ -54,6 +62,16 @@ class SimulatorOptions:
coupling_map: Optional[Union[List[List[int]], "CouplingMap"]] = None
basis_gates: Optional[List[str]] = None

@staticmethod
def validate_simulator_options(simulator_options: dict) -> None:
"""Validate that simulator options are legal.
Raises:
ValueError: if any simulator option is not supported
"""
for opt in simulator_options:
if not opt in get_args(SimulatorSupportedOptions):
raise ValueError(f"Unsupported value '{opt}' for simulator.")

def set_backend(self, backend: Union[BackendV1, BackendV2]) -> None:
"""Set backend for simulation.
This method changes noise_model, coupling_map, basis_gates according to given backend.
Expand Down
11 changes: 11 additions & 0 deletions qiskit_ibm_runtime/options/transpilation_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

from .utils import _flexible

TranspilationSupportedOptions = Literal[
"skip_transpilation",
"initial_layout",
"layout_method",
"routing_method",
"approximation_degree",
]
LayoutMethodType = Literal[
"trivial",
"dense",
Expand Down Expand Up @@ -64,10 +71,14 @@ class TranspilationOptions:
def validate_transpilation_options(transpilation_options: dict) -> None:
"""Validate that transpilation options are legal.
Raises:
ValueError: if any transpilation option is not supported
ValueError: if layout_method is not in LayoutMethodType or None.
ValueError: if routing_method is not in RoutingMethodType or None.
ValueError: if approximation_degree in not None or in the range 0.0 to 1.0.
"""
for opt in transpilation_options:
if not opt in get_args(TranspilationSupportedOptions):
raise ValueError(f"Unsupported value '{opt}' for transpilation.")
layout_method = transpilation_options.get("layout_method")
if not (layout_method in get_args(LayoutMethodType) or layout_method is None):
raise ValueError(
Expand Down
8 changes: 8 additions & 0 deletions releasenotes/notes/option_validation-79d26018ab770519.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
features:
- |
Added validations for options on the second level of the dict,
i.e., for each of resilience, simulator, execution, and
transpilation, check that their options are supported.
Otherwise throw an exception.

23 changes: 23 additions & 0 deletions test/unit/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,29 @@ def test_init_options_with_dictionary(self):
# Make sure the structure didn't change.
self.assertTrue(dict_keys_equal(asdict(Options()), options), f"options={options}")

def test_unsupported_options(self):
"""Test error on unsupported second level options"""
# defining minimal dict of options
options = {
"optimization_level": 1,
"resilience_level": 2,
"transpilation": {"initial_layout": [1, 2], "skip_transpilation": True},
"execution": {"shots": 100},
"environment": {"log_level": "DEBUG"},
"simulator": {"noise_model": "model"},
"resilience": {
"noise_amplifier": "GlobalFoldingAmplifier",
"extrapolator": "LinearExtrapolator",
},
}
Options.validate_options(options)
for opt in ["resilience", "simulator", "transpilation", "execution"]:
temp_options = options.copy()
temp_options[opt] = {"aaa": "bbb"}
with self.assertRaises(ValueError) as exc:
Options.validate_options(temp_options)
self.assertIn(f"Unsupported value 'aaa' for {opt}.", str(exc.exception))

def test_coupling_map_options(self):
"""Check that coupling_map is processed correctly for various types"""
coupling_map = {(1, 0), (2, 1), (0, 1), (1, 2)}
Expand Down