Package: csnlp
Nonlinear Programming with CasADicsnlpprovides classes and utilities to model, solve and analyse nonlinear programmes (NLPs) in optimization.In particular, it makes use of theCasADiframework[1]to model the optimization problems and perform symbolic differentiation, as well as theIPOPTsolver[2](though the package can be adapted to other solvers pretty easily). The package offers also tools for the sensitivity analysis of NLPs, solving them with multiple initial conditions, as well as for building MPC controllers.InstallationTo install the package, runpipinstallcsnlpcsnlphas the following dependenciesPython 3.9 or higherNumPyCasADiJoblibFor playing around with the source code instead, rungitclonehttps://github.com/FilippoAiraldi/casadi-nlp.gitUsageSimilar to CasADi Opti, we instantiate a class that represents the NLP and allows to model its variables, parameters, constraints and objective. A simple example is below:fromcsnlpimportNlpnlp=Nlp()x=nlp.variable("x")[0]y=nlp.variable("y")[0]p=nlp.parameter("p")nlp.minimize((1-x)**2+0.2*(y-x**2)**2)g=(x+0.5)**2+y**2nlp.constraint("c1",(p/2)**2,"<=",g)nlp.constraint("c2",g,"<=",p**2)nlp.init_solver()# initializes IPOPT under the hoodsol=nlp.solve(pars={"p":1.25})# solves the NLP for parameter p=1.25x_opt=sol.vals["x"]y_opt=sol.value(y)The package also allows to enhance the NLP with different capabilities with, e.g., multistart (seecsnlp.MultistartNlp) or by wrapping it. As of now, wrappers have been implemented forsensitivity analysis (seecsnlp.wrappers.NlpSensitivity; based on[3])Model Predictive Control (seecsnlp.wrappers.Mpc;[4]for details)NLP scaling (seecsnlp.wrappers.NlpScaling).For instance, to compute the sensitivity of the optimal primal-dual variablesywith respect to the parameterspof the NLP , first we need to augment the capabilities of the NLP with a wrapper specialized in differentiating the optimization problem, and then compute the first-order and second sensitivities (dydpandd2ydp2, respectively) as such:fromcsnlpimportwrappersnlp=wrappers.NlpSensitivity(nlp)dydp,d2ydp2=nlp.parametric_sensitivity()In other words, these sensitivities provide the jacobian and hessian that locally approximate the solution w.r.t. the parametersp. As shown in the examples, the sensitivity can be also computed for any generic expressionzthat is a function of the primal-dual variables and the parameters, i.e.,z(x(p),lam(p),p), and computations can be carried out symbolically or numerically (more stable).Similarly, an NLP instance can be wrapped in an MPC wrapper that makes it easier to build such controller.ExamplesOurexamplessubdirectory contains example applications of this package in NLP optimization, sensitivity analysis, scaling of NLPs, and optimal control.LicenseThe repository is provided under the MIT License. See the LICENSE file included with this repository.AuthorFilippo Airaldi, PhD Candidate [f.airaldi@tudelft.nl|filippoairaldi@gmail.com]Delft Center for Systems and ControlinDelft University of TechnologyCopyright (c) 2023 Filippo Airaldi.Copyright notice: Technische Universiteit Delft hereby disclaims all copyright interest in the program “csnlp” (Nonlinear Progamming with CasADi) written by the Author(s). Prof. Dr. Ir. Fred van Keulen, Dean of 3mE.References[1]Andersson, J.A.E., Gillis, J., Horn, G., Rawlings, J.B., and Diehl, M. (2019).CasADi: a software framework for nonlinear optimization and optimal control. Mathematical Programming Computation, 11(1), 1–36.[2]Wachter, A. and Biegler, L.T. (2006).On the implementation of an interior-point filter line-search algorithm for large-scale nonlinear programming. Mathematical Programming, 106(1), 25–57.[3]Büskens, C. and Maurer, H. (2001).Sensitivity analysis and real-time optimization of parametric nonlinear programming problems. In M. Grötschel, S.O. Krumke, and J. Rambau (eds.), Online Optimization of Large Scale Systems, 3–16. Springer, Berlin, Heidelberg[4]Rawlings, J.B., Mayne, D.Q. and Diehl, M., 2017.Model Predictive Control: theory, computation, and design (Vol. 2). Madison, WI: Nob Hill Publishing.