# Upcoming breaking change in JuMP with user-defined functions

**URL:** https://discourse.julialang.org/t/upcoming-breaking-change-in-jump-with-user-defined-functions/1191
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [December 28, 2016, 10:54pm UTC](https://discourse.julialang.org/t/upcoming-breaking-change-in-jump-with-user-defined-functions/1191 "2016-12-28T22:54:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)
#### Post date: [December 28, 2016, 10:54pm UTC](https://discourse.julialang.org/t/upcoming-breaking-change-in-jump-with-user-defined-functions/1191/1 "2016-12-28T22:54:45Z")

</div>

I’d like to let everyone know about an upcoming breaking change in how JuMP deals with [user-defined functions](http://www.juliaopt.org/JuMP.jl/0.15/nlp.html#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](https://github.com/JuliaOpt/JuMP.jl/pull/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:

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

```

After:

```julia
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.

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [December 28, 2016, 11:33pm UTC](https://discourse.julialang.org/t/upcoming-breaking-change-in-jump-with-user-defined-functions/1191/2 "2016-12-28T23:33:38Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![miles.lubin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miles.lubin/32/279_2.png) [@miles.lubin](https://discourse.julialang.org/u/miles.lubin)
#### Post date: [December 29, 2016, 4:03am UTC](https://discourse.julialang.org/t/upcoming-breaking-change-in-jump-with-user-defined-functions/1191/3 "2016-12-29T04:03:19Z")

</div>

> 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.
