Skip to content
Advertisement

How to hide `delta_grad == 0.0` warning in scipy.optimize.minimize?

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

  1. Check if this warning has already been displayed, and if so don’t display it again, OR
  2. 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.")
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement