constraint evaluation and printing level in Knitro's Python Scipy Interface

61 views
Skip to first unread message

Qingyi Chen

unread,
Sep 13, 2022, 12:50:12 AM9/13/22
to Artelys Knitro forum
Hi Artelys Knitro team,    

    Greetings. I am writing to inquire two problems about using Knitro with Python Interface, especially the Scipy interface.

    The knitro version I am using is knitro-13.1.0-Linux-64, running on Linux Ubuntu 22.04, Python 3.9.

    The first problem is about using the Python scipy interface with user-defined exact constraint jacobian function. It turns out that even if the user specifies a constraint jacobian function (say cons_J(x)) and declar the constraint to be
nonlinear_constraint = NonlinearConstraint(cons_f, cL, cU, jac=cons_J, hess=cons_H),
then call the optimization function
   res = minimize(
            fun=objective,
            x0=x0,
            method=kn_minimize,
            jac=objGrad,
            hess=objHess,
            constraints=[nonlinear_constraint],
            bounds=bounds,
            options={‘outlev’:0}
   )
,
the cons_J() function won’t be called even if it should be. The optimizer seems to be using numerical differential and therefore runs slower. The problem can be reproduced using any example problem defined in knitro-13.1.0-Linux-64/examples/Python/examples/exampleSciPy.py, by have a printing message in cons_J(x) or running a profile application to check how many times cons_J(x) is entered.

    The second problem is about using the Python scipy interface and specifying a printing level. It seems like even if the user specifies ‘disp’ = False (and ‘outlev’ = 0) option, when the optimize function is called, there would still be a few lines (undesiredly) being printed. As a comparison, for other methods in Scipy, specifying ‘disp’ = False will lead to completely no output. This problem can be reproduced by having opt={‘disp’:False} when calling minimize(options=opts). It may correspond to 1289-1293 lines in knitro-13.1.0-Linux-64/examples/Python/knitro/scipy/scipy_wrapper.py where the printing lines are not monitored by the disp variable.    

Thank you very much for your great product. I hope my inquiries would make sense - please kindly let me know if more information or clarification is needed.

Best regards,
Qingyi


Richard Waltz

unread,
Sep 15, 2022, 11:00:11 AM9/15/22
to Artelys Knitro forum

Dear Qingyi,


Thank you for your message and feedback on the Knitro-Scipy interface. We will investigate it to try to fix it accordingly.


In the meantime, if you are solving complex nonlinear applications I would recommend to directly use the Knitro Python API as it is much more flexible and designed especially for complex nonlinear models. The Scipy interface is more limited as it is also designed for simpler algorithms that only handles unconstrained problems.


Kind regards,



From: kni...@googlegroups.com <kni...@googlegroups.com> on behalf of Qingyi Chen <che...@umich.edu>
Sent: Monday, September 12, 2022 5:47 PM
To: Artelys Knitro forum <kni...@googlegroups.com>
Subject: [Knitro] constraint evaluation and printing level in Knitro's Python Scipy Interface
 
--
You received this message because you are subscribed to the Artelys "Knitro Nonlinear Optimization Solver" google group.
To post to this group, send email to kni...@googlegroups.com
To unsubscribe from this group, send email to knitro-un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/knitro?hl=en
Thank You,
Artelys
http://www.artelys.com/en/optimization-tools/knitro
---
You received this message because you are subscribed to the Google Groups "Artelys Knitro forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to knitro+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/knitro/a88a7e45-81ed-4355-86b1-43fecbd00fecn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages