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
1 change: 0 additions & 1 deletion qiskit_ibm_runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@
from .ibm_backend import IBMBackend
from .runtime_job import RuntimeJob
from .runtime_job_v2 import RuntimeJobV2
from .runtime_options import RuntimeOptions
from .utils.json import RuntimeEncoder, RuntimeDecoder
from .session import Session # pylint: disable=cyclic-import
from .batch import Batch # pylint: disable=cyclic-import
Expand Down
11 changes: 3 additions & 8 deletions qiskit_ibm_runtime/fake_provider/local_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import copy
import logging
import warnings
from dataclasses import asdict
from typing import Callable, Dict, List, Literal, Optional, Union
from typing import Callable, Dict, List, Literal, Optional

from qiskit.primitives import (
BackendEstimatorV2,
Expand All @@ -34,7 +33,6 @@
from .fake_provider import FakeProviderForBackendV2 # pylint: disable=unused-import, cyclic-import
from .local_runtime_job import LocalRuntimeJob
from ..ibm_backend import IBMBackend
from ..runtime_options import RuntimeOptions

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -148,7 +146,7 @@ def _run(
self,
program_id: Literal["sampler", "estimator"],
inputs: Dict,
options: Union[RuntimeOptions, Dict],
options: Dict,
) -> PrimitiveJob:
"""Execute the runtime program.

Expand All @@ -165,10 +163,7 @@ def _run(
ValueError: If input is invalid.
NotImplementedError: If using V2 primitives.
"""
if isinstance(options, Dict):
qrt_options = copy.deepcopy(options)
else:
qrt_options = asdict(options)
qrt_options = copy.deepcopy(options)

backend = qrt_options.pop("backend", None)

Expand Down
8 changes: 3 additions & 5 deletions qiskit_ibm_runtime/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from abc import abstractmethod
from typing import Iterable, Tuple, Union, Any
from dataclasses import dataclass, fields, asdict, is_dataclass
from dataclasses import dataclass, asdict, is_dataclass
import copy

from qiskit.transpiler import CouplingMap
Expand All @@ -31,7 +31,6 @@
)
from .environment_options import EnvironmentOptions
from .simulator_options import SimulatorOptions
from ..runtime_options import RuntimeOptions


def _make_data_row(indent: int, name: str, value: Any, is_section: bool) -> Iterable[str]:
Expand Down Expand Up @@ -93,9 +92,8 @@ def _get_runtime_options(options: dict) -> dict:
environment = options_copy.get("environment") or {}
out = {"max_execution_time": options_copy.get("max_execution_time", None)}

for fld in fields(RuntimeOptions):
if fld.name in environment:
out[fld.name] = environment[fld.name]
for fld in environment:
out[fld] = environment[fld]

if "image" in options_copy:
out["image"] = options_copy["image"]
Expand Down
37 changes: 14 additions & 23 deletions qiskit_ibm_runtime/qiskit_runtime_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from .runtime_job_v2 import RuntimeJobV2
from .utils import validate_job_tags
from .api.client_parameters import ClientParameters
from .runtime_options import RuntimeOptions
from .ibm_backend import IBMBackend
from .models import QasmBackendConfiguration

Expand Down Expand Up @@ -842,7 +841,7 @@ def _run(
self,
program_id: str,
inputs: Dict,
options: Optional[Union[RuntimeOptions, Dict]] = None,
options: Optional[Dict] = None,
callback: Optional[Callable] = None,
result_decoder: Optional[Union[Type[ResultDecoder], Sequence[Type[ResultDecoder]]]] = None,
session_id: Optional[str] = None,
Expand Down Expand Up @@ -877,18 +876,9 @@ def _run(
RuntimeProgramNotFound: If the program cannot be found.
IBMRuntimeError: An error occurred running the program.
"""

qrt_options: RuntimeOptions = options
if options is None:
qrt_options = RuntimeOptions()
elif isinstance(options, Dict):
qrt_options = RuntimeOptions(**options)

qrt_options.validate(channel=self.channel)

backend = qrt_options.backend
backend = options["backend"]
if isinstance(backend, str):
backend = self.backend(name=qrt_options.get_backend_name())
backend = self.backend(name=backend)

status = backend.status()
if status.operational is True and status.status_msg != "active":
Expand All @@ -900,24 +890,24 @@ def _run(
try:
response = self._active_api_client.program_run(
program_id=program_id,
backend_name=qrt_options.get_backend_name(),
backend_name=backend.name,
params=inputs,
image=qrt_options.image,
log_level=qrt_options.log_level,
image=options.get("image"),
log_level=options.get("log_level"),
session_id=session_id,
job_tags=qrt_options.job_tags,
max_execution_time=qrt_options.max_execution_time,
job_tags=options.get("job_tags"),
max_execution_time=options.get("max_execution_time"),
start_session=start_session,
session_time=qrt_options.session_time,
private=qrt_options.private,
session_time=options.get("session_time"),
private=options.get("private"),
)

except RequestsApiError as ex:
if ex.status_code == 404:
raise RuntimeProgramNotFound(f"Program not found: {ex.message}") from None
raise IBMRuntimeError(f"Failed to run program: {ex}") from None

if response["backend"] and response["backend"] != qrt_options.get_backend_name():
if response["backend"] and response["backend"] != backend.name:
backend = self.backend(name=response["backend"])

return RuntimeJobV2(
Expand All @@ -927,10 +917,11 @@ def _run(
program_id=program_id,
user_callback=callback,
result_decoder=result_decoder,
image=qrt_options.image,
image=options.get("image"),
tags=options.get("job_tags"),
service=self,
version=version,
private=qrt_options.private,
private=options.get("private"),
)

def job(self, job_id: str) -> Union[RuntimeJob, RuntimeJobV2]:
Expand Down
118 changes: 0 additions & 118 deletions qiskit_ibm_runtime/runtime_options.py

This file was deleted.

21 changes: 0 additions & 21 deletions test/unit/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from qiskit.transpiler import CouplingMap
from qiskit_aer.noise import NoiseModel

from qiskit_ibm_runtime import RuntimeOptions
from qiskit_ibm_runtime.options import EstimatorOptions, SamplerOptions
from qiskit_ibm_runtime.fake_provider import FakeManilaV2, FakeNairobiV2

Expand All @@ -32,26 +31,6 @@
class TestOptionsV2(IBMTestCase):
"""Class for testing the v2 Options class."""

@data(EstimatorOptions, SamplerOptions)
def test_runtime_options(self, opt_cls):
"""Test converting runtime options."""
full_options = RuntimeOptions(
backend="ibm_gotham",
image="foo:bar",
log_level="DEBUG",
instance="crn",
job_tags=["foo", "bar"],
max_execution_time=600,
)
partial_options = RuntimeOptions(backend="foo", log_level="DEBUG")

for rt_options in [full_options, partial_options]:
with self.subTest(rt_options=rt_options):
self.assertGreaterEqual(
vars(rt_options).items(),
opt_cls._get_runtime_options(vars(rt_options)).items(),
)

@data(EstimatorOptions, SamplerOptions)
def test_kwargs_options(self, opt_cls):
"""Test specifying arbitrary options."""
Expand Down
Loading