# sIpopt extension in JuMP?

**URL:** <https://discourse.julialang.org/t/sipopt-extension-in-jump/32899>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [January 2, 2020, 10:29pm UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899 "2020-01-02T22:29:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mandart](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mandart](https://discourse.julialang.org/u/mandart)\
**Post date:** [January 2, 2020, 10:29pm UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/1 "2020-01-02T22:29:32Z")

</div>

Hi, is there a way to use the sIpopt extension to Ipopt ([https://projects.coin-or.org/Ipopt/wiki/sIpopt](https://projects.coin-or.org/Ipopt/wiki/sIpopt)) within JuMP?

I can set up a JuMP model with a call to the AMPL sIpopt executable using AmplNLWriter.jl. However, storing sIpopt solutions requires AMPL suffixes, which don’t have an equivalent in JuMP. Is there a way around this?

---

<div class="post-metadata">

**Author:** ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)\
**Post date:** [January 3, 2020, 7:30am UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/2 "2020-01-03T07:30:35Z")

</div>

As far as I know, there is no way to call directly sIpopt from JuMP currently. But I agree that would be a nice extension. I recommend you having a look at :

> **[GitHub - JuliaStochOpt/ParameterJuMP.jl: A JuMP extension to use parameter in...](https://github.com/JuliaStochOpt/ParameterJuMP.jl)**
>
> A JuMP extension to use parameter in constraints RHS - GitHub - JuliaStochOpt/ParameterJuMP.jl: A JuMP extension to use parameter in constraints RHS

However ParameterJuMP.jl does not support pure NLP problems, as sIpopt. Last time I checked though, I did not find a C API available for sIpopt, so currently I think we should stick to AmplNLWriter.

My own opinion is that at some point it could be useful to have a MOI extension that supports parametric optimization. That would pave the road to a Julia equivalent of [cvxpylayer](https://github.com/cvxgrp/cvxpylayers).

---

<div class="post-metadata">

**Author:** ![mandart](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mandart](https://discourse.julialang.org/u/mandart)\
**Post date:** [January 3, 2020, 5:03pm UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/3 "2020-01-03T17:03:29Z")

</div>

Thank you, I mainly want to get NLP sensitivities through sIpopt.

Pyomo/AMPL/C have extensions to sIpopt and other platforms like Casadi have frameworks to directly access the NLP sensitivities. I agree it would be nice to have a Julia equivalent.

---

<div class="post-metadata">

**Author:** ![frapac](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frapac/32/6879_2.png) [@frapac](https://discourse.julialang.org/u/frapac)\
**Post date:** [January 5, 2020, 2:50am UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/4 "2020-01-05T02:50:01Z")

</div>

You are right. Looking at the code of the AMPL interface, it appears that sIpopt overloads the method `get_var_con_metadata` to pass the parameters to Ipopt (provided that sIpopt was compiled before).  
I think it’s doable to mirror the behavior of the function `get_var_con_metadata` in Ipopt.jl, but this is not a trivial job though. One major difficulty is that the function `get_var_con_metadata` does not seem to be mirrored in [Ipopt’s C interface](https://github.com/coin-or/Ipopt/blob/master/src/Interfaces/IpStdCInterface.h).

Further, the signature of this function

```julia
    virtual bool get_var_con_metadata(Index n,
                                      StringMetaDataMapType& var_string_md,
                                      IntegerMetaDataMapType& var_integer_md,
                                      NumericMetaDataMapType& var_numeric_md,
                                      Index m,
                                      StringMetaDataMapType& con_string_md,
                                      IntegerMetaDataMapType& con_integer_md,
                                      NumericMetaDataMapType& con_numeric_md)

```

depends on non-trivial type, as the map structure of the std:

```julia
    typedef std::map<std::string, std::vector<std::string> > StringMetaDataMapType;
    typedef std::map<std::string, std::vector<Index> > IntegerMetaDataMapType;
    typedef std::map<std::string, std::vector<Number> > NumericMetaDataMapType;

```

I do not know if [sIpopt2](https://github.com/athrpf/sipopt2) gives a better support. Nonetheless, the package looks a bit abandonned.

---

<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:** [January 5, 2020, 5:55pm UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/5 "2020-01-05T17:55:11Z")

</div>

> [@mandart](#):
>
> sIpopt solutions requires AMPL suffixes, which don’t have an equivalent in JuMP

The equivalent of AMPL suffixes are variable and constraint attributes (see MathOptInterface docs). Could you explain how sIpopt uses AMPL suffixes? It’s likely a question of connecting the plumbing through AmplNLWriter.

---

<div class="post-metadata">

**Author:** ![mandart](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@mandart](https://discourse.julialang.org/u/mandart)\
**Post date:** [January 6, 2020, 8:44pm UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/6 "2020-01-06T20:44:04Z")

</div>

sIpopt calculates parametric NLP sensitivities and provides perturbed solutions for perturbed parameters.

The AMPL model needs suffixes to communicate certain inputs to sIpopt - these inputs relate to nominal and perturbed values of the parameters, and some additional flags. The model also needs a suffix to store the perturbed solution from sIpopt. These suffixes are declared in AMPL as follows:

```julia
# declare AMPL suffixes for sIPOPT code
suffix sens_state_0, IN;
suffix sens_state_1, IN;
suffix sens_state_value_1, IN;
suffix sens_init_constr, IN;
suffix sens_sol_state_1, OUT;

```

The inputs are then passed through the input suffixes, for example:

```julia
var x;
let x.sens_state_0 := 1;

```

Once the perturbed solution is found, the output can be accessed via, for example:

```julia
x.sens_sol_state_1

```

Could you give an example of how MOI variable and constraint attributes can be modified to mimic the AMPL suffixes? Thank you.

---

<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:** [January 6, 2020, 9:29pm UTC](https://discourse.julialang.org/t/sipopt-extension-in-jump/32899/7 "2020-01-06T21:29:05Z")

</div>

This is likely very non-trivial. How are the sensitivities returned by sIpopt? Programatically or via the .sol file? Either way, it’s probably easier to write a new sIpopt.jl package and to modify an existing one. (And that isn’t really that easy.)
