Parse NLconstraint in JuMP

Hi folks,

I want do the following in JuMP but I don’t know how to do it. Suppose I already have a model m. In model m, I defined variables x (for simplicity let’s just represent all the variables in x, which is a R^n vector). I also have nonlinear constraints g(x)<=0 in model m. The nonlinear constraints are defined using macro @NLconstraint. In this case, g(x)<=0 could correspond to several @NLconstraint we defined in a JuMP model. Now, I want to generate a new model n based on model m. In model n, I have variables y, which is R^n, and variable lambda, which is R^1. I want to define constraint lambda*g(y/lambda)<=0 in model n, which is like the perspective function of g(x).

Suppose someone else give me a model m written in JuMP, it there some ways to generate the corresponding model n in JuMP automatically by writing a parser?

More specifically, I guess my question is 1. how to obtain the expression in NLconstraint?
2. Is there some symbolic library in Julia that can do the following: given an expression g(x), is there any ways to generate the expression lambda*g(x/lambda)? Also would the symbolic library work for the expression in JuMP? If not, how to translate a JuMP expression to an expression that can be parsed by the symbolic library?

Thanks a lots!

Best regards,
Can

JuMP has a developer API for accessing expressions from a model and inputting expressions programmatically. See:
http://www.juliaopt.org/JuMP.jl/0.18/nlp.html#querying-derivatives-from-a-jump-model
http://mathprogbasejl.readthedocs.io/en/latest/nlp.html#obj_expr
http://mathprogbasejl.readthedocs.io/en/latest/nlp.html#constr_expr
http://www.juliaopt.org/JuMP.jl/0.18/nlp.html#raw-expression-input

https://github.com/lanl-ansi/POD.jl is a pretty comprehensive example of a solver that exploits this interface.

By the way, if you’re dealing with perspective functions, I’d highly recommend considering conic formulations of the constraints instead of NLP formulations. Conic form deals with perspectives naturally and doesn’t suffer from the division-by-zero issues that you would get when an NLP solver asks for a derivative evaluation at lambda = 0. If you’re bored you can read more about conic form and its modeling side (DCP) in my thesis.

1 Like

Hi Miles,

Thanks for your answer. I’m new to the developer API. Could you explain how to use it?

Let’s say I have defined
m=Model(solver=IpoptSolver())
@variable(m, x)
@NLconstraint(m, c1, x^2<=1)

how do I access the constraint c1 using the API constr_expr?

Also, do you know how to get the expression of the corresponding perspective function programmatically?

By the way, thanks for the link of your thesis. I will take a look later. We normally use the approximation
image
for perspective functions to avoid the division by zero problem.

Thanks a lot!
Can