Scipy error using optimization module. Error converting array to fortran

Trying to use the scipy optimize module to find the minimum of a function using slsqp, and I am encountering some problems. The actual code calling the function is shown below:

def minimizeWebEnergyLost(x, parameters): """values = [theta, velocity]""" firstTerm = lambda values: (x * values[1]**2 / 2.0) sqrtTerm = lambda values: np.sqrt((parameters.gravity**2 * x**2) / (4 * values[1]**4 * np.cos(values[0])**4) + 1) secondTerm = lambda values: (values[1]**4 * np.cos(values[0])**2) / parameters.gravity arcsinhTerm = lambda values: np.arcsinh((parameters.gravity * x) / (2 * values[1]**2 * np.cos(values[0])**2)) costFunction = lambda values: firstTerm(values)*sqrtTerm(values)+secondTerm(values)*arcsinhTerm(values) bounds = ((-math.pi/2,math.pi/2),(0,parameters.maxSlingSpeed)) minimum = minimize(costFunction, (pi/4, 20), method="SLSQP", bounds=bounds) return minimum 

For some reason, the error I am getting is as follows:

 _slsqp.error: failed in converting 8th argument `g' of _slsqp.slsqp to C/Fortran array 

Not quite sure what is happening in hre, but I can send any code that might be useful if that helps.

+7
source share
1 answer

This critical error occurs when a custom objective function does not return a scalar. The explicit error message is now returned in the b-carter patch,

 "Objective function must return a scalar" 

and the documentation is updated, see this thread for discussion.

0
source

All Articles