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

Options v2 #1221

Merged
merged 32 commits into from
Nov 16, 2023
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2785023
Add experimental options (#1067)
jyu00 Sep 20, 2023
cf0d816
Merge branch 'main' of https://github.com/Qiskit/qiskit-ibm-runtime i…
jyu00 Oct 27, 2023
989a321
fix merge issues
jyu00 Oct 27, 2023
5ab8a93
add pydantic
jyu00 Oct 30, 2023
11c30cc
black
jyu00 Oct 30, 2023
e6ef47f
lint
jyu00 Oct 30, 2023
e998b81
Merge branch 'fast_forward' of https://github.com/jyu00/qiskit-ibm-ru…
jyu00 Oct 31, 2023
3e0b4af
Fast forward experimental to latest main (#1178)
jyu00 Oct 31, 2023
b5c7100
v2 options
jyu00 Nov 1, 2023
3671b46
estimator options
jyu00 Nov 3, 2023
bf5a677
update test
jyu00 Nov 3, 2023
1d4b36e
lint
jyu00 Nov 3, 2023
1790d63
Merge branch 'experimental' of https://github.com/Qiskit/qiskit-ibm-r…
jyu00 Nov 3, 2023
4198fad
fix merge issues
jyu00 Nov 3, 2023
9c3e359
black
jyu00 Nov 3, 2023
4ec1b9e
fix noise model type
jyu00 Nov 3, 2023
3c9261c
lint again
jyu00 Nov 3, 2023
6369191
fix header
jyu00 Nov 6, 2023
548005a
fix mypy
jyu00 Nov 6, 2023
d05ce59
use v2 as default
jyu00 Nov 6, 2023
6745067
cleanup terra options
jyu00 Nov 6, 2023
7370b5d
black
jyu00 Nov 6, 2023
a19ccd4
options need not be callable
jyu00 Nov 6, 2023
52febc9
fix doc
jyu00 Nov 6, 2023
b29a4e5
fix tests
jyu00 Nov 6, 2023
1f8bd7c
fix version
jyu00 Nov 6, 2023
a56cdf0
freeze constants
jyu00 Nov 7, 2023
0131789
remove is_simulator
jyu00 Nov 7, 2023
665b881
make image work
jyu00 Nov 8, 2023
9439047
Merge branch 'main' of https://github.com/Qiskit/qiskit-ibm-runtime i…
jyu00 Nov 16, 2023
9dd2c7d
fix tests
jyu00 Nov 16, 2023
d987572
lint
jyu00 Nov 16, 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
Prev Previous commit
Next Next commit
remove is_simulator
jyu00 committed Nov 7, 2023
commit 01317894ead8f9c21b3a83f4ffd5ad8fb0500c76
17 changes: 14 additions & 3 deletions qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
@@ -155,9 +155,6 @@ def __init__(
Estimator.__init__(self)
BasePrimitiveV2.__init__(self, backend=backend, session=session, options=options)

self.options._is_simulator = (
self._backend is not None and self._backend.configuration().simulator is True
)
if self._service._channel_strategy == "q-ctrl":
raise NotImplementedError("EstimatorV2 is not supported with q-ctrl channel strategy.")

@@ -244,9 +241,23 @@ def _validate_options(self, options: dict) -> None:

Raises:
ValidationError: if validation fails.
ValueError: if validation fails.
"""
self._OPTIONS_CLASS(**options)

# TODO: Server should have different optimization/resilience levels for simulator

if (
options["resilience_level"] == 3
and self._backend is not None
and self._backend.configuration().simulator is True
and not options["simulator"]["coupling_map"]
):
raise ValueError(
"When the backend is a simulator and resilience_level == 3,"
"a coupling map is required."
)

@staticmethod
def _validate_observables(
observables: Sequence[ObservablesArrayLike] | ObservablesArrayLike,
27 changes: 4 additions & 23 deletions qiskit_ibm_runtime/options/estimator_options.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@

from qiskit.transpiler import CouplingMap
from pydantic.dataclasses import dataclass as pydantic_dataclass
from pydantic import Field, ConfigDict, model_validator, field_validator
from pydantic import Field, ConfigDict, field_validator

from .utils import (
Dict,
@@ -90,11 +90,9 @@ class EstimatorOptions(OptionsV2):

"""

_VERSION: int = Field(2, frozen=True)
_MAX_OPTIMIZATION_LEVEL: int = Field(3, frozen=True)
_MAX_RESILIENCE_LEVEL: int = Field(3, frozen=True)

_is_simulator: bool = False
_VERSION: int = Field(2, frozen=True) # pylint: disable=invalid-name
_MAX_OPTIMIZATION_LEVEL: int = Field(3, frozen=True) # pylint: disable=invalid-name
_MAX_RESILIENCE_LEVEL: int = Field(3, frozen=True) # pylint: disable=invalid-name

# Sadly we cannot use pydantic's built in validation because it won't work on Unset.
optimization_level: Union[UnsetType, int] = Unset
@@ -130,23 +128,6 @@ def _validate_resilience_level(cls, resilience_level: int) -> int:
)
return resilience_level

@model_validator(mode="after")
def _validate_options(self) -> "EstimatorOptions":
"""Validate the model."""
# TODO: Server should have different optimization/resilience levels for simulator

if (
self.resilience_level == 3
and self._is_simulator
and isinstance(self.simulator.coupling_map, UnsetType) # type: ignore[union-attr]
):
raise ValueError(
"When the backend is a simulator and resilience_level == 3,"
"a coupling map is required."
)

return self

@staticmethod
def _get_program_inputs(options: dict) -> dict:
"""Convert the input options to program compatible inputs.
11 changes: 11 additions & 0 deletions test/unit/test_estimator.py
Original file line number Diff line number Diff line change
@@ -80,6 +80,17 @@ def test_unsupported_values_for_estimator_options(self):
_ = inst.run(self.circuit, observables=self.observables, **bad_opt)
self.assertIn(list(bad_opt.keys())[0], str(exc.exception))

def test_res_level3_simulator(self):
"""Test the correct default error levels are used."""

session = MagicMock(spec=MockSession)
session.service.backend().configuration().simulator = True

inst = EstimatorV2(session=session, options={"resilience_level": 3})
with self.assertRaises(ValueError) as exc:
inst.run(self.circuit, observables=self.observables)
self.assertIn("coupling map", str(exc.exception))

def test_run_default_options(self):
"""Test run using default options."""
session = MagicMock(spec=MockSession)
1 change: 0 additions & 1 deletion test/unit/test_estimator_options.py
Original file line number Diff line number Diff line change
@@ -151,7 +151,6 @@ def test_coupling_map_options(self):
{"execution": {"shots": 0}},
{"twirling": {"strategy": "foo"}},
{"transpilation": {"foo": "bar"}},
{"resilience_level": 3, "_is_simulator": True},
{"zne_noise_factors": [0.5]},
{"noise_factors": [1, 3, 5]},
{"zne_extrapolator": "exponential", "zne_noise_factors": [1]},