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

Strange conflict when importing Measurements.jl and BlackBoxOptim.jl in the same program

Open Boxylmer opened this issue 4 years ago • 8 comments

I've been working on optimizing some values that have uncertainties associated with them in Measurements. I wanted to use BlackBoxOptim for this purpose but I'm getting some strange behavior by the Julia compiler (using 1.6.0, and to my knowledge this is also the case in earlier versions (1.5.x) too).

Here's a MWE (ignore the variable names, this was taken from me and a few people over at the Humans of Julia Discord server messing around with the actual project)

using BlackBoxOptim
# using Measurements  # uncomment this after confirming it runs correctly
function solve_volume_uncertainty_bbox(p_uncertainty, v_value, t)
    function target_function(volume_uncertainty_guess_l_mol)
        resulting_pressure = 4
        return (resulting_pressure - p_uncertainty)^2
    end
    res = bboptimize(target_function; SearchRange=(0.0, 10.0), NumDimensions=1, Method=:de_rand_1_bin)  
    return best_candidate(res)[1]
end

bbox = solve_volume_uncertainty_bbox(0.1, 20.08405, 273.15)
println(bbox)

When running without Measurements imported, the program runs fine. If it is imported, however, we get a nasty stackoverflow error, seemingly from the compiler. This error continues to spam your terminal for a bit before it returns the correctly solved value. A formal exception is not actually thrown in the Julia runtime.

I've spoken to the developer of Measurements in JuliaPhysics/Measurements.jl#100 and they narrowed the issue down in a Measurements operation involving logarithms, namely this snippet of code, by cutting things out until including the using Measurements worked without issue:

https://github.com/JuliaPhysics/Measurements.jl/blob/e71f5203ee70fd66057d349855b604db126d4a55/src/math.jl#L619-L622

Would anyone know what exactly is going on here? Note that in the MWE there are no measurement types being created, and the library isn't even being used at all. I would be absolutely thrilled to see compatibility between these two libraries as optimizing uncertainty in iterative functions would be awesome in some of the projects we do in polymer research!

Boxylmer avatar Apr 06 '21 00:04 Boxylmer

Hmm, this is very strange. No clue what can be causing this. I grepped uses of log in BlackBoxOptim and there are quite a few uses but no redefinition or similar. Will investigate more but not really sure where to start and haven't been using Measurements myself. I assume you have tried this also on master (add BlackBoxOptim#master) since there are conflicts with other packages on latest release?

robertfeldt avatar Apr 06 '21 07:04 robertfeldt

@robertfeldt Sorry for the delay in response! I'm a bit new to Github issues and haven't made the habit of checking frequently.

Were you able to fully replicate the issue? I'm a bit new to Julia and wasn't aware of that convenience to switching branches like that. So I just took a shot at both (with and without using Measurements) and didn't get the issue in the latter case!

Boxylmer avatar Apr 09 '21 14:04 Boxylmer

No worries.

I'm running on master branch and couldn't replicate. But the only real change between latest release and master is the dependencies on other packages so that none of us can replicate on master indicates to me that the issue is really in some other package. And likely in an older version of some package. Ok, I'll explore some more but likely this "bug" should go away with a new release.

robertfeldt avatar Apr 09 '21 15:04 robertfeldt

But the only real change between latest release and master is the dependencies on other packages

I'm not sure git history agrees: https://github.com/robertfeldt/BlackBoxOptim.jl/compare/v0.5.0...83c8116

giordano avatar Apr 09 '21 15:04 giordano

Point taken, I expressed myself badly. I was thinking of recent commits; could actually be nice to see if the problem reported in this thread was introduced by any of the commits prior to these recent ones. But yes, a new release a really overdue.

robertfeldt avatar Apr 09 '21 15:04 robertfeldt

Hmm, I just removed BBO and Measurements and reinstalled them both on 1.6 (BBO on master) and then I can replicate this problem. Ok, so back to the debug stage 1 again... ;)

robertfeldt avatar Apr 09 '21 15:04 robertfeldt

Any updates on this? I'd really love to see compatibility between the two libraries as I've wanted to try out BorgMOEA in my project that also uses Measurement uncertainties! (We strip them from the values going in, but just having the two libraries in the same file causes problems)

Boxylmer avatar Jun 18 '21 03:06 Boxylmer

Yeah, I'm not really sure how to start debugging this. I guess we'll have to try excluding files, one by one, and seeing when/if the problem disappears. But likely it is not on a file level and the dependencies might be hard to handle. But yes I can replicate this and the problem remains on Julia 1.6.1 with recent versions of the two packages. Ideas on how to debug this are welcome.

robertfeldt avatar Jun 18 '21 06:06 robertfeldt