Skip to content

Commit

Permalink
Small bugfix in resilience validation (#1632)
Browse files Browse the repository at this point in the history
* Fixed a bug in resilience options checking

* Linting

* linting

---------

Co-authored-by: Kevin Tian <kevin.tian@ibm.com>
  • Loading branch information
gadial and kt474 committed Apr 24, 2024
1 parent bcba30a commit e0b0733
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions qiskit_ibm_runtime/options/resilience_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ class ResilienceOptionsV2:
@model_validator(mode="after")
def _validate_options(self) -> "ResilienceOptionsV2":
"""Validate the model."""
if not self.measure_mitigation and any(asdict(self.measure_noise_learning).values()):
if not self.measure_mitigation and any(
value != Unset for value in asdict(self.measure_noise_learning).values()
):
raise ValueError(
"'measure_noise_learning' options are set, but 'measure_mitigation' is not set to True."
)

if not self.zne_mitigation and any(asdict(self.zne).values()):
if not self.zne_mitigation and any(value != Unset for value in asdict(self.zne).values()):
raise ValueError("'zne' options are set, but 'zne_mitigation' is not set to True.")

if not self.pec_mitigation and any(asdict(self.pec).values()):
if not self.pec_mitigation and any(value != Unset for value in asdict(self.pec).values()):
raise ValueError("'pec' options are set, but 'pec_mitigation' is not set to True.")

# Validate not ZNE+PEC
Expand Down
4 changes: 4 additions & 0 deletions test/unit/test_estimator_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class TestEstimatorOptions(IBMTestCase):
{"resilience": {"zne": {"noise_factors": [1, 3, 5]}}},
"'zne' options are set, but 'zne_mitigation' is not set to True",
),
(
{"resilience": {"pec": {"max_overhead": None, "noise_gain": 0}}},
"'pec' options are set, but 'pec_mitigation' is not set to True",
),
)
def test_bad_inputs(self, val):
"""Test invalid inputs."""
Expand Down

0 comments on commit e0b0733

Please sign in to comment.