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 new submodule #1804

Merged
merged 15 commits into from
Apr 25, 2022
Merged

[Nonlinear] add new submodule #1804

merged 15 commits into from
Apr 25, 2022

Conversation

odow
Copy link
Member

@odow odow commented Apr 19, 2022

At attempt to make #1803 more reviewable.

TODO before merging:

  • Relicensing
    • @amontoison

@odow odow force-pushed the od/nonlinear-api branch from e671887 to 406e190 Compare April 19, 2022 23:48
@odow odow changed the title RFC: add [Nonlinear] submodule RFC: add [Nonlinear.ReverseAD] submodule Apr 19, 2022
@odow odow changed the title RFC: add [Nonlinear.ReverseAD] submodule RFC: add [Nonlinear] submodule Apr 19, 2022
@odow odow added the Project: next-gen nonlinear support Issues relating to nonlinear support label Apr 19, 2022
@odow odow mentioned this pull request Apr 19, 2022
3 tasks
@odow
Copy link
Member Author

odow commented Apr 20, 2022

I discussed this with @matbesancon, and we decided that that easiest way forward is to make a new NonlinearOptInterface package, to merge this code into that, and then for JuMP to (temporarily) depend upon NonlinearOptInterface.jl.

That lets us break things at will, and we can make small PRs without having to manage this stack (GitHub should make it easier to manage stacked PRs).

@mlubin
Copy link
Member

mlubin commented Apr 20, 2022

I discussed this with @matbesancon, and we decided that that easiest way forward is to make a new NonlinearOptInterface package, to merge this code into that, and then for JuMP to (temporarily) depend upon NonlinearOptInterface.jl.

That lets us break things at will, and we can make small PRs without having to manage this stack (GitHub should make it easier to manage stacked PRs).

Wouldn't working on branches of MOI and JuMP accomplish the same goal? You can submit PRs against branches.

@matbesancon
Copy link
Contributor

Wouldn't working on branches of MOI and JuMP accomplish the same goal? You can submit PRs against branches.

It can be a bit harder to keep track of a separate branch all the time. A separate repo can also work better to dev the package but still keep MOI as-is, seeing the current state, etc

@odow
Copy link
Member Author

odow commented Apr 22, 2022

Okay, I've done quite a large refactoring. We now have Model, Evaluator and NLPBlockData:

model = Nonlinear.Model()
# add expressions, constraints etc.
evaluator = Nonlinear.Evaluator(model, Nonlinear.ExprGraphOnly(), [x])
block = MOI.NLPBlockData(evaluator)

I think that makes the distinction a lot clearer, because Nonlinear.Model is now just the data structure, with no fields for any AD. Presumably, someone could also write a presolve(::Model)::Model function, which consumes a model and returns a presolved model.

@odow odow mentioned this pull request Apr 22, 2022
@odow odow mentioned this pull request Apr 22, 2022
Copy link
Member

@mlubin mlubin left a comment

Choose a reason for hiding this comment

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

The refactor is a big improvement.

Ok to merge or split off into a package (as you prefer). IMO it should be manageable to keep working within the MOI package using branches as needed.

@odow odow changed the title RFC: add [Nonlinear] submodule DNMY: add [Nonlinear] submodule Apr 22, 2022
@odow
Copy link
Member Author

odow commented Apr 22, 2022

Ok to merge...IMO it should be manageable to keep working within the MOI package using branches as needed.

You mean merge into MOI proper? Or squash these commits and then leave it as a long-running branch that we merge other PRs into?

@mlubin
Copy link
Member

mlubin commented Apr 22, 2022

I don't see the harm in merging into MOI master.

@odow
Copy link
Member Author

odow commented Apr 22, 2022

Ah okay. I guess this warning is sufficient for the near term:
image

@odow odow changed the title DNMY: add [Nonlinear] submodule [Nonlinear] add new submodule Apr 22, 2022
@matbesancon
Copy link
Contributor

The other argument for having this in a separate package is keeping compilation time at a reasonable level, since one might change this one often in some cases without touching the rest of MOI. Having separate packages means separate compilation units

@blegat
Copy link
Member

blegat commented Apr 23, 2022

Trying to see what this would give in the future, I guess we could have

function Nonlinear.set_objective(model, expr)
    func = Nonlinear.parse_expression(model, expr)
    MOI.set(model, MOI.ObjectiveFunction{typeof(obj)}(), func)
end
function Nonlinear.add_constraint(model, expr, set)
    expr = parse_expression(model, expr)
    MOI.add_constraint(model, func, set)
end

so these functions would provide a convenience API for providing expressions with the :(...) syntax.
Is that aligned with what you imagine ? If we want to be able to break Nonlinear in the future, should we name it _Nonlinear ?

@matbesancon
Copy link
Contributor

Is that aligned with what you imagine ? If we want to be able to break Nonlinear in the future, should we name it _Nonlinear

There is a warning at the top-level of the Nonlinear doc that anything in there is experimental and subject to breaking changes.

We could add a statement in a docstring attached to the Nonlinear submodule itself

@blegat
Copy link
Member

blegat commented Apr 24, 2022

Doc is helping but I don't know if that's sufficient, might be though, just think we should consider both possibilities.

@odow
Copy link
Member Author

odow commented Apr 24, 2022

We could add a statement in a docstring attached to the Nonlinear submodule itself

I'll add a docstring. No one is going to be messing with this submodule accidentally. The docs are pretty clear that it is experimental, so I don't mind breaking things at-will for the near-term.

odow and others added 3 commits April 25, 2022 10:36
The majority of this development was carried out in the JuMP PRs:
 * jump-dev/JuMP.jl#2939
 * jump-dev/JuMP.jl#2942
 * jump-dev/JuMP.jl#2943

Nonlinear.ReverseAD is a minor refactoring of code that previously
existed in JuMP under the _Derivatives submodule, and prior to that
the ReverseDiffSparse.jl package.
odow and others added 10 commits April 25, 2022 10:36
@odow odow force-pushed the od/nonlinear-api branch from 6046b30 to 969129c Compare April 24, 2022 22:40
@odow odow merged commit 1af7064 into master Apr 25, 2022
@odow odow deleted the od/nonlinear-api branch April 25, 2022 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Project: next-gen nonlinear support Issues relating to nonlinear support
Development

Successfully merging this pull request may close these issues.

5 participants