Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method error during eval #8

Closed
odow opened this issue May 21, 2024 · 4 comments · Fixed by #9
Closed

Method error during eval #8

odow opened this issue May 21, 2024 · 4 comments · Fixed by #9

Comments

@odow
Copy link
Contributor

odow commented May 21, 2024

I assume somewhere that you drop zeros from summations, so then you're left with an empty list of arguments.

Reported on https://discourse.julialang.org/t/jump-maingo-no-method-matching/114514

julia> using JuMP, MAiNGO

julia> model = Model(MAiNGO.Optimizer);

julia> @variable(model, x);

julia> @objective(model, Min, [x, x]' * [x^2, 0])
0.0 + (x * (0)) + (x * (x²))

julia> optimize!(model)
ERROR: MethodError: no method matching +()
String concatenation is performed with * (See also: https://docs.julialang.org/en/v1/manual/strings/#man-concatenation).

Closest candidates are:
  +(::Base.CoreLogging.LogLevel, ::Integer)
   @ Base logging.jl:131
  +(::Bool, ::Complex{Bool})
   @ Base complex.jl:305
  +(::Bool, ::Bool)
   @ Base bool.jl:166
  ...

Stacktrace:
  [1] top-level scope
    @ none:1
  [2] eval
    @ ./boot.jl:385 [inlined]
  [3] eval
    @ ~/.julia/packages/MAiNGO/zVhVL/src/MAiNGO.jl:8 [inlined]
  [4] to_str(expr::Expr, variable_names::Vector{String})
    @ MAiNGO ~/.julia/packages/MAiNGO/zVhVL/src/util.jl:189
  [5] to_str_
    @ ~/.julia/packages/MAiNGO/zVhVL/src/util.jl:137 [inlined]
  [6] (::MAiNGO.var"#7#10"{MAiNGO.var"#to_str_#8"{Vector{String}}})(d::Expr)
    @ MAiNGO ./none:0
  [7] iterate
    @ ./generator.jl:47 [inlined]
  [8] collect_to!(dest::Vector{String}, itr::Base.Generator{Vector{…}, MAiNGO.var"#7#10"{…}}, offs::Int64, st::Int64)
    @ Base ./array.jl:892
  [9] collect_to_with_first!(dest::Vector{String}, v1::String, itr::Base.Generator{Vector{…}, MAiNGO.var"#7#10"{…}}, st::Int64)
    @ Base ./array.jl:870
 [10] collect(itr::Base.Generator{Vector{Any}, MAiNGO.var"#7#10"{MAiNGO.var"#to_str_#8"{Vector{String}}}})
    @ Base ./array.jl:844
 [11] to_str(expr::Expr, variable_names::Vector{String})
    @ MAiNGO ~/.julia/packages/MAiNGO/zVhVL/src/util.jl:213
 [12] to_str_
    @ ~/.julia/packages/MAiNGO/zVhVL/src/util.jl:137 [inlined]
 [13] (::MAiNGO.var"#7#10"{MAiNGO.var"#to_str_#8"{Vector{String}}})(d::Expr)
    @ MAiNGO ./none:0
 [14] iterate
    @ ./generator.jl:47 [inlined]
 [15] collect_to!(dest::Vector{String}, itr::Base.Generator{Vector{…}, MAiNGO.var"#7#10"{…}}, offs::Int64, st::Int64)
    @ Base ./array.jl:892
 [16] collect_to_with_first!(dest::Vector{String}, v1::String, itr::Base.Generator{Vector{…}, MAiNGO.var"#7#10"{…}}, st::Int64)
    @ Base ./array.jl:870
 [17] collect(itr::Base.Generator{Vector{Any}, MAiNGO.var"#7#10"{MAiNGO.var"#to_str_#8"{Vector{String}}}})
    @ Base ./array.jl:844
 [18] to_str(expr::Expr, variable_names::Vector{String})
    @ MAiNGO ~/.julia/packages/MAiNGO/zVhVL/src/util.jl:213
 [19] write_ALE_problem(m::MAiNGO.MAINGOModel)
    @ MAiNGO ~/.julia/packages/MAiNGO/zVhVL/src/util.jl:370
 [20] optimize!(model::MAiNGO.Optimizer)
    @ MAiNGO ~/.julia/packages/MAiNGO/zVhVL/src/MOI_wrapper.jl:190
 [21] optimize!
    @ ~/.julia/packages/MathOptInterface/2rAFb/src/Bridges/bridge_optimizer.jl:380 [inlined]
 [22] optimize!
    @ ~/.julia/packages/MathOptInterface/2rAFb/src/MathOptInterface.jl:85 [inlined]
 [23] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{…})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/2rAFb/src/Utilities/cachingoptimizer.jl:316
 [24] optimize!(model::Model; ignore_optimize_hook::Bool, _differentiation_backend::MathOptInterface.Nonlinear.SparseReverseMode, kwargs::@Kwargs{})
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/optimizer_interface.jl:457
 [25] optimize!(model::Model)
    @ JuMP ~/.julia/packages/JuMP/Gwn88/src/optimizer_interface.jl:409
 [26] top-level scope
    @ REPL[10]:1
Some type information was truncated. Use `show(err)` to see complete types.
@MAiNGO-github
Copy link
Owner

MAiNGO-github commented May 23, 2024

Thank you for bringing this to our attention.

Unfortunately, this will take some time to figure out.
In my test, the same issue also happens in BARON.jl (we use basically the same way to translate expressions to strings as that package).

Also, I do not think that we are actually responsible for dropping terms.
Using @show on the expression, as it is given to the solver, I got

c = :(0.0 + x[1] * +() + x[1] * +(1.0 * x[1] * x[1]))

So it seems that MathOptInterface is already dropping that term?
Not sure if that is a bug in MathOptInterface or a corner case that is expected, but not covered here and in BARON.jl

@odow
Copy link
Contributor Author

odow commented May 23, 2024

Let me take a look

@odow
Copy link
Contributor Author

odow commented May 23, 2024

This is a bug in MAiNGO, but it is also a bug in BARON. I'll submit a PR with the fix.

@odow
Copy link
Contributor Author

odow commented May 23, 2024

Fixed BARON as well: jump-dev/BARON.jl#81

You should be a bit mindful of the source code in BARON. That part was written in 2019, right near the start of our transition to MathOptInterface. It hadn't had many eyes (or tests) on it over time 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants