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

Throw a helpful error for begin...end in NL macros #2463

Merged
merged 1 commit into from
Feb 18, 2021
Merged

Conversation

odow
Copy link
Member

@odow odow commented Feb 14, 2021

Closes #2448

I didn't realize that things like this worked in @objective:

julia> using JuMP

julia> model = Model();

julia> @variable(model, x);

julia> @objective(model, Min, begin
           y = 2 * x
           z = y + 1
           2 * z + 2
       end)
4 x + 4

But we can't make this work in general for nonlinear expressions, so I've opted to just make it a more informative error:

julia> using JuMP

julia> model = Model();

julia> @variable(model, x);

julia> @NLexpression(model, begin sin(x) + 1 end)
ERROR: LoadError: `begin...end` blocks are not supported in nonlinear macros. The nonlinear expression must be a single statement.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] _parse_NL_expr(::Symbol, ::Expr, ::Symbol, ::Int64, ::Symbol) at /Users/oscar/.julia/dev/JuMP/src/parse_nlp.jl:23
 [3] _process_NL_expr(::Symbol, ::Expr) at /Users/oscar/.julia/dev/JuMP/src/parse_nlp.jl:257
 [4] @NLexpression(::LineNumberNode, ::Module, ::Vararg{Any,N} where N) at /Users/oscar/.julia/dev/JuMP/src/macros.jl:1619
in expression starting at REPL[5]:1

@codecov
Copy link

codecov bot commented Feb 14, 2021

Codecov Report

Merging #2463 (e6b6584) into master (c432f66) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2463      +/-   ##
==========================================
- Coverage   92.23%   92.19%   -0.05%     
==========================================
  Files          43       43              
  Lines        4652     4626      -26     
==========================================
- Hits         4291     4265      -26     
  Misses        361      361              
Impacted Files Coverage Δ
src/parse_nlp.jl 95.10% <100.00%> (+4.65%) ⬆️
src/Containers/no_duplicate_dict.jl 92.85% <0.00%> (-7.15%) ⬇️
src/Containers/vectorized_product_iterator.jl 40.00% <0.00%> (-6.67%) ⬇️
src/Containers/SparseAxisArray.jl 80.26% <0.00%> (-3.95%) ⬇️
src/Containers/DenseAxisArray.jl 74.81% <0.00%> (-2.97%) ⬇️
src/Containers/generate_container.jl 81.48% <0.00%> (-0.67%) ⬇️
src/print.jl 90.71% <0.00%> (-0.31%) ⬇️
src/macros.jl 92.43% <0.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c432f66...e6b6584. Read the comment docs.

@odow odow merged commit 4d4854b into master Feb 18, 2021
@odow odow deleted the od/nl_macro branch February 18, 2021 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistance between @NLobjective and @objective
1 participant