Knitro#
Artelys Knitro is an especially powerful nonlinear solver, offering a range of state-of-the-art algorithms and options for working with both smooth and discrete objective and constraint functions in continuous and integer variables. It is designed for local optimization of large-scale problems with up to hundreds of thousands of variables.
Product Page | Features | Options | Changes
Download Knitro | Start a Knitro Trial Now!
How to use it#
How to install using amplpy:
# Install Python API for AMPL:
$ python -m pip install amplpy --upgrade
# Install AMPL & solver modules:
$ python -m amplpy.modules install knitro # install Knitro
# Activate your license (e.g., free ampl.com/ce or ampl.com/academia licenses):
$ python -m amplpy.modules activate <your-license-uuid>
How to use:
from amplpy import AMPL
ampl = AMPL()
...
ampl.solve(solver="knitro", knitro_options="option1=value1 option2=value2")
Learn more about what we have to offer to implement and deploy Optimization in Python.
ampl: option solver knitro; # change the solver
ampl: option knitro_options 'option1=value1 option2=value2'; # specify options
ampl: solve; # solve the problem
Features#
Algorithms#
Continuous models: interior point, active set, SQP
nlp_algorithm: 0 automatic (default), 1 interior point (direct),
2 interior point (CG), 3 active set (SLQP), 4 SQP, 5 several
algorithms, 6 augmented Lagrangian. Knitro returns local optima.
Mixed-integer models
mip_method: 0 automatic, 1 branch-and-bound, 3 mixed-integer SQP.
On nonconvex models the result is a local, not a global, optimum.
Multistart
ms_enable=1 solves from several starting points and keeps the best local
optimum; ms_maxsolves sets how many. For MIP, mip_multistart=1.
Threads and time
numthreads (parallel features), maxtime (seconds).
Modeling with MP expressions#
MP expressions: logic and counting (MP2NL)
Natively, Knitro solves smooth nonlinear models with continuous and integer variables, and complementarity (complements). MP’s expressions (==>, or, atmost, count, alldiff, piecewise-linear terms, …) are not part of its native model type: through MP2NL, MP reformulates them into it first.
The Knitro driver includes the MP2NL bridge: set mp2nl=1 in knitro_options. MP’s own options (cvt:..., sol:chk:...) then go into the AMPL option mp_options.
MP reformulates logic with binary variables, which Knitro handles as integer variables.
ampl.solve(solver="knitro", knitro_options="mp2nl=1", mp_options="cvt:bigM=1e5")
ampl: option solver knitro;
ampl: option knitro_options 'mp2nl=1';
ampl: option mp_options 'cvt:bigM=1e5';
ampl: solve;
More: Meta-driver MP2NL.
Options#
Full list of solver options:
Retrieving solutions#
The outcome of the last optimization is stored in the AMPL parameter solve_result_num and the relative message in
solve_result.
display solve_result_num, solve_result;
Knitro solve result codes:
Solve result table (AMPL default ranges)
0- 99 solved: optimal for an optimization problem, feasible for a satisfaction problem
100-199 solved? solution candidate returned but error likely
200-299 infeasible
300-399 unbounded
400-499 limit
500-999 failure, no solution returned
Changelog#
- KNITRO Changelog
- 20261029
- 20260714
- 20260108
- 20251219
- 20251123
- 20250923
- 20241220
- 20240209
- 20240201
- 20221213
- 20221123
- 20220704
- 20220215
- 20220124
- 20220118
- 20220104
- 20211109
- 20211006
- 20210820
- 20210622
- 20210410
- 20210330
- 20210111
- 20201030
- 20201030
- 20201018
- 20201005
- 20200914
- 20200905
- 20200503
- 20200502
- 20200414
- 20191219
- 20191204
- 20190908
- 20190711
- 20190605, 20190606
- 20190315
- 20181221
- 20190207
- 20181221
- 20181210
- 20181120
- 20180925
- 20180816
- 20180619
- 20180609
- 20180525
- 20180519
- 20180515
- 20180402
- 20180314
- 20180302
- 20180209
- 20180121
- 20171218
- 20171211
- 20171129
- 20170803
- 20170801
- 20170723
- 20170619
- 20170515
- 20170514
- 20170511
- 20161208
- 20160908
- 20160831
- 20160608
- 20160329
- 20160111
- 20151211
- 20151210
- 20151208
- 20151031
- 20150814
- 20150630
- 20150602
- 20150529
- 20150424
- 20150226
- 20150203
- 20150126
- 20150122
- 20150114
- 20141210
- 20141124
- 20141102
- 20141013
- 20141004
- 20140918
- 20140409
- 20140306
- 20140305
- 20131219
- 20131023
- 20131018
- 20131011
- 20130823
- 20130606
- 20130525
- 20130419
- 20130320
- 20130308
- 20130130
- 20121220
- 20120813
- 20120624
- 20120620
- 20120608
- 20120320
- 20120120
- 20120117
- 20120115
- 20111229
- 20111206
- 20111107
- 20111018
- 20111005
- 20111003
- 20110915
- 20110822
- 20110527
- 20110426
- 20110117
- 20101013