Extracting the coefficient of a nonlinear term in a JuMP model

Hi @handahye, welcome to the forum :smile:

The simple answer is “no”.

If you grab the constraint function:

model = Model()
@variable(model, x[1:3])
c = @constraint(model, (x[1] - (((3* ((x[2] ^ 2.0) + (x[3] ^ 2.0)))))) <= 0)
o = constraint_object(c)
o.func

You can play around to see what the fields are: Nonlinear Modeling · JuMP

julia> o.func.args[1].args[2].args
2-element Vector{Any}:
 3.0
  (x[2] ^ 2.0) + (x[3] ^ 2.0)

I don’t know what an .nlp file is, but if you had written the constraint as the quadratic:

c_quad = @constraint(model, x[1] - 3 * (x[2]^2 + x[3]^2) <= 0)
c_quad_object = constraint_object(c_quad)
coefficient(c_quad_object.func, x[2], x[2])

this would work.

We’re working on some features to automatically convert nonlinear constraints to quadratic, etc, that might help in a future release of JuMP: [Nonlinear] add SymbolicAD submodule by odow · Pull Request #2624 · jump-dev/MathOptInterface.jl · GitHub