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

Skip to first unread message

Qingyi Chen

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(
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/, 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/ 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,

Richard Waltz

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: <> on behalf of Qingyi Chen <>
Sent: Monday, September 12, 2022 5:47 PM
To: Artelys Knitro forum <>
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
To unsubscribe from this group, send email to
For more options, visit this group at
Thank You,
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
To view this discussion on the web visit
Reply all
Reply to author
0 new messages