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

Fix promotion rules for GenericNonlinearExpr #3483

Merged
merged 7 commits into from
Sep 5, 2023

Conversation

odow
Copy link
Member

@odow odow commented Sep 3, 2023

@odow odow changed the title WIP: Fix promotion rules for GenericNonlinearExpr and VectorNonlinearFunction Fix promotion rules for GenericNonlinearExpr and VectorNonlinearFunction Sep 3, 2023
@codecov
Copy link

codecov bot commented Sep 3, 2023

Codecov Report

Patch coverage: 66.66% and project coverage change: -0.06% ⚠️

Comparison is base (7b98ffc) 98.09% compared to head (7002356) 98.04%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3483      +/-   ##
==========================================
- Coverage   98.09%   98.04%   -0.06%     
==========================================
  Files          37       37              
  Lines        5518     5525       +7     
==========================================
+ Hits         5413     5417       +4     
- Misses        105      108       +3     
Files Changed Coverage Δ
src/nlp_expr.jl 99.04% <50.00%> (-0.23%) ⬇️
src/aff_expr.jl 97.34% <100.00%> (+0.02%) ⬆️

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@odow
Copy link
Member Author

odow commented Sep 3, 2023

This fixes the UnitJuMP test failure, although UnitJuMP still commits type piracy.

@odow
Copy link
Member Author

odow commented Sep 4, 2023

It's still possible to generate Vector{AbstractJuMPScalar}:

julia> using JuMP

julia> model = Model();

julia> @variable(model, x);

julia> y = [i == 1 ? x : sin(x) for i in 1:2]
2-element Vector{AbstractJuMPScalar}:
 x
 sin(x)

julia> @objective(model, Min, [i == 1 ? x : sin(x) for i in 1:2])
ERROR: MethodError: no method matching moi_function(::Vector{AbstractJuMPScalar})
Closest candidates are:
  moi_function(::AbstractConstraint) at /Users/oscar/.julia/dev/JuMP/src/constraints.jl:550
  moi_function(::AbstractVariableRef) at /Users/oscar/.julia/dev/JuMP/src/variables.jl:575
  moi_function(::Vector{var"#s65"} where var"#s65"<:AbstractVariableRef) at /Users/oscar/.julia/dev/JuMP/src/variables.jl:584
  ...
Stacktrace:
 [1] set_objective_function(model::Model, func::Vector{AbstractJuMPScalar})
   @ JuMP ~/.julia/dev/JuMP/src/objective.jl:146
 [2] set_objective(model::Model, sense::MathOptInterface.OptimizationSense, func::Vector{AbstractJuMPScalar})
   @ JuMP ~/.julia/dev/JuMP/src/objective.jl:175
 [3] macro expansion
   @ ~/.julia/dev/JuMP/src/macros.jl:1850 [inlined]
 [4] top-level scope
   @ REPL[5]:1

julia> @objective(model, Min, y)
ERROR: MethodError: no method matching moi_function(::Vector{AbstractJuMPScalar})

So perhaps we need a better error for the fallback.

@odow
Copy link
Member Author

odow commented Sep 4, 2023

Thoughts @pulsipher?

@odow
Copy link
Member Author

odow commented Sep 4, 2023

@trulsf fixed UnitJuMP, but I think this is the right thing regardless. We can always add back support for Vector{AbstractJuMPScalar} later.

@odow odow mentioned this pull request Sep 4, 2023
25 tasks
src/nlp_expr.jl Outdated Show resolved Hide resolved
src/nlp_expr.jl Outdated Show resolved Hide resolved
@odow odow changed the title Fix promotion rules for GenericNonlinearExpr and VectorNonlinearFunction Fix promotion rules for GenericNonlinearExpr Sep 5, 2023
@odow odow merged commit f496535 into master Sep 5, 2023
@odow odow deleted the od/promotion-vector-nonlinear branch September 5, 2023 06:57
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.

The Vector{AbstractJuMPScalar} problem
3 participants