-
Notifications
You must be signed in to change notification settings - Fork 20
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
Support Nonlinear Expressions #161
Conversation
Codecov Report
@@ Coverage Diff @@
## master #161 +/- ##
==========================================
+ Coverage 99.78% 99.81% +0.03%
==========================================
Files 32 33 +1
Lines 6522 7149 +627
==========================================
+ Hits 6508 7136 +628
+ Misses 14 13 -1
Continue to review full report at Codecov.
|
@frapac might be of interest for experimenting next-generation JuMP nonlinear |
I benchmarked a lot of different configurations as this was developed and this approach was the most performant. Admittedly, it is not always as fast as the It does handle large sums reasonably well: julia> @time @expression(m, sum(x^i for i in 1:1000));
0.001774 seconds (25.96 k allocations: 1.129 MiB)
julia> @time @expression(m, sum(x^i for i in 1:10000));
0.013832 seconds (268.96 k allocations: 11.429 MiB)
julia> @time @expression(m, sum(x^i for i in 1:100000)); # we start to hit gc at about this point
0.167060 seconds (2.70 M allocations: 114.426 MiB, 18.01% gc time)
julia> f(n) = sum(x^i for i in 1:n);
julia> @time f(1000);
0.001436 seconds (25.96 k allocations: 1.129 MiB)
julia> @time f(10000);
0.014032 seconds (268.96 k allocations: 11.429 MiB)
julia> @time f(100000);
0.176825 seconds (2.70 M allocations: 114.426 MiB, 22.59% gc time) |
Well after months of work, nonlinear has finally arrived! This implements our own nonlinear expression abstraction
NLPExpr
s which use a left-child right-sibling expression tree that can store constants, variables, affine expressions, and/or quadratic expressions as leaves. Moreover, we supportNLPExpr
as a 1st class citizen inInfiniteOpt
having nearly all the functionality of affine/quadratic expressions! Closes #16.Early adopters can try this out via:
The preview of the relevant new nonlinear documentation is available here: https://pulsipher.github.io/InfiniteOpt.jl/previews/PR161/guide/expression/#nlp_guide
Some of the many features are highlighted below.
Operator Definition
Nonlinear expressions can be defined outside of macros like their quad/affine counterparts:
Macro Definition
By making the necessary extensions to
MutableArithmetics
, we can defineNLPExprs
inside of@expression
,@objective
, and@constraint
(i.e., no need for the specialNL
macros):Linear Algebra Support
We can also do linear algebra operations:
Function Tracing
Because we support operator definition, we can trace functions in like manner to
Symbolics.jl
:Deletion
Variables can be deleted from
NLPExpr
s and constraints withNLPExpr
s can also be deleted:User Defined Functions
For user-defined functions that are not compatible with tracing, we allow them to be registered like in
JuMP
andSymbolics.jl
.Note that it must be a macro since we have to overload the function behind the scenes to create
NLPExprs
.