Skip to content

Commit 116689d

Browse files
Suppress zero div warning in curve analysis (#1098)
### 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 <[email protected]>
1 parent 2a556ab commit 116689d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

qiskit_experiments/curve_analysis/curve_analysis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,15 @@ def _objective(_params):
322322
ys = []
323323
for model in models:
324324
sub_data = curve_data.get_subset_of(model._name)
325+
with np.errstate(divide="ignore"):
326+
# Ignore numpy runtime warning.
327+
# Zero y_err point introduces infinite weight,
328+
# but this should be managed by LMFIT.
329+
weights = 1.0 / sub_data.y_err if valid_uncertainty else None
325330
yi = model._residual(
326331
params=_params,
327332
data=sub_data.y,
328-
weights=1.0 / sub_data.y_err if valid_uncertainty else None,
333+
weights=weights,
329334
x=sub_data.x,
330335
)
331336
ys.append(yi)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
other:
3+
- |
4+
NumPy runtime warning for zero division is suppressed in :class:`.CurveAnalysis`.
5+
This warning could occur in the edge case where the experiment data
6+
may contain data point with zero uncertainty.
7+
Such data point is safely ignored by LMFIT, since it may apply infinite fit weight.
8+
This runtime warning suppression makes standard error cleaner.

0 commit comments

Comments
 (0)