Skip to content

Commit

Permalink
Merge branch 'main' into error-unconstrained
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Aug 12, 2024
2 parents 21cb8aa + 82100be commit 6f53439
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 38 deletions.
7 changes: 1 addition & 6 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ task:
matrix:
- name: FreeBSD
freebsd_instance:
image_family: freebsd-13-2
image_family: freebsd-13-3
env:
matrix:
- JULIA_VERSION: 1.6
Expand All @@ -12,11 +12,6 @@ task:
image: alpine:3.14
env:
- JULIA_VERSION: 1
- name: MacOS M1
macos_instance:
image: ghcr.io/cirruslabs/macos-monterey-base:latest
env:
- JULIA_VERSION: 1
install_script: |
URL="https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh"
set -x
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/breakage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ jobs:
"JuliaSmoothOptimizers/SolverBenchmark.jl",
"JuliaSmoothOptimizers/SolverCore.jl",
"JuliaSmoothOptimizers/SolverTest.jl",
"JuliaSmoothOptimizers/SolverTools.jl"
"JuliaSmoothOptimizers/SolverTools.jl",
"MadNLP/MadNLP.jl",
"exanauts/ExaModels.jl"
]
pkgversion: [latest, stable]

steps:
- uses: actions/checkout@v2

# Install Julia
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: 1
arch: x64
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ jobs:
fail-fast: false
matrix:
version: ['1.6', '1']
os: [ubuntu-latest, macOS-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
arch: [x64]
allow_failure: [false]
include:
- version: '1'
os: macos-latest
arch: arm64
allow_failure: false
- version: 'nightly'
os: ubuntu-latest
arch: x64
allow_failure: true
- version: 'nightly'
os: macOS-latest
os: macos-latest
arch: x64
allow_failure: true
- version: 'nightly'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.jl.mem
docs/build
docs/site
Manifest.toml
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "NLPModels"
uuid = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
version = "0.21.1"
version = "0.21.3"

[deps]
FastClosures = "9aa1b823-49e4-5ca5-8b0f-3971ec8bab6a"
Expand Down
5 changes: 3 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"

[compat]
ADNLPModels = "0.7"
Documenter = "~0.27"
ADNLPModels = "0.8"
Documenter = "1.0"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ makedocs(
modules = [NLPModels],
doctest = true,
linkcheck = true,
strict = true,
format = Documenter.HTML(
assets = ["assets/style.css"],
prettyurls = get(ENV, "CI", nothing) == "true",
size_threshold_ignore = ["reference.md"],
),
sitename = "NLPModels.jl",
pages = [
Expand Down
4 changes: 2 additions & 2 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Namely,
- ``\nabla f(x)``, the gradient of ``f`` at the point ``x``;
- ``\nabla^2 f(x)``, the Hessian of ``f`` at the point ``x``;
- ``J(x) = \nabla c(x)^T``, the Jacobian of ``c`` at the point ``x``;
- ``\nabla^2 f(x) + \sum_{i=1}^m \lambda_i \nabla^2 c_i(x)``,
the Hessian of the Lagrangian function at the point ``(x,\lambda)``.
- ``\nabla^2 f(x) + \sum_{i=1}^m y_i \nabla^2 c_i(x)``,
the Hessian of the Lagrangian function at the point ``(x,y)``.

There are many ways to access some of these values, so here is a little
reference guide.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ There are about 30 functions in the NLPModels API, and a few with more than one
Luckily, many have a default implementation.
We collect here the list of functions that should be implemented for a complete API.

Here, the following notation apply:
Here, the following notation applies:
- `nlp` is your instance of `MyModel <: AbstractNLPModel`
- `x` is the point where the function is evaluated
- `y` is the vector of Lagrange multipliers (for constrained problems only)
Expand Down Expand Up @@ -143,4 +143,4 @@ Furthermore, the `show` method has to be updated with the correct direction of `
## [Advanced tests](@id advanced-tests)

We have created the package [NLPModelsTest.jl](https://github.com/JuliaSmoothOptimizers/NLPModelsTest.jl) which defines test functions and problems.
To make sure that your model is robust, we recommend using that package.
To make sure that your model is robust, we recommend using it in the test suite of your package.
16 changes: 8 additions & 8 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ The general form of the optimization problem is
```math
\begin{aligned}
\min \quad & f(x) \\
& c_i(x) = 0, \quad i \in E, \\
& c_{L_i} \leq c_i(x) \leq c_{U_i}, \quad i \in I, \\
& c_i(x) = c_{E_i}, \quad i \in {\cal E}, \\
& c_{L_i} \leq c_i(x) \leq c_{U_i}, \quad i \in {\cal I}, \\
& \ell \leq x \leq u,
\end{aligned}
```
where ``f:\mathbb{R}^n\rightarrow\mathbb{R}``,
``c:\mathbb{R}^n\rightarrow\mathbb{R}^m``,
``E\cup I = \{1,2,\dots,m\}``, ``E\cap I = \emptyset``,
``{\cal E}\cup {\cal I} = \{1,2,\dots,m\}``, ``{\cal E}\cap {\cal I} = \emptyset``,
and
``c_{L_i}, c_{U_i}, \ell_j, u_j \in \mathbb{R}\cup\{\pm\infty\}``
``c_{E_i}, c_{L_i}, c_{U_i}, \ell_j, u_j \in \mathbb{R}\cup\{\pm\infty\}``
for ``i = 1,\dots,m`` and ``j = 1,\dots,n``.

For computational reasons, we write
Expand All @@ -31,13 +31,13 @@ For computational reasons, we write
& \ell \leq x \leq u,
\end{aligned}
```
defining ``c_{L_i} = c_{U_i}`` for all ``i \in E``.
defining ``c_{L_i} = c_{U_i} = c_{E_i}`` for all ``i \in {\cal E}``.
The Lagrangian of this problem is defined as
```math
L(x,\lambda,z^L,z^U;\sigma) = \sigma f(x) + c(x)^T\lambda + \sum_{i=1}^n z_i^L(x_i-l_i) + \sum_{i=1}^nz_i^U(u_i-x_i),
L(x,y,z^L,z^U;\sigma) = \sigma f(x) + c(x)^T y + \sum_{i=1}^n z_{L_i}(x_i-l_i) + \sum_{i=1}^n z_{U_i}(u_i-x_i),
```
where ``\sigma`` is a scaling parameter included for computational reasons.
Notice that, for the Hessian, the variables ``z^L`` and ``z^U`` are not used.
Since the final two sums are linear in ``x``, the variables ``z_L`` and ``z_U`` do not appear in the Hessian ``\nabla^2 L(x,y)``.

Optimization problems are represented by an instance/subtype of `AbstractNLPModel`.
Such instances are composed of
Expand All @@ -48,7 +48,7 @@ Such instances are composed of

## Nonlinear Least Squares

A special type of `NLPModels` are the `NLSModels`, i.e., Nonlinear Least
A special subtype of `AbstractNLPModel` is `AbstractNLSModel`, i.e., Nonlinear Least
Squares models. In these problems, the function ``f(x)`` is given by
``\tfrac{1}{2}\Vert F(x)\Vert^2``, where ``F`` is referred as the residual function.
The individual value of ``F``, as well as of its derivatives, is also
Expand Down
4 changes: 2 additions & 2 deletions docs/src/models.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Models

The following is a list of packages implement the NLPModels API.
The following is a list of packages implementing the NLPModels API.

If you want your package listed here, open a Pull Request.

Expand All @@ -19,7 +19,7 @@ If you want to create your own interface, check these [Guidelines](@ref).
- [NLPModelsJuMP.jl](https://github.com/JuliaSmoothOptimizers/NLPModelsJuMP.jl):
For problems modeled using [JuMP.jl](https://github.com/jump-dev/JuMP.jl).
- [QuadraticModels.jl](https://github.com/JuliaSmoothOptimizers/QuadraticModels.jl):
For problems with quadratic and linear structure.
For problems with linear constraints and a quadratic objective (LCQP).
- [LLSModels.jl](https://github.com/JuliaSmoothOptimizers/LLSModels.jl):
Creates a linear least squares model.
- [PDENLPModels.jl](https://github.com/JuliaSmoothOptimizers/PDENLPModels.jl):
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ neval_obj(nlp)

Some counters are available for all models, some are specific. In
particular, there are additional specific counters for the nonlinear
least squares models.
least squares models (the ones with `residual` below).

| Counter | Description |
|---|---|
Expand Down Expand Up @@ -62,7 +62,7 @@ sum_counters(nlp)

## Querying problem type

There are some variable for querying the problem type:
There are some utility functions for querying the problem type:

- [`has_bounds`](@ref): True when not all variables are free.
- [`bound_constrained`](@ref): True for problems with bounded variables
Expand Down
5 changes: 2 additions & 3 deletions src/nlp/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ Evaluate ``f(x)`` and ``c(x)`` at `x`.
function objcons(nlp::AbstractNLPModel{T, S}, x::AbstractVector) where {T, S}
@lencheck nlp.meta.nvar x
check_constrained(nlp)
f = obj(nlp, x)
c = cons(nlp, x)
return f, c
c = S(undef, nlp.meta.ncon)
return objcons!(nlp, x, c)
end

"""
Expand Down
58 changes: 54 additions & 4 deletions src/nlp/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Some of their components may be infinite to indicate that the corresponding boun
---
NLPModelMeta(nvar; kwargs...)
NLPModelMeta(nvar::Integer; kwargs...)
NLPModelMeta(meta::AbstractNLPModelMeta; kwargs...)
Create an `NLPModelMeta` with `nvar` variables.
Alternatively, create an `NLPModelMeta` copy from another `AbstractNLPModelMeta`.
The following keyword arguments are accepted:
- `x0`: initial guess
- `lvar`: vector of lower bounds
Expand All @@ -50,7 +52,7 @@ The following keyword arguments are accepted:
- `islp`: true if the problem is a linear program
- `name`: problem name
`NLPModelMeta` also contains the following attributes:
`NLPModelMeta` also contains the following attributes, which are computed from the variables above:
- `nvar`: number of variables
- `ifix`: indices of fixed variables
- `ilow`: indices of variables with lower bound only
Expand Down Expand Up @@ -129,7 +131,7 @@ function NLPModelMeta{T, S}(
nnzo = nvar,
nnzj = nvar * ncon,
lin_nnzj = 0,
nln_nnzj = nvar * ncon,
nln_nnzj = nnzj - lin_nnzj,
nnzh = nvar * (nvar + 1) / 2,
lin = Int[],
minimize = true,
Expand All @@ -143,6 +145,7 @@ function NLPModelMeta{T, S}(
@lencheck nvar x0 lvar uvar
@lencheck ncon y0 lcon ucon
@rangecheck 1 ncon lin
@assert nnzj == lin_nnzj + nln_nnzj

ifix = findall(lvar .== uvar)
ilow = findall((lvar .> T(-Inf)) .& (uvar .== T(Inf)))
Expand Down Expand Up @@ -213,9 +216,56 @@ function NLPModelMeta{T, S}(
)
end

NLPModelMeta(nvar; x0::S = zeros(nvar), kwargs...) where {S} =
NLPModelMeta(nvar::Int; x0::S = zeros(nvar), kwargs...) where {S} =
NLPModelMeta{eltype(S), S}(nvar, x0 = x0; kwargs...)

function NLPModelMeta(
meta::AbstractNLPModelMeta{T, S};
nvar::Int = meta.nvar,
x0::S = meta.x0,
lvar::S = meta.lvar,
uvar::S = meta.uvar,
nlvb = meta.nlvb,
nlvo = meta.nlvo,
nlvc = meta.nlvc,
ncon = meta.ncon,
y0::S = meta.y0,
lcon::S = meta.lcon,
ucon::S = meta.ucon,
nnzo = meta.nnzo,
nnzj = meta.nnzj,
lin_nnzj = meta.lin_nnzj,
nln_nnzj = meta.nln_nnzj,
nnzh = meta.nnzh,
lin = meta.lin,
minimize = meta.minimize,
islp = meta.islp,
name = meta.name,
) where {T, S}
NLPModelMeta{T, S}(
nvar,
x0 = x0,
lvar = lvar,
uvar = uvar,
nlvb = nlvb,
nlvo = nlvo,
nlvc = nlvc,
ncon = ncon,
y0 = y0,
lcon = lcon,
ucon = ucon,
nnzo = nnzo,
nnzj = nnzj,
lin_nnzj = lin_nnzj,
nln_nnzj = nln_nnzj,
nnzh = nnzh,
lin = lin,
minimize = minimize,
islp = islp,
name = name,
)
end

"""
reset_data!(nlp)
Expand Down
8 changes: 8 additions & 0 deletions src/nlp/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,13 @@ macro default_counters(Model, inner)
end))
push!(ex.args, :(NLPModels.increment!(nlp::$(esc(Model)), s::Symbol) = increment!(nlp.$inner, s)))
push!(ex.args, :(NLPModels.decrement!(nlp::$(esc(Model)), s::Symbol) = decrement!(nlp.$inner, s)))

push!(
ex.args,
:(
Base.getproperty(nlp::$(esc(Model)), s::Symbol) =
(s == :counters ? nlp.$inner.counters : getfield(nlp, s))
),
)
ex
end
2 changes: 1 addition & 1 deletion src/nls/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following keyword arguments are accepted:
- `nnzh`: number of elements needed to store the nonzeros of the sum of Hessians of the residuals
- `lin`: indices of linear residuals
`NLSMeta` also contains the following attributes:
`NLSMeta` also contains the following attributes, which are computed from the variables above:
- `nequ`: size of the residual
- `nvar`: number of variables
- `nln`: indices of nonlinear residuals
Expand Down
27 changes: 27 additions & 0 deletions test/nlp/meta.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
@testset "A problem with zero variables doesn't make sense." begin
@test_throws ErrorException NLPModelMeta(0)
end

@testset "Meta copier." begin
nlp = SimpleNLPModel()

# Check simple copy
meta = NLPModelMeta(nlp.meta)
for field in fieldnames(typeof(nlp.meta))
@test getfield(nlp.meta, field) == getfield(meta, field)
end

modif = Dict(
:nnzh => 1,
:x0 => [2.0; 2.0; 0.0],
:nvar => 3,
:lvar => zeros(3),
:uvar => [1.0; 1.0; 0.0],
)
meta = NLPModelMeta(nlp.meta; modif...)

for field in setdiff(fieldnames(typeof(nlp.meta)), union(keys(modif), [:ifix]))
@test getfield(nlp.meta, field) == getfield(meta, field)
end
for field in keys(modif)
@test getfield(meta, field) == modif[field]
end
@test meta.ifix == [3]
end
1 change: 1 addition & 0 deletions test/nlp/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ end
nlp = SuperNLPModel{Float64, Vector{Float64}}(SimpleNLPModel())
increment!(nlp, :neval_obj)
@test neval_obj(nlp.model) == 1
@test nlp.counters == nlp.model.counters
end

0 comments on commit 6f53439

Please sign in to comment.