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

[Nonlinear] add support for simplifying NonlinearFunction #2605

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

odow
Copy link
Member

@odow odow commented Jan 8, 2025

Heading towards #2553

We have a few choices:

  • To leave this standalone
  • To make this the default for Utilities.canonicalize
  • To use this in isapprox

Not really sure what is a good approach. To be honest, canonicalize!(::ScalarNonlinearFunction) already does more than I remember adding.

@chriscoey
Copy link
Contributor

Nice, this seems very useful

@chriscoey
Copy link
Contributor

If we decide to add more algebraic simplifications in future, they won't be considered breaking right? Definitely looking forward to this!

@odow
Copy link
Member Author

odow commented Jan 14, 2025

Given the various bits I'm having to poke and prod, I'm not sure if this is a good or bad idea to have on by default.

# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

module SymbolicAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this called SymbolicAD ? It's not really doing AD, it's just simplifying

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My plan was to move lanl-ansi/MathOptSymbolicAD.jl#39 into here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense then

function simplify(f::MOI.ScalarQuadraticFunction{T}) where {T}
f = MOI.Utilities.canonical(f)
if isempty(f.quadratic_terms)
return simplify(MOI.ScalarAffineFunction(f.affine_terms, f.constant))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling simplify will canonicalize again, we don't need to do the type unstable part of deciding whether it should be a constant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we just did f = MOI.Utilities.canonical(f) so f.affine_terms are already canonicalized. Here, we create a SAF that we know is canonical and then pass it to simplify. The first thing the function will do is canonicalize again which is a bit wasteful

@odow odow marked this pull request as draft January 16, 2025 03:44
@odow
Copy link
Member Author

odow commented Jan 16, 2025

I went back to making some changes in lanl-ansi/MathOptSymbolicAD.jl#39 for now

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.

3 participants