diff --git a/README.md b/README.md index 1368a61b..2d118a28 100644 --- a/README.md +++ b/README.md @@ -84,40 +84,46 @@ The complete list of methods that an interface may implement can be found in the `NLPModelMeta` objects have the following attributes (with `S <: AbstractVector`): -Attribute | Type | Notes -------------|--------------------|------------------------------------ -`nvar` | `Int ` | number of variables -`x0 ` | `S` | initial guess -`lvar` | `S` | vector of lower bounds -`uvar` | `S` | vector of upper bounds -`ifix` | `Vector{Int}` | indices of fixed variables -`ilow` | `Vector{Int}` | indices of variables with lower bound only -`iupp` | `Vector{Int}` | indices of variables with upper bound only -`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range) -`ifree` | `Vector{Int}` | indices of free variables -`iinf` | `Vector{Int}` | indices of visibly infeasible bounds -`ncon` | `Int ` | total number of general constraints -`nlin ` | `Int ` | number of linear constraints -`nnln` | `Int ` | number of nonlinear general constraints -`y0 ` | `S` | initial Lagrange multipliers -`lcon` | `S` | vector of constraint lower bounds -`ucon` | `S` | vector of constraint upper bounds -`lin ` | `Vector{Int}` | indices of linear constraints -`nln` | `Vector{Int}` | indices of nonlinear constraints -`jfix` | `Vector{Int}` | indices of equality constraints -`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl -`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu -`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu -`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any) -`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints -`nnzo` | `Int ` | number of nonzeros in the gradient -`nnzh` | `Int ` | number of nonzeros in the sparse Hessian -`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian -`lin_nnzj` | `Int ` | number of nonzeros in the linear part of sparse Jacobian -`nln_nnzj` | `Int ` | number of nonzeros in the nonlinear part of sparse Jacobian -`minimize` | `Bool ` | true if `optimize == minimize` -`islp` | `Bool ` | true if the problem is a linear program -`name` | `String` | problem name +Attribute | Type | Notes +---------------------|---------------|------------------------------------ +`nvar` | `Int` | number of variables +`x0 ` | `S` | initial guess +`lvar` | `S` | vector of lower bounds +`uvar` | `S` | vector of upper bounds +`ifix` | `Vector{Int}` | indices of fixed variables +`ilow` | `Vector{Int}` | indices of variables with lower bound only +`iupp` | `Vector{Int}` | indices of variables with upper bound only +`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range) +`ifree` | `Vector{Int}` | indices of free variables +`iinf` | `Vector{Int}` | indices of visibly infeasible bounds +`ncon` | `Int` | total number of general constraints +`nlin ` | `Int` | number of linear constraints +`nnln` | `Int` | number of nonlinear general constraints +`y0 ` | `S` | initial Lagrange multipliers +`lcon` | `S` | vector of constraint lower bounds +`ucon` | `S` | vector of constraint upper bounds +`lin ` | `Vector{Int}` | indices of linear constraints +`nln` | `Vector{Int}` | indices of nonlinear constraints +`jfix` | `Vector{Int}` | indices of equality constraints +`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl +`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu +`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu +`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any) +`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints +`nnzo` | `Int` | number of nonzeros in the gradient +`nnzj` | `Int` | number of nonzeros in the sparse Jacobian +`lin_nnzj` | `Int` | number of nonzeros in the sparse linear constraints Jacobian +`nln_nnzj` | `Int` | number of nonzeros in the sparse nonlinear constraints Jacobian +`nnzh` | `Int` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian +`minimize` | `Bool` | true if `optimize == minimize` +`islp` | `Bool` | true if the problem is a linear program +`name` | `String` | problem name +`gradient_available` | `Bool` | true if the gradient of the objective is available +`jacobian_available` | `Bool` | true if the sparse Jacobian of the constraints is available +`hessian_available` | `Bool` | true if the sparse Hessian of the Lagrangian is available +`Jv_available` | `Bool` | true if the Jacobian-vector product `J * v` is available +`Jtv_available` | `Bool` | true if the transpose Jacobian-vector product `J' * v` is available +`Hv_available` | `Bool` | true if the Hessian-vector product of the Lagrangian `H * v` is available # Bug reports and discussions diff --git a/docs/src/index.md b/docs/src/index.md index 7f5b1bcf..70bfe679 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -79,40 +79,46 @@ See the [Models](@ref), the [Tools](@ref tools-section), or the [API](@ref). `NLPModelMeta` objects have the following attributes (with `S <: AbstractVector`): -Attribute | Type | Notes -------------|--------------------|------------------------------------ -`nvar` | `Int ` | number of variables -`x0 ` | `S` | initial guess -`lvar` | `S` | vector of lower bounds -`uvar` | `S` | vector of upper bounds -`ifix` | `Vector{Int}` | indices of fixed variables -`ilow` | `Vector{Int}` | indices of variables with lower bound only -`iupp` | `Vector{Int}` | indices of variables with upper bound only -`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range) -`ifree` | `Vector{Int}` | indices of free variables -`iinf` | `Vector{Int}` | indices of visibly infeasible bounds -`ncon` | `Int ` | total number of general constraints -`nlin ` | `Int ` | number of linear constraints -`nnln` | `Int ` | number of nonlinear general constraints -`y0 ` | `S` | initial Lagrange multipliers -`lcon` | `S` | vector of constraint lower bounds -`ucon` | `S` | vector of constraint upper bounds -`lin ` | `Vector{Int}` | indices of linear constraints -`nln` | `Vector{Int}` | indices of nonlinear constraints -`jfix` | `Vector{Int}` | indices of equality constraints -`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl -`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu -`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu -`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any) -`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints -`nnzo` | `Int ` | number of nonzeros in the gradient -`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian -`lin_nnzj` | `Int ` | number of nonzeros in the sparse linear constraints Jacobian -`nln_nnzj` | `Int ` | number of nonzeros in the sparse nonlinear constraints Jacobian -`nnzh` | `Int ` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian -`minimize` | `Bool ` | true if `optimize == minimize` -`islp` | `Bool ` | true if the problem is a linear program -`name` | `String` | problem name +Attribute | Type | Notes +---------------------|---------------|------------------------------------ +`nvar` | `Int` | number of variables +`x0 ` | `S` | initial guess +`lvar` | `S` | vector of lower bounds +`uvar` | `S` | vector of upper bounds +`ifix` | `Vector{Int}` | indices of fixed variables +`ilow` | `Vector{Int}` | indices of variables with lower bound only +`iupp` | `Vector{Int}` | indices of variables with upper bound only +`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range) +`ifree` | `Vector{Int}` | indices of free variables +`iinf` | `Vector{Int}` | indices of visibly infeasible bounds +`ncon` | `Int` | total number of general constraints +`nlin ` | `Int` | number of linear constraints +`nnln` | `Int` | number of nonlinear general constraints +`y0 ` | `S` | initial Lagrange multipliers +`lcon` | `S` | vector of constraint lower bounds +`ucon` | `S` | vector of constraint upper bounds +`lin ` | `Vector{Int}` | indices of linear constraints +`nln` | `Vector{Int}` | indices of nonlinear constraints +`jfix` | `Vector{Int}` | indices of equality constraints +`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl +`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu +`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu +`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any) +`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints +`nnzo` | `Int` | number of nonzeros in the gradient +`nnzj` | `Int` | number of nonzeros in the sparse Jacobian +`lin_nnzj` | `Int` | number of nonzeros in the sparse linear constraints Jacobian +`nln_nnzj` | `Int` | number of nonzeros in the sparse nonlinear constraints Jacobian +`nnzh` | `Int` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian +`minimize` | `Bool` | true if `optimize == minimize` +`islp` | `Bool` | true if the problem is a linear program +`name` | `String` | problem name +`gradient_available` | `Bool` | true if the gradient of the objective is available +`jacobian_available` | `Bool` | true if the sparse Jacobian of the constraints is available +`hessian_available` | `Bool` | true if the sparse Hessian of the Lagrangian is available +`Jv_available` | `Bool` | true if the Jacobian-vector product `J * v` is available +`Jtv_available` | `Bool` | true if the transpose Jacobian-vector product `J' * v` is available +`Hv_available` | `Bool` | true if the Hessian-vector product of the Lagrangian `H * v` is available ## License diff --git a/src/nlp/meta.jl b/src/nlp/meta.jl index ab3d0ea4..1232fdfd 100644 --- a/src/nlp/meta.jl +++ b/src/nlp/meta.jl @@ -51,6 +51,12 @@ The following keyword arguments are accepted: - `minimize`: true if optimize == minimize - `islp`: true if the problem is a linear program - `name`: problem name +- `gradient_available`: indicates whether the gradient of the objective is available +- `jacobian_available`: indicates whether the sparse Jacobian of the constraints is available +- `hessian_available`: indicates whether the sparse Hessian of the Lagrangian is available +- `Jv_available`: indicates whether the Jacobian-vector product `J * v` is available +- `Jtv_available`: indicates whether the transpose Jacobian-vector product `J' * v` is available +- `Hv_available`: indicates whether the Hessian-vector product of the Lagrangian `H * v` is available `NLPModelMeta` also contains the following attributes, which are computed from the variables above: - `nvar`: number of variables @@ -114,6 +120,13 @@ struct NLPModelMeta{T, S} <: AbstractNLPModelMeta{T, S} minimize::Bool islp::Bool name::String + + gradient_available::Bool + jacobian_available::Bool + hessian_available::Bool + Jv_available::Bool + Jtv_available::Bool + Hv_available::Bool end function NLPModelMeta{T, S}( @@ -134,9 +147,15 @@ function NLPModelMeta{T, S}( nln_nnzj = nnzj - lin_nnzj, nnzh = nvar * (nvar + 1) / 2, lin = Int[], - minimize = true, - islp = false, + minimize::Bool = true, + islp::Bool = false, name = "Generic", + gradient_available::Bool = true, + jacobian_available::Bool = true, + hessian_available::Bool = true, + Jv_available::Bool = true, + Jtv_available::Bool = true, + Hv_available::Bool = true, ) where {T, S} if (nvar < 1) || (ncon < 0) error("Nonsensical dimensions") @@ -213,6 +232,12 @@ function NLPModelMeta{T, S}( minimize, islp, name, + gradient_available, + jacobian_available, + hessian_available, + Jv_available, + Jtv_available, + Hv_available, ) end @@ -238,9 +263,15 @@ function NLPModelMeta( nln_nnzj = meta.nln_nnzj, nnzh = meta.nnzh, lin = meta.lin, - minimize = meta.minimize, - islp = meta.islp, + minimize::Bool = meta.minimize, + islp::Bool = meta.islp, name = meta.name, + gradient_available::Bool = meta.gradient_available, + jacobian_available::Bool = meta.jacobian_available, + hessian_available::Bool = meta.hessian_available, + Jv_available::Bool = meta.Jv_available, + Jtv_available::Bool = meta.Jtv_available, + Hv_available::Bool = meta.Hv_available, ) where {T, S} NLPModelMeta{T, S}( nvar, @@ -263,6 +294,12 @@ function NLPModelMeta( minimize = minimize, islp = islp, name = name, + gradient_available = gradient_available, + jacobian_available = jacobian_available, + hessian_available = hessian_available, + Jv_available = Jv_available, + Jtv_available = Jtv_available, + Hv_available = Hv_available, ) end diff --git a/src/nls/meta.jl b/src/nls/meta.jl index 5862cc09..fc9276e7 100644 --- a/src/nls/meta.jl +++ b/src/nls/meta.jl @@ -15,6 +15,11 @@ The following keyword arguments are accepted: - `nnzj`: number of elements needed to store the nonzeros of the Jacobian of the residual - `nnzh`: number of elements needed to store the nonzeros of the sum of Hessians of the residuals - `lin`: indices of linear residuals +- `jacobian_residual_available`: indicates whether the sparse Jacobian of the residuals is available +- `hessian_residual_available`: indicates whether the sum of the sparse Hessians of the residuals is available +- `Jv_residual_available`: indicates whether the Jacobian-vector product for the residuals is available +- `Jtv_residual_available`: indicates whether the transpose Jacobian-vector product for the residuals is available +- `Hv_residual_available`: indicates whether the sum of Hessian-vector product for the residuals is available `NLSMeta` also contains the following attributes, which are computed from the variables above: - `nequ`: size of the residual @@ -35,6 +40,12 @@ struct NLSMeta{T, S} lin::Vector{Int} # List of linear residuals nlin::Int # = length(lin) + jacobian_residual_available::Bool + hessian_residual_available::Bool + Jv_residual_available::Bool + Jtv_residual_available::Bool + Hv_residual_available::Bool + function NLSMeta{T, S}( nequ::Int, nvar::Int; @@ -42,6 +53,11 @@ struct NLSMeta{T, S} nnzj = nequ * nvar, nnzh = div(nvar * (nvar + 1), 2), lin = Int[], + jacobian_residual_available::Bool = true, + hessian_residual_available::Bool = true, + Jv_residual_available::Bool = true, + Jtv_residual_available::Bool = true, + Hv_residual_available::Bool = true, ) where {T, S} nnzj = max(0, nnzj) nnzh = max(0, nnzh) @@ -50,7 +66,9 @@ struct NLSMeta{T, S} nlin = length(lin) nnln = length(nln) - return new{T, S}(nequ, nvar, x0, nnzj, nnzh, nln, nnln, lin, nlin) + return new{T, S}(nequ, nvar, x0, nnzj, nnzh, nln, nnln, lin, nlin, + jacobian_residual_available, hessian_residual_available, Jv_residual_available, + Jtv_residual_available, Hv_residual_available) end end