Steven G. Johnson <stevenj.mit@...> writes:

> > 
> > Traceback (most recent call last):
> >  File "./toy_all_nlopt.py", line 42, in <module>
> >    variables_values = opt.optimize(numpy.array([0]*36, dtype=numpy.double))
> >  File "/Library/Python/2.7/site-packages/nlopt.py", line 254, in optimize
> >    def optimize(self, *args): return _nlopt.opt_optimize(self, *args)
> > TypeError: <lambda>() takes exactly 1 argument (2 given)
> 
> You don't provide your code, but I would guess that the error 
message means that you either passed 2
> arguments when 1 was expected or you declared your objective 
function with 1 argument when it is 
supposed
> to take 2 arguments.
> 
> 


Hi Steven, thanks for the quick reply!
Sorry for not providing more code, I didn't know what to include.

I haven't (as far as I know) passed 2 arguments anywhere.

Simplifying a little, my code goes like this:


opt = nlopt.opt(nlopt.LN_COBYLA, 36)

def objective(x, grad):
   if grad.size > 0:
       raise NotImplemented('Gradient requested')
   return 1.0 #actually some arithmetic (+/*) over x[i]'s, 
              #but I get the same error with just 1.0

opt.set_max_objective(objective)

# some constraints like:
opt.add_equality_constraint(lambda x: x[25] - 1)
# [...]

variables_values = opt.optimize(numpy.array([0]*36, dtype=numpy.double))


Any suggestion?


_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to