From e5abf1c918e3b89f8cae013af21506b6926744b7 Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Thu, 13 Jun 2024 15:37:35 -0400 Subject: [PATCH 1/3] deprecate optimization_level --- qiskit_ibm_runtime/estimator.py | 9 +++++++++ qiskit_ibm_runtime/options/estimator_options.py | 9 ++------- test/integration/test_estimator_v2.py | 2 -- test/unit/test_estimator_options.py | 7 +++++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/qiskit_ibm_runtime/estimator.py b/qiskit_ibm_runtime/estimator.py index 2a308a37a..7b9dccd71 100644 --- a/qiskit_ibm_runtime/estimator.py +++ b/qiskit_ibm_runtime/estimator.py @@ -209,6 +209,15 @@ def _validate_options(self, options: dict) -> None: "a coupling map is required." ) + if "optimization_level" in options: + 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/transpile for more information." + ) + @classmethod def _program_id(cls) -> str: """Return the program ID.""" diff --git a/qiskit_ibm_runtime/options/estimator_options.py b/qiskit_ibm_runtime/options/estimator_options.py index 67be9b08a..0cfa95eaf 100644 --- a/qiskit_ibm_runtime/options/estimator_options.py +++ b/qiskit_ibm_runtime/options/estimator_options.py @@ -60,19 +60,14 @@ class EstimatorOptions(OptionsV2): Default: ``None``. - optimization_level: How much optimization to perform on the circuits. + optimization_level: (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 - Refer to the - `Configure runtime compilation for Qiskit Runtime - `_. - for more information about the optimization levels. - - Default: 1. + Default: 0. resilience_level: How much resilience to build against errors. Higher levels generate more accurate results, diff --git a/test/integration/test_estimator_v2.py b/test/integration/test_estimator_v2.py index 574abd0e8..62ef546eb 100644 --- a/test/integration/test_estimator_v2.py +++ b/test/integration/test_estimator_v2.py @@ -78,7 +78,6 @@ def test_estimator_v2_options(self, service): estimator.options.default_precision = 0.05 estimator.options.default_shots = 400 estimator.options.resilience_level = 1 - estimator.options.optimization_level = 1 estimator.options.seed_estimator = 42 estimator.options.resilience.measure_mitigation = True estimator.options.resilience.zne_mitigation = True @@ -116,7 +115,6 @@ def test_pec(self, service): estimator = EstimatorV2(backend=backend) estimator.options.resilience_level = 0 - estimator.options.optimization_level = 0 estimator.options.resilience.pec_mitigation = True estimator.options.resilience.pec_max_overhead = 200 estimator.options.simulator.set_backend(FakeAuckland()) diff --git a/test/unit/test_estimator_options.py b/test/unit/test_estimator_options.py index 9a65df574..11f8d78ee 100644 --- a/test/unit/test_estimator_options.py +++ b/test/unit/test_estimator_options.py @@ -251,3 +251,10 @@ 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(backend=backend, options={"optimization_level": 1}) + with self.assertWarnsRegex(DeprecationWarning, r'.*optimization_level.*'): + _ = estimator.run(**get_primitive_inputs(estimator)) From d081c81dfc58776cefab770879c8f8e9e3649646 Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Thu, 13 Jun 2024 15:48:19 -0400 Subject: [PATCH 2/3] release note --- qiskit_ibm_runtime/estimator.py | 6 +++--- release-notes/unreleased/1748.deprecation.rst | 2 ++ test/unit/test_estimator_options.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 release-notes/unreleased/1748.deprecation.rst diff --git a/qiskit_ibm_runtime/estimator.py b/qiskit_ibm_runtime/estimator.py index 7b9dccd71..beba8539a 100644 --- a/qiskit_ibm_runtime/estimator.py +++ b/qiskit_ibm_runtime/estimator.py @@ -214,9 +214,9 @@ def _validate_options(self, options: dict) -> None: 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/transpile for more information." - ) + "or Qiskit transpiler service. " + "See https://docs.quantum.ibm.com/transpile for more information.", + ) @classmethod def _program_id(cls) -> str: diff --git a/release-notes/unreleased/1748.deprecation.rst b/release-notes/unreleased/1748.deprecation.rst new file mode 100644 index 000000000..72eab69f8 --- /dev/null +++ b/release-notes/unreleased/1748.deprecation.rst @@ -0,0 +1,2 @@ +The ``optimization_level`` option in ``EstimatorV2`` is deprecated. +Instead, you can perform circuit optimization using the Qiskit transpiler or Qiskit transpiler service. \ No newline at end of file diff --git a/test/unit/test_estimator_options.py b/test/unit/test_estimator_options.py index 11f8d78ee..0750a1e08 100644 --- a/test/unit/test_estimator_options.py +++ b/test/unit/test_estimator_options.py @@ -256,5 +256,5 @@ def test_optimization_level_deprecation(self): """Test optimization level being deprecated.""" backend = get_mocked_backend() estimator = Estimator(backend=backend, options={"optimization_level": 1}) - with self.assertWarnsRegex(DeprecationWarning, r'.*optimization_level.*'): + with self.assertWarnsRegex(DeprecationWarning, r".*optimization_level.*"): _ = estimator.run(**get_primitive_inputs(estimator)) From 911b89202840c3bdbe21ac6369a82d0e973d5dc1 Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Thu, 13 Jun 2024 16:41:44 -0400 Subject: [PATCH 3/3] fix logic --- qiskit_ibm_runtime/estimator.py | 2 +- test/unit/test_local_mode.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qiskit_ibm_runtime/estimator.py b/qiskit_ibm_runtime/estimator.py index beba8539a..50e15b562 100644 --- a/qiskit_ibm_runtime/estimator.py +++ b/qiskit_ibm_runtime/estimator.py @@ -209,7 +209,7 @@ def _validate_options(self, options: dict) -> None: "a coupling map is required." ) - if "optimization_level" in options: + if options.get("optimization_level", None): issue_deprecation_msg( msg="The 'optimization_level' option is deprecated", version="0.25.0", diff --git a/test/unit/test_local_mode.py b/test/unit/test_local_mode.py index c517b923c..a3302f4bf 100644 --- a/test/unit/test_local_mode.py +++ b/test/unit/test_local_mode.py @@ -185,7 +185,7 @@ def test_v2_estimator_with_accepted_options(self, backend): primitive=[SamplerV2, EstimatorV2], backend=[FakeManila(), FakeManilaV2(), AerSimulator()] ) def test_primitive_v2_with_not_accepted_options(self, primitive, backend): - """Test V1 primitive with accepted options.""" + """Test V2 primitive with not accepted options.""" options = { "max_execution_time": 200, "dynamical_decoupling": {"enable": True},