Printing non linear expression in model

Hi All,
is there a way to print non linear expression

model=Model()
@variable(model,x)
exp1 =@NLexpression(model,x*x)
@NLconstraint(model,exp1<=10)

println("exp1",exp1)
output

 exp1"Reference to nonlinear expression #1"
 
i want the output as
exp1 x*x

Do not know JuMP and a more direct way.

FWIW, the subexpression you need shows up in println(exp1.m)

It could be parsed:

s = split(split(string(exp1.m),"\n")[end-1], ": ")[2]
println("exp1 ", s)

Not without hacking some of the JuMP internals. Improving the printing of nonlinear information is on our TODO list.

You can do

julia> JuMP._nl_subexpression_string(JuMP.REPLMode, model)[exp1.index]
"subexpression[1]: x * x"

but this accesses a private method (beginning with _), so it may break in any future JuMP release.

1 Like

Many thanks for the reply with Julia 1.2 and JuMP 0.21.1
getting
ERROR: UndefVarError: _nl_subexpression_string not defined

with Julia 1.2 and JuMP 0.21.1

Please update to Julia 1.6 and JuMP 0.21.10.

1 Like

thanks

1 Like