I have a loop that executes several hundred optimizations using scipy.optimize.minimize. Unfortunately, I keep getting this annoying warning:
C:UsersLeonidasAnaconda3libsite-packagesscipyoptimize_hessian_update_strategy.py:186: UserWarning: delta_grad == 0.0. Check if the approximated function is linear. If the function is linear better results can be obtained by defining the Hessian as zero instead of using quasi-Newton approximations. 'approximations.', UserWarning)
Because I am running hundreds of optimizations, this warning shows up dozens and dozens of times during the loop, and it just clutters the console and obscures the rest of my program’s output. Is there a way to either
- Check if this warning has already been displayed, and if so don’t display it again, OR
- Completely suppress the warning altogether?
Advertisement
Answer
If you want to suppress the specific warning, you can add following at the beginning of your script:
import warnings warnings.filterwarnings("ignore", message="delta_grad == 0.0. Check if the approximated function is linear.")