lanl-ansi / Juniper.jl

A JuMP-based Nonlinear Integer Program Solver
https://lanl-ansi.github.io/Juniper.jl/stable/
MIT License
180 stars 22 forks source link

Key not found, even with Juniper registration #189

Closed rabritta closed 4 years ago

rabritta commented 4 years ago

Hello. As seen in the attached print-screen, I am getting a "KeyError: key :ntur not found" error even after registering the function both in the model and in Juniper. Jun

My registration looks like this:

nl_solver= optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0);
mip_solver = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0);
optm = Model(optimizer_with_attributes(Juniper.Optimizer, "nl_solver"=>nl_solver, "mip_solver"=>mip_solver, 
        "allow_almost_solved_integral"=>true,
        "registered_functions"=>[Juniper.register(:ntur, 3, ntur, grad_ntur)]));

register(optm, :ntur, 3, ntur, grad_ntur);

I could not find this issue already posted. Although issue #118 is similar, it was solved by simply registering the function in Juniper, which is not my case. I realized that in #118 the stacktrace [2] is identical to mine:

expr_to_nodedata(::Expr, ::Array{ReverseDiffSparse.NodeData,1}, ::Array{Float64,1}, ::Int64, ::ReverseDiffSparse.UserOperatorRegistry) at conversion.jl:23". However, stacktrace [1] is "getindex at dict.jl:474 [inlined]" whereas mine is "getindex(::Dict{Symbol,Int64}, ::Symbol) at .\dict.jl:477

Any help is appreciated. Regards.

Wikunia commented 4 years ago

Thanks for the bug report. It seemed to slipped through testing. Hope it's fixed now. Would be awesome if you can test it with ] dev https://github.com/lanl-ansi/Juniper.jl and then in .julia/dev/Juniper.jl use git checkout bugfix-registered-functions which should show you v0.6.3 in ] status afterwards. If that works out I'll register the new version. And welcome to GitHub :)

Btw I've changed your issue slightly such that the code is more readable now. You can do this with "````" around your code block.

rabritta commented 4 years ago

Hey @Wikunia! Thanks for welcoming me and for showing me how to make the code more readable. I got the ] dev https://github.com/lanl-ansi/Juniper.jl part just fine but I couldn't figure the rest out. Apologies, I am pretty new to this stuff. I found the bugfix file and did the attempt below, but I believe I am messing things up. image

Wikunia commented 4 years ago

No problem. I might have forgotten some parts: It's easiest to do in a shell but can be done in the REPL or in your notebook as well I believe. Can you try:

; cd C:/Users/Win10/.julia/Juniper/
; git checkout bugfix-registered-functions
] status

; brings you to shell mode. ] status should show Juniper v0.6.3 If that works you can just run your model and it should work fine.

rabritta commented 4 years ago

dev folder was missing, but I am still getting some errors image

Wikunia commented 4 years ago

Can you use a shell outside Julia? I haven't used Windows for quite a while :smile: If you have git installed which I think you need when using Julia checkout should be working. Maybe you can run the commands in the PowerShell? change to the dev/Juniper folder and then run git checkout bugfix-registered-functions

ccoffrin commented 4 years ago

Did you try using this package manager command?

] add Juniper#bugfix-registered-functions
rabritta commented 4 years ago

It seems like using Jupyter notebook instead of Julia directly was a problem indeed. Anyway, @ccoffrin 's command did the trick, as seem in the image below. But I am still getting the "key :ntur not found" error. Stacktrace [1] is still [1] getindex(::Dict{Symbol,Int64}, ::Symbol) at .\dict.jl:477. Let me know if you want me to send you my code.

image

Wikunia commented 4 years ago

Thanks for testing it out. Yes sending the code would be much appreciated. If you don't want to make it public here feel free to send me an email o.kroeger@opensourc.es

rabritta commented 4 years ago

Won't be necessary. I just needed to restart the kernel after the previous steps. It is working fine now :) You guys are awesome

ccoffrin commented 4 years ago

Thanks for the report and glad we could quickly resolve the issue. Kudos to @Wikunia!