Same answer as Ipopt's "local" optimum can be very substandard - #5 by odow
Additional question: will it be all right to directly write
g(x)
in theline, as it was look like in the Gurobi’s code?
Yes. JuMP uses function tracing to compute the underlying expression.