From 116689dddf2b22ede59f774482e0b6f570ed33c7 Mon Sep 17 00:00:00 2001 From: Naoki Kanazawa Date: Wed, 22 Mar 2023 12:28:15 +0900 Subject: [PATCH] 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 --- qiskit_experiments/curve_analysis/curve_analysis.py | 7 ++++++- .../notes/suppress-runtime-warning-a741dc96f6a0ce7a.yaml | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/suppress-runtime-warning-a741dc96f6a0ce7a.yaml diff --git a/qiskit_experiments/curve_analysis/curve_analysis.py b/qiskit_experiments/curve_analysis/curve_analysis.py index bce1fc1866..41f46244de 100644 --- a/qiskit_experiments/curve_analysis/curve_analysis.py +++ b/qiskit_experiments/curve_analysis/curve_analysis.py @@ -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) diff --git a/releasenotes/notes/suppress-runtime-warning-a741dc96f6a0ce7a.yaml b/releasenotes/notes/suppress-runtime-warning-a741dc96f6a0ce7a.yaml new file mode 100644 index 0000000000..102f5bfcd4 --- /dev/null +++ b/releasenotes/notes/suppress-runtime-warning-a741dc96f6a0ce7a.yaml @@ -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.