Skip to content

Commit d258d35

Browse files
arnavk23tmigot
andauthored
Add lin_nnzj and nln_nnzj and docstrings for functions (#500)
* Update api.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update src/nlp/show.jl Co-authored-by: Tangi Migot <[email protected]> * Update src/nlp/show.jl Co-authored-by: Tangi Migot <[email protected]> * Update show.jl * Update show.jl * Update show.jl * Update README.md * Update README.md * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update README.md * Update README.md * Update show.jl * Update show.jl * Update src/nlp/show.jl Co-authored-by: Tangi Migot <[email protected]> * Update src/nlp/show.jl Co-authored-by: Tangi Migot <[email protected]> * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl * Update show.jl --------- Co-authored-by: Tangi Migot <[email protected]>
1 parent 11b0bc6 commit d258d35

File tree

5 files changed

+52
-6
lines changed

5 files changed

+52
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ Attribute | Type | Notes
111111
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
112112
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
113113
`nnzo` | `Int ` | number of nonzeros in the gradient
114-
`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian
115114
`nnzh` | `Int ` | number of nonzeros in the sparse Hessian
115+
`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian
116+
`lin_nnzj` | `Int ` | number of nonzeros in the linear part of sparse Jacobian
117+
`nln_nnzj` | `Int ` | number of nonzeros in the nonlinear part of sparse Jacobian
116118
`minimize` | `Bool ` | true if `optimize == minimize`
117119
`islp` | `Bool ` | true if the problem is a linear program
118120
`name` | `String` | problem name

src/nlp/api.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,30 @@ function hess_op!(
13441344
return LinearOperator{T}(nlp.meta.nvar, nlp.meta.nvar, true, true, prod!, prod!, prod!)
13451345
end
13461346

1347+
"""
1348+
varscale(model::AbstractNLPModel)
1349+
1350+
Return a vector containing the scaling factors for each variable in the model.
1351+
This is typically used to normalize variables for numerical stability in solvers.
1352+
1353+
By default, the scaling is model-dependent. If not overridden by the model, a vector of ones
1354+
is returned. Inspired by the AMPL scaling conventions.
1355+
"""
13471356
function varscale end
1357+
1358+
"""
1359+
lagscale(model::AbstractNLPModel)
1360+
1361+
Return a vector of scaling factors for the Lagrange multipliers associated with constraints.
1362+
This can be used to improve numerical stability or condition number when solving KKT systems.
1363+
"""
13481364
function lagscale end
1365+
1366+
"""
1367+
conscale(model::AbstractNLPModel)
1368+
1369+
Return a vector of constraint scaling factors for the model.
1370+
These are typically used to normalize constraints to have similar magnitudes and improve
1371+
convergence behavior in nonlinear solvers.
1372+
"""
13491373
function conscale end

src/nlp/show.jl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868
6969
Describe `meta` for the `show` function.
7070
"""
71-
function lines_of_description(m::AbstractNLPModelMeta)
71+
function lines_of_description(m::M) where {M <: AbstractNLPModelMeta}
7272
V = [
7373
length(m.ifree),
7474
length(m.ilow),
@@ -93,8 +93,22 @@ function lines_of_description(m::AbstractNLPModelMeta)
9393
V = [sum(V); V]
9494
S = ["All constraints", "free", "lower", "upper", "low/upp", "fixed", "infeas"]
9595
conlines = lines_of_hist(S, V)
96-
push!(conlines, histline("linear", m.nlin, m.ncon), histline("nonlinear", m.nnln, m.ncon))
97-
push!(conlines, sparsityline("nnzj", m.nnzj, m.nvar * m.ncon))
96+
97+
append!(
98+
conlines,
99+
[
100+
histline("linear", m.nlin, m.ncon),
101+
histline("nonlinear", m.nnln, m.ncon),
102+
sparsityline("nnzj", m.nnzj, m.nvar * m.ncon),
103+
],
104+
)
105+
106+
if :lin_nnzj in fieldnames(M)
107+
push!(conlines, sparsityline("lin_nnzj", m.lin_nnzj, m.nlin * m.nvar))
108+
end
109+
if :nln_nnzj in fieldnames(M)
110+
push!(conlines, sparsityline("nln_nnzj", m.nln_nnzj, m.nnln * m.nvar))
111+
end
98112

99113
append!(varlines, repeat([" "^length(varlines[1])], length(conlines) - length(varlines)))
100114
lines = varlines .* conlines

test/nlp/show.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
nnzh: ( 33.33% sparsity) 2 linear: ██████████⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 1
1717
nonlinear: ██████████⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 1
1818
nnzj: ( 0.00% sparsity) 4
19+
lin_nnzj: ( 0.00% sparsity) 2
20+
nln_nnzj: ( 0.00% sparsity) 2
1921
2022
Counters:
2123
obj: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 grad: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 cons: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
@@ -39,7 +41,9 @@
3941
fixed: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 fixed: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
4042
infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 infeas: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
4143
nnzh: ( 0.00% sparsity) 1 linear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
42-
nonlinear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
43-
nnzj: (------% sparsity)\n\n"""
44+
nonlinear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
45+
nnzj: (------% sparsity)
46+
lin_nnzj: (------% sparsity)
47+
nln_nnzj: (------% sparsity)\n\n"""
4448
@test strip.(split(chomp(showed), "\n")) == strip.(split(chomp(expected), "\n"))
4549
end

test/nls/show.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
nnzh: ( 0.00% sparsity) 3 linear: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0
1717
nonlinear: ████████████████████ 3
1818
nnzj: ( 0.00% sparsity) 6
19+
lin_nnzj: (------% sparsity)
20+
nln_nnzj: ( 0.00% sparsity) 6
1921
2022
Counters:
2123
obj: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 grad: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0 cons: ⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅ 0

0 commit comments

Comments
 (0)