# Issue with JuMP's Parameter making the problem recognized as nonlinear

**URL:** <https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [November 2, 2024, 7:54am UTC](https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162 "2024-11-02T07:54:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuricst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuricst/32/207613_2.png) [@Yuricst](https://discourse.julialang.org/u/Yuricst)\
**Post date:** [November 2, 2024, 7:54am UTC](https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162/1 "2024-11-02T07:54:16Z")

</div>

Hello!

I am working on an algorithm where I would like to solve convex programs (CP) repeatedly; in the algorithm, the CP’s structure remains the same (same variables, same number of constraints, etc.), but coefficients to the constraints get updated. Thus, to automate the modification to the `JuMP.Model` (without having to reinstantiate one at each iteration), I am trying to use `Parameter` ’s.  
However, the issue I am having is that any nonlinear operation on `Parameter` ’s are recognized as nonlinearity of the optimization problem itself (even though it is meant to be a fixed value & not an optimization variable), thus making the resulting model appear as though it is not a CP.

Please see below a minimal example that I would like to resolve:

```julia
using ECOS
using JuMP

model = Model(ECOS.Optimizer)
@variable(model, x[1:2] >= 0)
@variable(model, θ in Parameter(0)) # initialize storage for parameter
set_parameter_value(θ, 0.5) # parameter value would be updated by outer loop

@constraint(model, x[1] + x[2] <= cos(θ)) # problematic due to nonlinear operation!

@objective(model, Min, 2x[1] + 3x[2])

optimize!(model)
@show objective_value(model)

```

for which I get the error

```julia
ERROR: LoadError: Constraints of type MathOptInterface.ScalarNonlinearFunction-in-MathOptInterface.LessThan{Float64} are not supported by the solver.

If you expected the solver to support your problem, you may have an error in your formulation. Otherwise, consider using a different solver.

The list of available solvers, along with the problem types they support, is available at https://jump.dev/JuMP.jl/stable/installation/#Supported-solvers.

```

Is there something that I am missing about how I should be using `Parameter`…?  
If not (and if this is unavoidable), what would be a good way for me to be able to update the value of \theta in the above code without having to recreate the model/overwrite the constraint?

I’d appreciate any help/suggestion, 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:** [November 3, 2024, 7:57pm UTC](https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162/2 "2024-11-03T19:57:07Z")

</div>

Hi @Yuricst, correct, we don’t detect that the nonlinear operation of a parameter is in fact a constant.

See this part of the JuMP documentation: [Constraints · JuMP](https://jump.dev/JuMP.jl/stable/manual/constraints/#Modify-a-constant-term)

For your code, it would look something like (I swapped `<=` to `>=` to yield different solutions):

```julia
julia> using ECOS

julia> using JuMP

julia> begin # Option 1
           model = Model(ECOS.Optimizer)
           set_silent(model)
           @variable(model, x[1:2] >= 0)
           constraint = @constraint(model, x[1] + x[2] >= 0.0)
           @objective(model, Min, 2x[1] + 3x[2])
           for rad in [0, 0.5, 1]
               set_normalized_rhs(constraint, cos(rad))
               optimize!(model)
               @assert is_solved_and_feasible(model)
               @show objective_value(model)
           end
       end
objective_value(model) = 1.999999997831738
objective_value(model) = 1.7551651219056938
objective_value(model) = 1.0806046105119194

julia> begin # Option 2
           model = Model(ECOS.Optimizer)
           set_silent(model)
           @variable(model, x[1:2] >= 0)
           @variable(model, cos_θ == cos(0))
           @constraint(model, x[1] + x[2] >= cos_θ)
           @objective(model, Min, 2x[1] + 3x[2])
           for rad in [0, 0.5, 1]
               fix(cos_θ, cos(rad); force = true)
               optimize!(model)
               @assert is_solved_and_feasible(model)
               @show objective_value(model)
           end
       end
objective_value(model) = 1.999999997831738
objective_value(model) = 1.7551651219056938
objective_value(model) = 1.0806046105119194

```

---

<div class="post-metadata">

**Author:** ![Yuricst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuricst/32/207613_2.png) [@Yuricst](https://discourse.julialang.org/u/Yuricst)\
**Post date:** [November 4, 2024, 10:45pm UTC](https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162/3 "2024-11-04T22:45:39Z")

</div>

Thank you for your reply!  
I see, I am for now resorting with using `set_normalized_rhs()`.

Concerning Option 2 in your code, I imagine using `fix(cos_θ, cos(rad); force = true)` still does not make `cos_θ` _not_ a variable as far as the model is concerned?  
I am asking for a scenario where I might have, for example, a constraint like

```julia
@constraint(model, x[1] * sin(θ) + x[2] * cos(θ) <= 0)

```

where I imagine even if I did

```julia
@variable(model, cos_θ == cos(0))
@variable(model, sin_θ == sin(0))

@constraint(model, x[1] * sin_θ + x[2] * cos_θ <= 0)

```

then

```julia
fix(cos_θ, cos(rad); force = true)
fix(cos_θ, sin(rad); force = true)

```

this would still be recognized as a quadratic constraint…?

---

<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:** [November 4, 2024, 11:16pm UTC](https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162/4 "2024-11-04T23:16:56Z")

</div>

Correct. We don’t substitute parameters into expressions and reduce them from nonlinear to linear/quadratic or quadratic to linear.

But you can use `set_normalized_coefficient` to modify the coefficient of a variable.

---

<div class="post-metadata">

**Author:** ![Yuricst](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuricst/32/207613_2.png) [@Yuricst](https://discourse.julialang.org/u/Yuricst)\
**Post date:** [November 5, 2024, 10:01pm UTC](https://discourse.julialang.org/t/issue-with-jumps-parameter-making-the-problem-recognized-as-nonlinear/122162/5 "2024-11-05T22:01:27Z")

</div>

Understood - thank you!
