# Couple JuMP with the simulator

**URL:** https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792
**Category:** Optimization (Mathematical)
**Created:** [May 10, 2022, 7:43am UTC](https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792 "2022-05-10T07:43:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jack\_Tang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jack_tang/32/33751_2.png) [@Jack\_Tang](https://discourse.julialang.org/u/Jack_Tang)
#### Post date: [May 10, 2022, 7:43am UTC](https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792/1 "2022-05-10T07:43:23Z")

</div>

Hi

I am working on a project about multi-reservoir control optimization problem and the objective function is calculated by Telemac simulator. Do you have some examples or best practices for such integration? I have read some JuMP examples and the objective function is written in expressions. Can I pass one function to @objective macro and can I get all variables in the function?

Thanks!

---

<div class="post-metadata">

### Author: ![tred](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@tred](https://discourse.julialang.org/u/tred)
#### Post date: [May 10, 2022, 8:01am UTC](https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792/2 "2022-05-10T08:01:30Z")

</div>

As far as I know, JuMP cannot deal with black box functions. [Alternatives are listed here](https://jump.dev/JuMP.jl/stable/should_i_use/#Black-box,-derivative-free,-or-unconstrained-optimization)

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [May 10, 2022, 8:38am UTC](https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792/3 "2022-05-10T08:38:01Z")

</div>

Hi @Jack_Tang,

If your simulator can only return function evaluations, then JuMP isn’t the right tool for the job. Follow the link suggested by @tred for alternatives.

But if it can return derivative information, then you could consider using a user-defined function: [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nlp/#User-defined-Functions)

---

<div class="post-metadata">

### Author: ![Jack\_Tang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jack_tang/32/33751_2.png) [@Jack\_Tang](https://discourse.julialang.org/u/Jack_Tang)
#### Post date: [May 10, 2022, 8:41am UTC](https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792/4 "2022-05-10T08:41:48Z")

</div>

Thanks for your quick reply. Follow the link you provide, I find the user-defined-function section: [Nonlinear Modeling · JuMP](https://jump.dev/JuMP.jl/stable/manual/nlp/#Register-a-function). And the code snippet from `Register a function` section

```julia
square(x) = x^2
couple_with(x, y) = function .... get result from simultor... end

model = Model()

register(model, :square, 1, square; autodiff = true)
register(model, :couple_with, 2, f; autodiff = true)

@variable(model, x[1:2] >= 0.5)
@NLobjective(model, Min, couple_with(x[1], x[2]))

```

Thanks!

---

<div class="post-metadata">

### Author: ![Jack\_Tang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jack_tang/32/33751_2.png) [@Jack\_Tang](https://discourse.julialang.org/u/Jack_Tang)
#### Post date: [May 10, 2022, 8:42am UTC](https://discourse.julialang.org/t/couple-jump-with-the-simulator/80792/5 "2022-05-10T08:42:24Z")

</div>

Yep, thanks for the confirm!
