I'm working with pyomo and already have a model defined, with an objective function to go with it. After the model is solved, the objective function has certain parameters attached to it. So if i had a multi index variable [x1, x2, x3]
, my quadratic objective function would suppose look something like this: (x1^2 + 13*x2^2 + 10*x3^2) + (2*x1 +......)
.
My question is: given that i can actually access this expression in string format from the objective, is there any way to obtain the second derivative of this function with respect to all the variables?
There are two ways to get derivative information in Pyomo.
If you need numeric derivatives at a single point, you can use a tool like the "gjh_asl_json" tool (https://github.com/ghackebeil/gjh_asl_json) that can take an NL file generated by Pyomo and produces a JSON file with the Jacobian and Hessian information.
If you want symbolic derivatives, Pyomo can provide those directly, provided you also have
sympy
installed:Of course, given that your expression is quadratic, symbolic and numeric differentiation will both give you the same answer.