Skip to content

Commit

Permalink
Support only LocalFoldingAmplifier as noise_amplifier option (#1093)
Browse files Browse the repository at this point in the history
* Removed support for all noise_amplifier options other than LocalFoldingAmplifier. Removed deprecation warning.

* Removed tests that covered deprecation. Updated documentation

---------

Co-authored-by: Kevin Tian <[email protected]>
  • Loading branch information
merav-aharoni and kt474 authored Oct 11, 2023
1 parent ea5dd82 commit a20fa88
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 57 deletions.
15 changes: 3 additions & 12 deletions docs/how_to/error-mitigation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,8 @@ As a part of the beta release of the resilience options, users will be able conf
+---------------------------------------------------------------+----------------------------------+--------------------------------------------------------+
| Options | Inputs | Description |
+===============================================================+==================================+========================================================+
| options.resilience.noise_amplifier(Optional[str]) | ``TwoQubitAmplifier`` [Default] | Amplifies noise of all two qubit gates by performing |
| | | local gate folding. |
| select your amplification strategy +----------------------------------+--------------------------------------------------------+
| | ``CxAmplifier`` | Amplifies noise of all CNOT gates by performing local |
| | | gate folding. |
| +----------------------------------+--------------------------------------------------------+
| | ``LocalFoldingAmplifier`` | Amplifies noise of all gates by performing local |
| | | gate folding. |
| +----------------------------------+--------------------------------------------------------+
| | ``GlobalFoldingAmplifier`` | Amplifies noise of the input circuit by performing |
| | | global folding of the entire input circuit. |
| options.resilience.noise_amplifier(Optional[str]) | ``LocalFoldingAmplifier`` | Amplifies noise of all gates by performing local |
| (currently only one available option) | | gate folding. |
+---------------------------------------------------------------+----------------------------------+--------------------------------------------------------+
| options.resilience.noise_factors((Optional[Sequence[float]]) | (1, 3, 5) [Default] | Noise amplification factors, where `1` represents the |
| | | baseline noise. They all need to be greater than or |
Expand All @@ -228,7 +219,7 @@ Example of adding ``resilience_options`` into your estimator session
options.optimization_level = 3
options.resilience_level = 2
options.resilience.noise_factors = (1, 2, 3, 4)
options.resilience.noise_amplifier = 'CxAmplifier'
options.resilience.noise_amplifier = 'LocalFoldingAmplifier'
options.resilience.extrapolator = 'QuadraticExtrapolator'
Expand Down
24 changes: 4 additions & 20 deletions qiskit_ibm_runtime/options/resilience_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
from dataclasses import dataclass

from .utils import _flexible
from ..utils.deprecation import issue_deprecation_msg

ResilienceSupportedOptions = Literal[
"noise_amplifier",
"noise_factors",
"extrapolator",
]
NoiseAmplifierType = Literal[
"TwoQubitAmplifier",
"GlobalFoldingAmplifier",
"LocalFoldingAmplifier",
"CxAmplifier",
]
ExtrapolatorType = Literal[
"LinearExtrapolator",
Expand All @@ -48,10 +44,9 @@ class ResilienceOptions:
Only applicable for ``resilience_level=2``.
Default: ``None``, and (1, 3, 5) if resilience level is 2.
noise_amplifier (DEPRECATED): A noise amplification strategy. One of ``"TwoQubitAmplifier"``,
``"GlobalFoldingAmplifier"``, ``"LocalFoldingAmplifier"``, ``"CxAmplifier"``.
Only applicable for ``resilience_level=2``.
Default: "TwoQubitAmplifier".
noise_amplifier (DEPRECATED): A noise amplification strategy. Currently only
``"LocalFoldingAmplifier"`` is supported Only applicable for ``resilience_level=2``.
Default: "LocalFoldingAmplifier".
extrapolator: An extrapolation strategy. One of ``"LinearExtrapolator"``,
``"QuadraticExtrapolator"``, ``"CubicExtrapolator"``, ``"QuarticExtrapolator"``.
Expand All @@ -75,21 +70,10 @@ def validate_resilience_options(resilience_options: dict) -> None:
ValueError: if extrapolator == "QuarticExtrapolator" and number of noise_factors < 5.
ValueError: if extrapolator == "CubicExtrapolator" and number of noise_factors < 4.
"""
if resilience_options.get("noise_amplifier", None) is not None:
issue_deprecation_msg(
msg="The 'noise_amplifier' resilience option is deprecated",
version="0.12.0",
period="1 month",
remedy="After the deprecation period, only local folding amplification "
"will be supported. "
"Refer to https://github.com/qiskit-community/prototype-zne "
"for global folding amplification in ZNE.",
)

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") or "TwoQubitAmplifier"
noise_amplifier = resilience_options.get("noise_amplifier") or "LocalFoldingAmplifier"
if noise_amplifier not in get_args(NoiseAmplifierType):
raise ValueError(
f"Unsupported value {noise_amplifier} for noise_amplifier. "
Expand Down
26 changes: 1 addition & 25 deletions test/unit/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@

"""Tests for estimator class."""

import warnings

from qiskit import QuantumCircuit
from qiskit.quantum_info import SparsePauliOp

from qiskit_ibm_runtime import Estimator, Session, Options
from qiskit_ibm_runtime import Estimator, Session

from ..ibm_test_case import IBMTestCase
from ..utils import get_mocked_backend
from .mock.fake_runtime_service import FakeRuntimeService


Expand All @@ -47,25 +45,3 @@ def test_unsupported_values_for_estimator_options(self):
with self.assertRaises(ValueError) as exc:
_ = inst.run(self.circuit, observables=self.observables, **bad_opt)
self.assertIn(list(bad_opt.keys())[0], str(exc.exception))

def test_deprecated_noise_amplifier(self):
"""Test noise_amplifier deprecation."""
opt = Options()
opt.resilience.noise_amplifier = "GlobalFoldingAmplifier"

with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter("always")
estimator = Estimator(backend=get_mocked_backend(), options=opt)
estimator.run(self.circuit, self.observables)
self.assertEqual(len(warn), 1, "Deprecation warning not found.")
self.assertIn("noise_amplifier", str(warn[-1].message))

def test_deprecated_noise_amplifier_run(self):
"""Test noise_amplifier deprecation in run."""

with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter("always")
estimator = Estimator(backend=get_mocked_backend())
estimator.run(self.circuit, self.observables, noise_amplifier="GlobalFoldingAmplifier")
self.assertEqual(len(warn), 1, "Deprecation warning not found.")
self.assertIn("noise_amplifier", str(warn[-1].message))

0 comments on commit a20fa88

Please sign in to comment.