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

Add support for min and max operators in GenericNonlinearExpr #3509

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

odow
Copy link
Member

@odow odow commented Sep 14, 2023

Closes #3508

@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (0c53e0b) 98.14% compared to head (6f3468e) 98.14%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3509   +/-   ##
=======================================
  Coverage   98.14%   98.14%           
=======================================
  Files          37       37           
  Lines        5545     5545           
=======================================
  Hits         5442     5442           
  Misses        103      103           
Files Changed Coverage Δ
src/nlp_expr.jl 99.51% <ø> (ø)

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

@odow odow merged commit beb1826 into master Sep 14, 2023
@odow odow deleted the od/min-max branch September 14, 2023 20:35
@davidanthoff
Copy link
Contributor

Wow, that was fast, thanks a lot :)

@odow
Copy link
Member Author

odow commented Sep 14, 2023

I'm about to tag v1.15, so I wanted it in

@davidanthoff
Copy link
Contributor

@odow I just ran into a corner case that is not yet handled by this PR: min and max can also be called with just one argument, and the current implementation doesn't solve that.

For now I can work around this by adding

# TODO Remove this once this is fixed in JuMP
function Base.min(x::JuMP.AbstractJuMPScalar)
    JuMP._throw_if_not_real(x)
    return JuMP.GenericNonlinearExpr{JuMP.variable_ref_type(x)}(:min, x)
end

to our own codebase, but I think this should really live here in JuMP. I would add a PR, but not entirely sure how you want to handle this kind of thing as you seem to use macros a bit to add these permutations, right?

@odow
Copy link
Member Author

odow commented Sep 22, 2023

Argh. Why would min and max be unary methods 😢 Let me take a look

@davidanthoff
Copy link
Contributor

Yeah, in MPSGE.jl we ran into this case because these expressions get auto-generated. We could work around it on our end, but given that Base.min and Base.max accept one arg as well, it seems better to fix here, right?

@odow
Copy link
Member Author

odow commented Sep 22, 2023

I think this is better

Base.min(x::JuMP.AbstractJuMPScalar) = x
Base.max(x::JuMP.AbstractJuMPScalar) = x

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.

New nonlinear expression stuff doesn't support min properly
2 participants