Skip to content

Commit

Permalink
Suppress zero div warning in curve analysis (#1098)
Browse files Browse the repository at this point in the history
### Summary

This PR suppresses runtime warning for zero dive error in curve
analysis. Such data points are safely managed by LMFIT so user doesn't
need to take care of it. This PR makes standard error cleaner.

Fix #1087 

### Details and comments

---------

Co-authored-by: Helena Zhang <Helena.Zhang@ibm.com>
  • Loading branch information
nkanazawa1989 and coruscating authored Mar 22, 2023
1 parent 2a556ab commit 116689d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion qiskit_experiments/curve_analysis/curve_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,15 @@ def _objective(_params):
ys = []
for model in models:
sub_data = curve_data.get_subset_of(model._name)
with np.errstate(divide="ignore"):
# Ignore numpy runtime warning.
# Zero y_err point introduces infinite weight,
# but this should be managed by LMFIT.
weights = 1.0 / sub_data.y_err if valid_uncertainty else None
yi = model._residual(
params=_params,
data=sub_data.y,
weights=1.0 / sub_data.y_err if valid_uncertainty else None,
weights=weights,
x=sub_data.x,
)
ys.append(yi)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
other:
- |
NumPy runtime warning for zero division is suppressed in :class:`.CurveAnalysis`.
This warning could occur in the edge case where the experiment data
may contain data point with zero uncertainty.
Such data point is safely ignored by LMFIT, since it may apply infinite fit weight.
This runtime warning suppression makes standard error cleaner.

0 comments on commit 116689d

Please sign in to comment.