# Nonlinear Optimization with Many Constraints + Autodifferentiation: Which Julia Solution?

**URL:** <https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, ipopt, nonlinear-optimizati\
**Created:** [February 24, 2024, 12:00am UTC](https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678 "2024-02-24T00:00:30Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [February 26, 2024, 7:22am UTC](https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678/21 "2024-02-26T07:22:30Z")

</div>

> [@odow](#):
>
> For algebraic expressions, JuMP does not use ForwardDiff, but a custom sparse reverse mode AD.

Thanks, I finally did find a mention of it buried deep in [https://jump.dev/JuMP.jl/stable/moi/submodules/Nonlinear/overview/#ReverseAD](https://jump.dev/JuMP.jl/stable/moi/submodules/Nonlinear/overview/#ReverseAD). Do you think it deserves a more visible spot, somewhere in [https://jump.dev/JuMP.jl/stable/manual/nonlinear/](https://jump.dev/JuMP.jl/stable/manual/nonlinear/)? I would open a PR myself but I’m unsure how to phrase it

---

<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:** [February 26, 2024, 7:58am UTC](https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678/22 "2024-02-26T07:58:43Z")

</div>

It doesnt have a prominent mention because almost all users should never need to know about or understand the details. The AD system is very JuMP specific, so you can’t just swap to use Enzyme or similar.

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [February 26, 2024, 11:04am UTC](https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678/23 "2024-02-26T11:04:38Z")

</div>

Alright. I was only asking because until now I was not aware of the different treatment between “algebraic expressions” (aka [function tracing](https://jump.dev/JuMP.jl/stable/manual/nonlinear/#Function-tracing)?) and custom functions. But granted, I haven’t done lots of nonlinear modeling so far

---

<div class="post-metadata">

**Author:** ![SebKrantz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebkrantz/32/50256_2.png) [@SebKrantz](https://discourse.julialang.org/u/SebKrantz)\
**Post date:** [March 15, 2024, 6:42pm UTC](https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678/24 "2024-03-15T18:42:18Z")

</div>

@odow thanks again for your help. [OptimalTransportNetworks.jl](https://github.com/SebKrantz/OptimalTransportNetworks.jl) is under development. I have another question regarding the specification and updating of the `kappa_ex` vector (containing exogeneous transport frictions). As you suggested, I am using a parameter as follows, for example in [model\_fixed.jl](https://github.com/SebKrantz/OptimalTransportNetworks.jl/blob/main/src/models/model_fixed.jl):

```julia
 kappa_ex_init = auxdata[:kappa_ex]

# ... some code

# Parameters: to be updated between solves
@variable(model, kappa_ex[i = 1:graph.ndeg] in Parameter(kappa_ex_init[i]))

```

Then, in [optimal\_network.jl](https://github.com/SebKrantz/OptimalTransportNetworks.jl/blob/de157f7a38157f6ff05929ff5d983ae5d7d9e481/src/main/optimal_network.jl#L212), there is an updating line as follows:

```julia
set_parameter_value.(model.obj_dict[:kappa_ex], kappa_ex_updated)

```

I wanted to know if this is the recommended way of doing so. Is it possible to also generate a vector parameter which would simplify the Syntax and updating? (noting also that `kappa_ex` can be large for large networks). The reason I am asking this in particular is because I seem to be getting a [failure building the library on Github](https://github.com/SebKrantz/OptimalTransportNetworks.jl/actions/runs/8293569510/job/22696914414) because of this line. Many thanks!

[Previous page](https://discourse.julialang.org/t/nonlinear-optimization-with-many-constraints-autodifferentiation-which-julia-solution/110678.md?page=1)
