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

Fix guess.rb_decay not to raise an error against bad output #1336

Merged
merged 3 commits into from
Jan 17, 2024

Conversation

itoko
Copy link
Contributor

@itoko itoko commented Dec 4, 2023

Summary

Fixed a bug in guess.rb_decay where it unintentionally raises an error if all y values are below the b value (that can happen in experiments on real devices).

Details and comments

Changed to return 0 as the initial guess of the decay parameter when all y values are below the b value, instead of raising an IndexError like

File "/qiskit-experiments/qiskit_experiments/curve_analysis/guess.py", line 406, in rb_decay
    return ((y[0] - b) / a) ** (1 / x[0])
IndexError: index 0 is out of bounds for axis 0 with size 0

An alternative solution might be explicitly raising a QiskitError. But, if we want to raise an error for too bad data to fit, I think the fitter (not rb_decay) should raise an error because it should not be due to the failure of guessing initial parameter (that is the object of rb_decay function.

@itoko itoko added backport stable potential The issue or PR might be minimal and/or import enough to backport to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Dec 5, 2023
Copy link
Collaborator

@coruscating coruscating left a comment

Choose a reason for hiding this comment

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

This looks reasonable to me. @nkanazawa1989 are you okay with merging?

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

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

LGTM. One minor suggestion to the unittest :)

test/curve_analysis/test_guess.py Outdated Show resolved Hide resolved
@nkanazawa1989 nkanazawa1989 added this pull request to the merge queue Jan 17, 2024
Merged via the queue into qiskit-community:main with commit 0937bb4 Jan 17, 2024
11 checks passed
mergify bot pushed a commit that referenced this pull request Jan 17, 2024
### Summary
Fixed a bug in `guess.rb_decay` where it unintentionally raises an error
if all y values are below the b value (that can happen in experiments on
real devices).

### Details and comments
Changed to return `0` as the initial guess of the decay parameter when
all y values are below the b value, instead of raising an IndexError
like
```
File "/qiskit-experiments/qiskit_experiments/curve_analysis/guess.py", line 406, in rb_decay
    return ((y[0] - b) / a) ** (1 / x[0])
IndexError: index 0 is out of bounds for axis 0 with size 0
```

An alternative solution might be explicitly raising a QiskitError. But,
if we want to raise an error for too bad data to fit, I think the fitter
(not rb_decay) should raise an error because it should not be due to the
failure of guessing initial parameter (that is the object of `rb_decay`
function.

---------

Co-authored-by: Naoki Kanazawa <[email protected]>
(cherry picked from commit 0937bb4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport stable potential The issue or PR might be minimal and/or import enough to backport to stable Changelog: Bugfix Include in the "Fixed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants