bbopt / NOMAD.jl

Julia interface to the NOMAD blackbox optimization software
Other
47 stars 6 forks source link

Getting Inexact Errors from NOMAD.jl when tuning Integer and Boolean variables #48

Open MonssafToukal opened 2 years ago

MonssafToukal commented 2 years ago

I sometimes obtain the following error when using integer and boolean inputs. From my perspective, it seems to happen randomly, but I am not sure. I will sometimes rerun NOMAD.jl and I won't get an error. Here is a recent stacktrace:

ERROR: LoadError: InexactError: Bool(1.00000000000003)                                                         [29/1822]Stacktrace:                                                                                                               [1] Bool                                                                                                                  @ ./float.jl:106 [inlined]                                                                                            [2] convert                                                                                                               @ ./number.jl:7 [inlined]                                                                                             [3] set_default!(parameter::AlgorithmicParameter{Bool, BinaryRange{Bool}}, new_value::Float64)
    @ Main ~/ParameterTuningInterface/src/parameters.jl:38
  [4] (::var"#14#17")(::Tuple{AlgorithmicParameter{Bool, BinaryRange{Bool}}, Float64})
    @ Main ./none:0
  [5] iterate
    @ ./generator.jl:47 [inlined]
  [6] collect_to!(dest::Vector{Real}, itr::Base.Generator{Base.Iterators.Zip{Tuple{Vector{AlgorithmicParameter}, Vector{Float64}}}, var"#14#17"}, offs::Int64, st::Tuple{Int64, Int64})
    @ Base ./array.jl:724
  [7] collect_to!(dest::Vector{Int64}, itr::Base.Generator{Base.Iterators.Zip{Tuple{Vector{AlgorithmicParameter}, Vector{Float64}}}, var"#14#17"}, offs::Int64, st::Tuple{Int64, Int64})
    @ Base ./array.jl:732
  [8] collect_to_with_first!(dest::Vector{Int64}, v1::Int64, itr::Base.Generator{Base.Iterators.Zip{Tuple{Vector{AlgorithmicParameter}, Vector{Float64}}}, var"#14#17"}, st::Tuple{Int64, Int64})
    @ Base ./array.jl:702
  [9] collect(itr::Base.Generator{Base.Iterators.Zip{Tuple{Vector{AlgorithmicParameter}, Vector{Float64}}}, var"#14#17"})
    @ Base ./array.jl:683
 [10] obj
    @ ~/ParameterTuningInterface/src/parameters.jl:103 [inlined]
 [11] obj
    @ ~/ParameterTuningInterface/src/parameters.jl:103 [inlined]

To fix the issue, I had to do a convert(Bool, round(Int64, value)).

Any ideas? I am curious why it seems to happen arbitrarily.

salomonl commented 2 years ago

@MonssafToukal Could you provide a simple blackbox example ?

amontoison commented 2 years ago

@MonssafToukal Is it the output of the blackbox 1.00000000000003 ? Did you specify that it's a Boolean variable in NOMAD.jl ?

tmigot commented 2 years ago

Hey @salomonl and @amontoison I don't think there is something about specifying integer or boolean in the documentation that would be really a great add-on if that's possible with Nomad.jl!

salomonl commented 2 years ago

https://bbopt.github.io/NOMAD.jl/dev/nomadProblem/ : see input_types.

But yes, we should precise that all inputs of a blackbox for Nomad will be considered as Float64 ( for example, x1 = true => x1 = 1). It is a convention of the C++ interface, which makes it easy to implement different types.

MonssafToukal commented 2 years ago

Hi @salomonl ! Sorry for the late reply. Indeed, the input_types for my boolean and my integer variables are respectively "B"and "I" as mentioned in the documentation. I will try to reproduce the error with a simple program.