Upcoming breaking change in JuMP with user-defined functions

I’d like to let everyone know about an upcoming breaking change in how JuMP deals with user-defined functions. Previously, functions registered using JuMP.register were global in scope, making them complicated to deal with in a modular way. Since PR #930, JuMP.register now takes a JuMP model as the first argument, and the registration of the function will remain local to that model.

Before:

mysquare(x) = x^2
JuMP.register(:mysquare, 1, mysquare, autodiff=true)
m = Model()
@variable(m, x)
@NLobjective(m, Min, mysquare(x))

After:

mysquare(x) = x^2
m = Model()
JuMP.register(m, :mysquare, 1, mysquare, autodiff=true)
@variable(m, x)
@NLobjective(m, Min, mysquare(x))

Uses of JuMP.register without a model as the first argument will produce an error. My intention is to release this relatively soon (<1 month) in JuMP 0.16. Feedback and bug reports are welcome as always.

1 Like

That looks like a good idea.

As a non-current-user of this package, but implementer of somewhat related functionality, I have the following question:

Why is this not a macro @register to simplify the heavy notation a bit? Presumably there is a good reason (that might affect me), hence the question!

Why is this not a macro @register to simplify the heavy notation a bit? Presumably there is a good reason (that might affect me), hence the question!

No good reason really. Nobody has been motivated to implement it so far.