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.