NLopt.jl icon indicating copy to clipboard operation
NLopt.jl copied to clipboard

algorithm-specific parameters structure empty

Open gvnwst opened this issue 2 years ago • 1 comments

When defining an Opt object using, for example, the MMA algorithm the parameters structure is empty. I would think the correct behavior is to populate with the default values for each parameter available to that algorithm.

using NLopt 
opt = Opt(:LD_MMA, 10)
opt.params

> NLopt.OptParams()

Additionally querying for example haskey(opt.params, "inner_maxeval") returns false. Since this calls the C function nlopt_has_param I'd expect it to return true because the MMA algorithm supports the inner_maxeval parameter (according to the relevant PR). I can imagine this is extra confusing without knowing the available parameters ahead of time. Is there a list of internal parameters for each algorithm? I didn't see it in the NLopt generic documentation.

Setting some value with setindex!(opt.params, <value>, <parameter name>) works and populates the dict, but allows any string as a parameter name -- not just those which would be allowed by that algorithm.

Related to this, what is the purpose for requiring a default value to be passed to get()? I find it confusing that the "default value" passed as an argument is returned. How can you use that function to query the current value?

gvnwst avatar Jul 19 '23 16:07 gvnwst

NLopt doesn't currently export a global list of the algorithms and any parameters that they allow and their defaults. The only way to check optional parameters for a given algorithm is currently to look up that algorithm in the NLopt manual.

So this would need to be changed in the underlying C library first.

(get allows a default value in order to conform to the generic AbstractDict interface.)

stevengj avatar Jul 19 '23 17:07 stevengj

Closing because this isn't possible to achieve in NLopt.jl. We can revisit if a future version of NLopt supports this.

It will also work by default if the C library starts reporting nlopt_has_param as true for the default parameters, so we probably don't even need to do anything here.

odow avatar Aug 19 '24 05:08 odow