You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug description
When I use a recent version of Scipy (versions 1.5.0 or later), I cannot set an equality constraint in the SLSQP yaw optimization functions successfully. It seems that the optimization attempts to calculate a gradient for the equality-constrained turbines, thereby dividing some value by 0 and exiting the optimization without success after the first iteration.
To Reproduce
The following is a minimal example that reproduces the issue for me:
import os
import numpy as np
import floris.tools as wfct
from floris.tools.optimization.scipy.yaw import YawOptimization
# Instantiate the FLORIS object
file_dir = os.path.dirname(os.path.abspath(__file__))
fi = wfct.floris_interface.FlorisInterface(
os.path.join(file_dir, "../../../example_input.json")
)
# Set turbine locations to 3 turbines in a row
D = fi.floris.farm.turbines[0].rotor_diameter
layout_x = [0, 7 * D, 14 * D]
layout_y = [0, 0, 0]
fi.reinitialize_flow_field(layout_array=(layout_x, layout_y))
# Optimize yaw under bounds
yaw_opt = YawOptimization(fi, bnds=[(0., 25.), (0., 25.), (0., 0.)])
yaw_angles = yaw_opt.optimize()
Expected behavior
The correct behavior is, when using scipy<1.5.0:
Screenshots, if applicable
This is the error that is reported:
=====================================================
Optimizing wake redirection control...
Number of parameters to optimize = 3
=====================================================
/home/bdoekeme/.python_environments/.floris/lib/python3.8/site-packages/scipy/optimize/_numdiff.py:519: RuntimeWarning: invalid value encountered in true_divide
J_transposed[i] = df / dx
NIT FC OBJFUN GNORM
1 4 -1.000000E+00 NAN
Inequality constraints incompatible (Exit mode 4)
Current function value: -1.0
Iterations: 1
Function evaluations: 4
Gradient evaluations: 1
No change in controls suggested for this inflow condition...
Floris Version
v2.3 (main branch as of to date)
System Information (please complete the following information):
OS: Ubuntu 18.04 LTS through WSL 1 on a Windows 10 (20H2) machine
Library versions
numpy=1.19.5
pytest=6.2.2
scipy=1.6.0
Additional context
A potential future-proof solution to this would be to condition what goes into the scipy.optimize.minimize function. Namely, the yaw optimization code could take the user-specified bounds on the floris-side, then determine what turbines have equality constraints, and finally only optimize for the remaining non-equality-constrained turbines. That way, we would present the user with the right value for the number of variables optimized (in this example, it reports 3 but it should be 2), and it provides greater freedom in the optimization methods. I haven't worked out the details really, but it could be something as simple as:
Bug description
When I use a recent version of Scipy (versions 1.5.0 or later), I cannot set an equality constraint in the SLSQP yaw optimization functions successfully. It seems that the optimization attempts to calculate a gradient for the equality-constrained turbines, thereby dividing some value by 0 and exiting the optimization without success after the first iteration.
To Reproduce
The following is a minimal example that reproduces the issue for me:
Expected behavior
The correct behavior is, when using scipy<1.5.0:
Screenshots, if applicable
This is the error that is reported:
Floris Version
v2.3 (main branch as of to date)
System Information (please complete the following information):
Additional context
A potential future-proof solution to this would be to condition what goes into the
scipy.optimize.minimize
function. Namely, the yaw optimization code could take the user-specified bounds on the floris-side, then determine what turbines have equality constraints, and finally only optimize for the remaining non-equality-constrained turbines. That way, we would present the user with the right value for the number of variables optimized (in this example, it reports 3 but it should be 2), and it provides greater freedom in the optimization methods. I haven't worked out the details really, but it could be something as simple as:Adding this snippet to
reinitialize_opt(...)
:and then change the cost function to accept a subset of yaw angles, only the ones relevant for optimization:
The text was updated successfully, but these errors were encountered: