Gradient information at optimum (currently using IPOPT)

235 views
Skip to first unread message

Danny Kaufman

unread,
Jul 22, 2018, 10:15:19 AM7/22/18
to Pyomo Forum
I really enjoy using Pyomo, but could use some help!

When trying to analyze a nonlinear ConcreteModel solved using Pyomo with IPOPT, I am having difficulties determining an approximation of the gradient, i.e. trying to answer the question:
- At the optimum (x*), when each variable x_i is perturbed, e.g. to x*_i+1 or x*_i+0.001, what is the change in the objective function value?




I may just be skipping over something, but feel like I'm going around in circles... I've tried:

- using the "gjh" solver, however the results do not seem to correspond well to results of manually perturbing the solution.

- looking at the dual, ipopt_zL_out, ipopt_zU_out Suffixes. 
But, am I right that the dual, ipopt_zL_out, ipopt_zU_out variables won't provide the precise information I'm looking for? That is, the zL and zU represent shadow prices / gradients only for constrained variables? (for reference, I looked at https://groups.google.com/forum/#!topic/pyomo-forum/OqIcVNIKUMk)

- using the "derivative_test" option with IPOPT (but the "grad_f" output doesn't seem to be placed back into the model instance when specifying "grad_f" as an IMPORT Suffix)

---- (a related question: even if I can load the grad_f values into the model instance, how does one relate the numbered indexes, e.g. grad_f[  121], to variables indexed by named sets, which might be unordered? For this instance, each variable looks like x[('ConserveTill', 'N51133RL0_6450_0000', 'hfr')], so I don't know which variable [  121] is referring to. )



Here are the problem details as output by IPOPT:
Number of nonzeros in equality constraint Jacobian...:        0
Number of nonzeros in inequality constraint Jacobian.:     2628
Number of nonzeros in Lagrangian Hessian.............:     5278

Total number of variables............................:     1339
                     variables with only lower bounds:     1339
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:        0
Total number of inequality constraints...............:     1108
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:     1108



I am relatively new to using nonlinear solvers, so please pardon any unintentional misstatements and the additional questions embedded within this one post.  Thanks for any thoughts you are willing to share!

Santiago rodriguez

unread,
Jul 23, 2018, 8:57:31 AM7/23/18
to Pyomo Forum
There is fork of pyomo with the capabilities you are looking for. Derivatives are basically compute with ASL and stored in numpy arrays. There have some discussions on adding some of these features on pyomo and therefore the fork is currently on a pull request. If you want to have a look you could clone the project from


To use it you will have to checkout the pynumero branch. Within the contrib folder you can find examples of how to get derivative information


There is also an example on how to compute sensitivity of an nlp


However, currently we only support these features in OSX and Linux so as the code will only work if you are in any of those platforms. 

Danny Kaufman

unread,
Jul 24, 2018, 1:51:03 PM7/24/18
to pyomo...@googlegroups.com
Santiago, I really appreciate your response.  Pynumero looks like a great addition to the pyomo repo.  

I've tried to get Pynumero working on the model instance I have, but there's an error immediately on the line:
>>> nlp = PyomoNLP(instance)

The error message reads:
OSError: dlopen(.../pyomo/pyomo/contrib/pynumero/extensions/lib/Darwin/libpynumero_ASL.so, 6): Symbol not found: ___cxa_throw_bad_array_new_length
  Referenced from: .../pyomo/pyomo/contrib/pynumero/extensions/lib/Darwin/libpynumero_ASL.so
  Expected in: /usr/lib/libstdc++.6.0.9.dylib
 in .../pyomo/pyomo/contrib/pynumero/extensions/lib/Darwin/libpynumero_ASL.so

Have you seen this before.. Any thoughts?
(It is running on OSX)

Perhaps it is a path issue, in which case I will keep trying to sort it out on my own as well.

Thanks,
Danny

Santiago rodriguez

unread,
Jul 24, 2018, 2:05:12 PM7/24/18
to Pyomo Forum
Did the example scripts run? 

We are currently working on the pull request to add pynumero into pyomo so probably it will be wise to wait few days for the latest version. 

If you want you can send me your model instance on a private message and I'll try to figure out what is causing the problem.

/Santiago
Reply all
Reply to author
Forward
0 new messages