https://github.com/juliasmoothoptimizers/adnlpmodels.jl
https://github.com/juliasmoothoptimizers/adnlpmodels.jl
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/juliasmoothoptimizers/adnlpmodels.jl
- Owner: JuliaSmoothOptimizers
- License: other
- Created: 2021-03-14T12:59:50.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-06-04T23:19:02.000Z (about 1 year ago)
- Last Synced: 2025-06-05T03:30:02.647Z (about 1 year ago)
- Language: Julia
- Size: 54 MB
- Stars: 40
- Watchers: 4
- Forks: 17
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Citation: CITATION.cff
- Zenodo: .zenodo.json
Awesome Lists containing this project
README
# ADNLPModels
[](https://doi.org/10.5281/zenodo.4605982)
[](https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl/releases/latest)
[](https://JuliaSmoothOptimizers.github.io/ADNLPModels.jl/stable)
[](https://JuliaSmoothOptimizers.github.io/ADNLPModels.jl/dev)
[](https://codecov.io/gh/JuliaSmoothOptimizers/ADNLPModels.jl)

[](https://cirrus-ci.com/github/JuliaSmoothOptimizers/ADNLPModels.jl)
This package provides automatic differentiation (AD)-based model implementations that conform to the [NLPModels](https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl) API.
The general form of the optimization problem is
```math
\begin{aligned}
\min \quad & f(x) \\
& c_L \leq c(x) \leq c_U \\
& \ell \leq x \leq u,
\end{aligned}
```
## How to Cite
If you use ADNLPModels.jl in your work, please cite using the format given in [CITATION.bib](https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl/blob/main/CITATION.bib).
## Installation
ADNLPModels is a
Julia Language
package. To install ADNLPModels,
please open
Julia's interactive session (known as REPL) and press ] key in the REPL to use the package mode, then type the following command
```julia
pkg> add ADNLPModels
```
## Examples
For optimization in the general form, this package exports two constructors `ADNLPModel` and `ADNLPModel!`.
```julia
using ADNLPModels
f(x) = 100 * (x[2] - x[1]^2)^2 + (x[1] - 1)^2
T = Float64
x0 = T[-1.2; 1.0]
# Rosenbrock
nlp = ADNLPModel(f, x0) # unconstrained
lvar, uvar = zeros(T, 2), ones(T, 2) # must be of same type than `x0`
nlp = ADNLPModel(f, x0, lvar, uvar) # bound-constrained
c(x) = [x[1] + x[2]]
lcon, ucon = -T[0.5], T[0.5]
nlp = ADNLPModel(f, x0, lvar, uvar, c, lcon, ucon) # constrained
c!(cx, x) = begin
cx[1] = x[1] + x[2]
return cx
end
nlp = ADNLPModel!(f, x0, lvar, uvar, c!, lcon, ucon) # in-place constrained
```
It is possible to distinguish between linear and nonlinear constraints, see [](https://JuliaSmoothOptimizers.github.io/ADNLPModels.jl/stable).
This package also exports the constructors `ADNLSModel` and `ADNLSModel!` for Nonlinear Least Squares (NLS), i.e. when the objective function is a sum of squared terms.
```julia
using ADNLPModels
F(x) = [10 * (x[2] - x[1]^2); x[1] - 1]
nequ = 2 # length of Fx
T = Float64
x0 = T[-1.2; 1.0]
# Rosenbrock in NLS format
nlp = ADNLSModel(F, x0, nequ)
```
The resulting models, `ADNLPModel` and `ADNLSModel`, are instances of `AbstractNLPModel` and implement the NLPModel API, see [NLPModels.jl](https://github.com/JuliaSmoothOptimizers/NLPModels.jl).
We refer to the documentation for more details on the resulting models, and you can find tutorials on [jso.dev/tutorials/](https://jso.dev/tutorials/) and select the tag `ADNLPModel.jl`.
## AD backend
The following AD packages are supported:
- `ForwardDiff.jl`;
- `ReverseDiff.jl`;
and as optional dependencies (you must load the package before):
- `Enzyme.jl`;
- `Zygote.jl`.
## Bug reports and discussions
If you think you found a bug, feel free to open an [issue](https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl/issues).
Focused suggestions and requests can also be opened as issues. Before opening a pull request, start an issue or a discussion on the topic, please.
If you want to ask a question not suited for a bug report, feel free to start a discussion [here](https://github.com/JuliaSmoothOptimizers/Organization/discussions). This forum is for general discussion about this repository and the [JuliaSmoothOptimizers](https://github.com/JuliaSmoothOptimizers), so questions about any of our packages are welcome.