diff --git a/README.md b/README.md index 3d3cdc6..222fa6b 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ It currently supports the following optimizers: - [HiGHS](https://github.com/ERGO-Code/HiGHS) ( Open source ) - [Mosek](https://www.mosek.com/) ( Commercial ) - [Ipopt](https://github.com/coin-or/Ipopt) ( Open source ) +- [KNITRO](https://www.artelys.com/solvers/knitro/) ( Commercial ) ## Short Example ```python @@ -113,7 +114,7 @@ It uses [nanobind](https://github.com/wjakob/nanobind), [fmtlib](https://github. The design of PyOptInterface is inspired by [JuMP.jl](https://jump.dev). -Some solver-related code in `src` folder is adapted from the corresponding solver interface package in `JuMP.jl` +Some solver-related code in `src` folder is adapted from the corresponding solver interface package in `JuMP.jl` ecosystem, which is licensed under MIT License. The header files in `thirdparty/solvers` directory are from the corresponding distribution of optimizers and are licensed under their own licenses. diff --git a/docs/source/index.md b/docs/source/index.md index 40fb7a1..fd334bb 100644 --- a/docs/source/index.md +++ b/docs/source/index.md @@ -28,6 +28,7 @@ copt.md mosek.md highs.md ipopt.md +knitro.md changelog.md ``` diff --git a/docs/source/knitro.md b/docs/source/knitro.md index 77f2067..fe15fab 100644 --- a/docs/source/knitro.md +++ b/docs/source/knitro.md @@ -10,6 +10,23 @@ model = knitro.Model() You need to follow the instructions in [Getting Started](getting_started.md#knitro) to set up the optimizer correctly. +If you want to manage the license of KNITRO manually, you can create a `knitro.Env` object and pass it to the constructor of the `knitro.Model` object, otherwise a check of the license will be performed when initializing the `knitro.Model` object. + +```python +env = knitro.Env() +model = knitro.Model(env) +``` + +For users who want to release the license immediately after the optimization, you can call the `close` method of all models created and the `knitro.Env` object. + +```python +env = knitro.Env() +model = knitro.Model(env) +# do something with the model +model.close() +env.close() +``` + ## The capability of `knitro.Model` ### Supported constraints @@ -116,3 +133,7 @@ name = model.get_constraint_name(constraint) primal = model.get_constraint_primal(constraint) dual = model.get_constraint_dual(constraint) ``` + +## Support for KNITRO callbacks + +Unfortunately, KNITRO's callback interface is not supported in PyOptInterface at the moment. diff --git a/docs/source/nonlinear.md b/docs/source/nonlinear.md index 7564a7e..a986c6c 100644 --- a/docs/source/nonlinear.md +++ b/docs/source/nonlinear.md @@ -11,7 +11,7 @@ Compared with the linear and quadratic expressions and objectives we have discus :::{note} -Before trying out the code snippets, please ensure that you have completed the installation of PyOptInterface with correct dependencies via `pip install pyoptinterface[nlp]` and solvers that support nonlinear programming (IPOPT, COPT, Xpress, Gurobi) as described in the [Getting Started](getting_started.md) section. +Before trying out the code snippets, please ensure that you have completed the installation of PyOptInterface with correct dependencies via `pip install pyoptinterface[nlp]` and solvers that support nonlinear programming (IPOPT, COPT, Xpress, Gurobi, KNITRO) as described in the [Getting Started](getting_started.md) section. ::: ## Construct nonlinear expressions diff --git a/src/pyoptinterface/_src/knitro.py b/src/pyoptinterface/_src/knitro.py index a073bd7..acba5d7 100644 --- a/src/pyoptinterface/_src/knitro.py +++ b/src/pyoptinterface/_src/knitro.py @@ -221,7 +221,7 @@ def _result_status_knitro(model: "Model"): return ResultStatusCode.INFEASIBLE_POINT return ResultStatusCode.NO_SOLUTION - +# Model Attribute model_attribute_get_func_map = { ModelAttribute.ObjectiveValue: lambda model: model.get_obj_value(), ModelAttribute.ObjectiveSense: lambda model: model.get_obj_sense(),