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

Support only LocalFoldingAmplifier as noise_amplifier option #1093

Merged
merged 8 commits into from
Oct 11, 2023
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'
kt474 marked this conversation as resolved.
Show resolved Hide resolved
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".
Comment on lines +47 to +49
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really need an option if there is only 1 choice. And it shouldn't be marked as DEPRECATED without a deprecation warning.

Copy link
Contributor Author

@merav-aharoni merav-aharoni Oct 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jyu00 - Indeed the DEPRECATED should have been removed.
At the time, we left noise_amplifier as an option because it can be None, for resilience level lower than 2. Do you think we should remove it entirely, assuming the server knows to set it correctly? Or else keep as an option with just one choice that is hard coded?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merav-aharoni Well from UX perspective, we should remove it. However, you are correct that it looks like the server side primitive would blow up if it's not passed in 😞. We can remove it after it's fixed on the server side.


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))
Loading