Skip to content

Commit

Permalink
Remove 0.25 deprecations (#1965)
Browse files Browse the repository at this point in the history
* Remove 0.25 deprecations

* Fix unit tests

* Add release note
  • Loading branch information
kt474 authored Oct 23, 2024
1 parent 9e3c397 commit 50d143e
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 373 deletions.
9 changes: 0 additions & 9 deletions qiskit_ibm_runtime/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ def _validate_options(self, options: dict) -> None:
"a coupling map is required."
)

if options.get("optimization_level", None):
issue_deprecation_msg(
msg="The 'optimization_level' option is deprecated",
version="0.25.0",
remedy="Instead, you can perform circuit optimization using Qiskit transpiler "
"or Qiskit transpiler service. "
"See https://docs.quantum.ibm.com/guides/transpile for more information.",
)

@classmethod
def _program_id(cls) -> str:
"""Return the program ID."""
Expand Down
12 changes: 0 additions & 12 deletions qiskit_ibm_runtime/options/estimator_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from .utils import primitive_dataclass, make_constraint_validator

MAX_RESILIENCE_LEVEL: int = 2
MAX_OPTIMIZATION_LEVEL: int = 1


@primitive_dataclass
Expand Down Expand Up @@ -64,16 +63,6 @@ class EstimatorOptions(OptionsV2):
Default: ``None``.
"""
optimization_level: Union[UnsetType, int] = Unset
r"""(DEPRECATED) How much optimization to perform on the circuits.
Higher levels generate more optimized circuits,
at the expense of longer processing times.
* 0: no optimization
* 1: light optimization
Default: 0.
"""
resilience_level: Union[UnsetType, int] = Unset
r"""How much resilience to build against errors.
Higher levels generate more accurate results,
Expand Down Expand Up @@ -120,5 +109,4 @@ class EstimatorOptions(OptionsV2):

_gt0 = make_constraint_validator("default_precision", gt=0)
_ge0 = make_constraint_validator("default_shots", ge=0)
_opt_lvl = make_constraint_validator("optimization_level", ge=0, le=MAX_OPTIMIZATION_LEVEL)
_res_lvl = make_constraint_validator("resilience_level", ge=0, le=MAX_RESILIENCE_LEVEL)
3 changes: 0 additions & 3 deletions qiskit_ibm_runtime/options/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ def _set_if_exists(name: str, _inputs: dict, _options: dict) -> None:
# TODO: We can just move this to json encoder
if isinstance(coupling_map, CouplingMap):
sim_options["coupling_map"] = list(map(list, coupling_map.get_edges()))
output_options["transpilation"] = {
"optimization_level": options_copy.get("optimization_level", Unset),
}

for fld in [
"default_precision",
Expand Down
52 changes: 0 additions & 52 deletions qiskit_ibm_runtime/runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,55 +364,3 @@ def backend(self, timeout: Optional[float] = None) -> Optional[Backend]:
except RequestsApiError as err:
raise IBMRuntimeError(f"Failed to get job backend: {err}") from None
return self._backend

@deprecate_function("stream_results()", "0.25", "", stacklevel=1)
def stream_results(
self, callback: Callable, decoder: Optional[Type[ResultDecoder]] = None
) -> None:
"""(DEPRECATED) Start streaming job results.
Args:
callback: Callback function to be invoked for any interim results and final result.
The callback function will receive 2 positional parameters:
1. Job ID
2. Job result.
decoder: A :class:`ResultDecoder` subclass used to decode job results.
Raises:
RuntimeInvalidStateError: If a callback function is already streaming results or
if the job already finished.
"""
if self._status in self.JOB_FINAL_STATES:
raise RuntimeInvalidStateError("Job already finished.")
if self._is_streaming():
raise RuntimeInvalidStateError("A callback function is already streaming results.")
self._ws_client_future = self._executor.submit(self._start_websocket_client)
self._executor.submit(
self._stream_results,
result_queue=self._result_queue,
user_callback=callback,
decoder=decoder,
)

@deprecate_function("interim_results()", "0.25", "", stacklevel=1)
def interim_results(self, decoder: Optional[Type[ResultDecoder]] = None) -> Any:
"""(DEPRECATED) Return the interim results of the job.
Args:
decoder: A :class:`ResultDecoder` subclass used to decode interim results.
Returns:
Runtime job interim results.
Raises:
RuntimeJobFailureError: If the job failed.
"""
if not self._final_interim_results:
_decoder = decoder or self._interim_result_decoder
interim_results_raw = self._api_client.job_interim_results(job_id=self.job_id())
self._interim_results = _decoder.decode(interim_results_raw)
if self.status() in self.JOB_FINAL_STATES:
self._final_interim_results = True
return self._interim_results
52 changes: 0 additions & 52 deletions qiskit_ibm_runtime/runtime_job_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,55 +271,3 @@ def backend(self, timeout: Optional[float] = None) -> Optional[Backend]:
except RequestsApiError as err:
raise IBMRuntimeError(f"Failed to get job backend: {err}") from None
return self._backend

@deprecate_function("stream_results()", "0.25", "", stacklevel=1)
def stream_results(
self, callback: Callable, decoder: Optional[Type[ResultDecoder]] = None
) -> None:
"""(DEPRECATED) Start streaming job results.
Args:
callback: Callback function to be invoked for any interim results and final result.
The callback function will receive 2 positional parameters:
1. Job ID
2. Job result.
decoder: A :class:`ResultDecoder` subclass used to decode job results.
Raises:
RuntimeInvalidStateError: If a callback function is already streaming results or
if the job already finished.
"""
if self._status in self.JOB_FINAL_STATES:
raise RuntimeInvalidStateError("Job already finished.")
if self._is_streaming():
raise RuntimeInvalidStateError("A callback function is already streaming results.")
self._ws_client_future = self._executor.submit(self._start_websocket_client)
self._executor.submit(
self._stream_results,
result_queue=self._result_queue,
user_callback=callback,
decoder=decoder,
)

@deprecate_function("interim_results()", "0.25", "", stacklevel=1)
def interim_results(self, decoder: Optional[Type[ResultDecoder]] = None) -> Any:
"""(DEPRECATED) Return the interim results of the job.
Args:
decoder: A :class:`ResultDecoder` subclass used to decode interim results.
Returns:
Runtime job interim results.
Raises:
RuntimeJobFailureError: If the job failed.
"""
if not self._final_interim_results:
_decoder = decoder or self._interim_result_decoder
interim_results_raw = self._api_client.job_interim_results(job_id=self.job_id())
self._interim_results = _decoder.decode(interim_results_raw)
if self.status() in self.JOB_FINAL_STATES:
self._final_interim_results = True
return self._interim_results
4 changes: 4 additions & 0 deletions release-notes/unreleased/1965.other.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deprecations from the ``0.25.0`` release have been removed.

- ``optimization_level`` is no longer a valid option for ``EstimatorV2``.
- Job methods ``interim_results()`` and ``stream_results()`` have been removed.
9 changes: 3 additions & 6 deletions test/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ def test_run_program_inputs(self, abs_pubs):
def test_unsupported_values_for_estimator_options(self):
"""Test exception when options levels are not supported."""
options_bad = [
{"resilience_level": 4, "optimization_level": 1},
{"optimization_level": 4, "resilience_level": 2},
{
"resilience_level": 4,
},
]

with Session(
Expand Down Expand Up @@ -115,10 +116,6 @@ def test_run_default_options(self):
EstimatorOptions(default_shots=1024), # pylint: disable=unexpected-keyword-arg
{"default_shots": 1024},
),
(
EstimatorOptions(optimization_level=1), # pylint: disable=unexpected-keyword-arg
{"transpilation": {"optimization_level": 1}},
),
(
{
"default_precision": 0.1,
Expand Down
28 changes: 2 additions & 26 deletions test/unit/test_estimator_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class TestEstimatorOptions(IBMTestCase):
"""Class for testing the EstimatorOptions class."""

@data(
({"optimization_level": 99}, "optimization_level must be <=1"),
({"resilience_level": -1}, "resilience_level must be >=0"),
({"default_precision": 0}, "default_precision must be >0"),
(
Expand Down Expand Up @@ -99,7 +98,6 @@ def test_program_inputs(self):
# pylint: disable=unexpected-keyword-arg

noise_model = NoiseModel.from_backend(FakeManilaV2())
optimization_level = 0
resilience_level = 2
simulator = {
"noise_model": noise_model,
Expand Down Expand Up @@ -132,7 +130,6 @@ def test_program_inputs(self):
simulator=simulator,
default_precision=0.5,
default_shots=1000,
optimization_level=optimization_level,
resilience_level=resilience_level,
seed_estimator=42,
dynamical_decoupling=dynamical_decoupling,
Expand All @@ -142,9 +139,6 @@ def test_program_inputs(self):
experimental={"foo": "bar", "execution": {"secret": 88}},
)

transpilation = {
"optimization_level": optimization_level,
}
execution.update(
{
"secret": 88,
Expand All @@ -154,7 +148,6 @@ def test_program_inputs(self):
"default_precision": 0.5,
"default_shots": 1000,
"seed_estimator": 42,
"transpilation": transpilation,
"twirling": twirling,
"dynamical_decoupling": dynamical_decoupling,
"execution": execution,
Expand All @@ -176,7 +169,7 @@ def test_program_inputs(self):
{},
{"default_precision": 0.5},
{"simulator": {"seed_simulator": 42}},
{"optimization_level": 1, "environment": {"log_level": "WARNING"}},
{"environment": {"log_level": "WARNING"}},
{"execution": {"init_qubits": True}},
{"twirling": {"enable_gates": True, "strategy": "active"}},
{"environment": {"log_level": "ERROR"}},
Expand All @@ -196,11 +189,10 @@ def test_init_options_with_dictionary(self, opts_dict):
@data(
{"resilience_level": 2},
{"max_execution_time": 200},
{"resilience_level": 2, "optimization_level": 1},
{"resilience_level": 2},
{"default_shots": 1024, "simulator": {"seed_simulator": 42}},
{"resilience_level": 2, "default_shots": 2048},
{
"optimization_level": 1,
"environment": {"log_level": "INFO"},
},
{"resilience": {"zne_mitigation": True, "zne": {"noise_factors": [1, 2, 3]}}},
Expand Down Expand Up @@ -233,15 +225,6 @@ def test_zero_values(self, opt_dict):
options = backend.service._run.call_args.kwargs["inputs"]["options"]
self.assertDictEqual(options, opt_dict)

def test_zero_optimization_level(self):
"""Test optimization_level=0."""
opt_dict = {"optimization_level": 0}
backend = get_mocked_backend()
estimator = Estimator(mode=backend, options=opt_dict)
_ = estimator.run(**get_primitive_inputs(estimator))
options = backend.service._run.call_args.kwargs["inputs"]["options"]
self.assertDictEqual(options, {"transpilation": {"optimization_level": 0}})

def test_zero_resilience_level(self):
"""Test resilience_level=0"""
opt_dict = {"resilience_level": 0}
Expand All @@ -251,10 +234,3 @@ def test_zero_resilience_level(self):
options = backend.service._run.call_args.kwargs["inputs"]
self.assertIn("resilience_level", options)
self.assertEqual(options["resilience_level"], 0)

def test_optimization_level_deprecation(self):
"""Test optimization level being deprecated."""
backend = get_mocked_backend()
estimator = Estimator(mode=backend, options={"optimization_level": 1})
with self.assertWarnsRegex(DeprecationWarning, r".*optimization_level.*"):
_ = estimator.run(**get_primitive_inputs(estimator))
8 changes: 0 additions & 8 deletions test/unit/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,6 @@ def test_final_result(self, service):
result = job.result()
self.assertTrue(result)

@run_quantum_and_cloud_fake
def test_interim_results(self, service):
"""Test getting interim results."""
job = run_program(service)
# TODO maybe a bit more validation on the returned interim results
interim_results = job.interim_results()
self.assertTrue(interim_results)

@run_quantum_and_cloud_fake
def test_job_status(self, service):
"""Test job status."""
Expand Down
1 change: 0 additions & 1 deletion test/unit/test_options_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def test_merge_estimator_options(self):
{"default_shots": 99, "seed_estimator": 42},
{"resilience_level": 99, "default_shots": 98},
{
"optimization_level": 1,
"environment": {"log_level": "INFO"},
},
{
Expand Down
Loading

0 comments on commit 50d143e

Please sign in to comment.