From 4b6d2bba7532325c66879c1567775d9822ad5a37 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 1 Dec 2025 19:40:03 +1300 Subject: [PATCH 1/5] Add availability flags in NLPModelMeta --- docs/src/index.md | 73 +++++++++++++++++++++++++---------------------- src/nlp/meta.jl | 39 ++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 38 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 7f5b1bcf..75837b9d 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -79,40 +79,45 @@ 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 +`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 objective or Lagrangian `H * v` is available ## License diff --git a/src/nlp/meta.jl b/src/nlp/meta.jl index ab3d0ea4..e7126848 100644 --- a/src/nlp/meta.jl +++ b/src/nlp/meta.jl @@ -51,6 +51,11 @@ The following keyword arguments are accepted: - `minimize`: true if optimize == minimize - `islp`: true if the problem is a linear program - `name`: problem name +- `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 objective or Lagrangian `H * v` is available `NLPModelMeta` also contains the following attributes, which are computed from the variables above: - `nvar`: number of variables @@ -114,6 +119,12 @@ struct NLPModelMeta{T, S} <: AbstractNLPModelMeta{T, S} minimize::Bool islp::Bool name::String + + jacobian_available::Bool + hessian_available::Bool + Jv_available::Bool + Jtv_available::Bool + Hv_available::Bool end function NLPModelMeta{T, S}( @@ -134,9 +145,14 @@ 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", + 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 +229,11 @@ function NLPModelMeta{T, S}( minimize, islp, name, + jacobian_available, + hessian_available, + Jv_available, + Jtv_available, + Hv_available, ) end @@ -238,9 +259,14 @@ 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, + 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 +289,11 @@ function NLPModelMeta( minimize = minimize, islp = islp, name = name, + jacobian_available = jacobian_available, + hessian_available = hessian_available, + Jv_available = Jv_available, + Jtv_available = Jtv_available, + Hv_available = Hv_available, ) end From 734bd93899797b7a7c62e0813136ed3b99c1fdce Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 1 Dec 2025 20:16:34 +1300 Subject: [PATCH 2/5] Also add a flag for the gradient --- docs/src/index.md | 3 ++- src/nlp/meta.jl | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 75837b9d..70bfe679 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -113,11 +113,12 @@ Attribute | Type | Notes `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 objective or Lagrangian `H * 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 e7126848..1232fdfd 100644 --- a/src/nlp/meta.jl +++ b/src/nlp/meta.jl @@ -51,11 +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 objective or Lagrangian `H * 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 @@ -120,6 +121,7 @@ struct NLPModelMeta{T, S} <: AbstractNLPModelMeta{T, S} islp::Bool name::String + gradient_available::Bool jacobian_available::Bool hessian_available::Bool Jv_available::Bool @@ -148,6 +150,7 @@ function NLPModelMeta{T, S}( minimize::Bool = true, islp::Bool = false, name = "Generic", + gradient_available::Bool = true, jacobian_available::Bool = true, hessian_available::Bool = true, Jv_available::Bool = true, @@ -229,6 +232,7 @@ function NLPModelMeta{T, S}( minimize, islp, name, + gradient_available, jacobian_available, hessian_available, Jv_available, @@ -262,6 +266,7 @@ function NLPModelMeta( 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, @@ -289,6 +294,7 @@ function NLPModelMeta( minimize = minimize, islp = islp, name = name, + gradient_available = gradient_available, jacobian_available = jacobian_available, hessian_available = hessian_available, Jv_available = Jv_available, From 77714b1fada8f732a04b7dbb0ad6f4884a3dd682 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 1 Dec 2025 21:16:30 +1300 Subject: [PATCH 3/5] Update NLSMeta --- src/nls/meta.jl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/nls/meta.jl b/src/nls/meta.jl index 5862cc09..d14c2edd 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 From 7d8d4d2cb1365a937592f9c2ec378d8a663a22d7 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 1 Dec 2025 21:21:26 +1300 Subject: [PATCH 4/5] Fix typo --- src/nls/meta.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/nls/meta.jl b/src/nls/meta.jl index d14c2edd..fc9276e7 100644 --- a/src/nls/meta.jl +++ b/src/nls/meta.jl @@ -53,11 +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 + 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) From 3b83db2e1ff981183ec04af08f43999676b8623a Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Mon, 1 Dec 2025 22:32:07 +1300 Subject: [PATCH 5/5] Update README.md --- README.md | 74 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 34 deletions(-) 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