Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
77973b1
batch_* API & dumb VectorBatchNLPModel
klamike Nov 17, 2025
9c82541
add missing SimpleNLPModel methods
klamike Nov 17, 2025
0dedde4
counters
klamike Nov 17, 2025
3d3afd2
cleanup
klamike Nov 18, 2025
14e5608
update
klamike Nov 20, 2025
258b0c1
stubs
klamike Nov 20, 2025
a4866fa
rm comment
klamike Nov 20, 2025
6ae536d
inplace
klamike Nov 20, 2025
cef0863
reduce lambdas
klamike Nov 20, 2025
fe1c38f
no inplace ops, test with parametric simple model
klamike Nov 20, 2025
f531f44
Vararg{Any} -> Vararg{T}
klamike Nov 20, 2025
004308c
simplify inplace syntax
klamike Nov 20, 2025
1e86c69
add todo
klamike Nov 24, 2025
7d2b6c5
1.12 gi
klamike Dec 5, 2025
8640ab2
revert
klamike Dec 5, 2025
8b3b511
try `@eval`
klamike Dec 6, 2025
af377a0
simplify inputs/outputs
klamike Dec 10, 2025
a568e33
back to old API
klamike Dec 10, 2025
b596941
Polish the batch API
amontoison Feb 3, 2026
fe12b7f
Add BatchNLPModelMeta
amontoison Feb 3, 2026
3c4b31b
Update batch_api.jl
amontoison Feb 4, 2026
4cc15f0
Trim a little bit the content of the PR
amontoison Feb 4, 2026
ce91823
Update batch_meta.jl
amontoison Feb 4, 2026
219a196
Apply suggestion from @amontoison
amontoison Feb 4, 2026
ca3cd06
rm new simplenlpmodel methods
klamike Feb 5, 2026
409d24a
nits
klamike Feb 5, 2026
61ecfee
typos
klamike Feb 5, 2026
89a46f6
bugs
klamike Feb 5, 2026
5097824
simple batch model
klamike Feb 5, 2026
16a7d23
tests
klamike Feb 5, 2026
a20cc30
VI -> Vector{Int}
amontoison Feb 5, 2026
26093b5
Fix the tests
amontoison Feb 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
*.jl.mem
docs/build
docs/site
Manifest.toml
Manifest*.toml
2 changes: 2 additions & 0 deletions src/NLPModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ for f in ["utils", "api", "counters", "meta", "show", "tools"]
include("nlp/$f.jl")
include("nls/$f.jl")
end
include("nlp/batch_api.jl")
include("nlp/batch_meta.jl")

end # module
219 changes: 219 additions & 0 deletions src/nlp/batch_api.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
export AbstractBatchNLPModel

export batch_obj, batch_obj!
export batch_grad, batch_grad!
export batch_cons, batch_cons!
export batch_jac_structure, batch_jac_structure!
export batch_hess_structure, batch_hess_structure!
export batch_jac_coord, batch_jac_coord!
export batch_hess_coord, batch_hess_coord!
export batch_jprod, batch_jprod!
export batch_jtprod, batch_jtprod!
export batch_hprod, batch_hprod!

"""
AbstractBatchNLPModel

Abstract base type for batched nonlinear optimization models.

Each model in the batch has the same number of variables and constraints,
and the sparsity patterns of the Jacobian and the Hessian of the Lagrangian are identical across the batch.
"""
abstract type AbstractBatchNLPModel{T, S} end

"""
bf = batch_obj(bnlp, bx)
"""
function batch_obj(bnlp::AbstractBatchNLPModel{T, S}, bx::AbstractVector) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx
bf = S(undef, bnlp.meta.nbatch)
batch_obj!(bnlp, bx, bf)
return bf
end

"""
bf = batch_obj!(bnlp, bx, bf)
"""
function batch_obj! end

"""
bg = batch_grad(bnlp, bx)

This function is only available if `bnlp.meta.grad_available` is set to `true`.
"""
function batch_grad(bnlp::AbstractBatchNLPModel{T, S}, bx::AbstractVector) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx
bg = S(undef, bnlp.meta.nvar * bnlp.meta.nbatch)
batch_grad!(bnlp, bx, bg)
return bg
end

"""
bg = batch_grad!(bnlp, bx, bg)

This function is only available if `bnlp.meta.grad_available` is set to `true`.
"""
function batch_grad! end

"""
bc = batch_cons(bnlp, bx)
"""
function batch_cons(bnlp::AbstractBatchNLPModel{T, S}, bx::AbstractVector) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx
bc = S(undef, bnlp.meta.ncon * bnlp.meta.nbatch)
batch_cons!(bnlp, bx, bc)
return bc
end

"""
bc = batch_cons!(bnlp, bx, bc)
"""
function batch_cons! end

"""
(jrows, jcols) = batch_jac_structure(bnlp)

This function is only available if `bnlp.meta.jac_available` is set to `true`.
"""
function batch_jac_structure(bnlp::AbstractBatchNLPModel{T, S}) where {T, S}
jrows = Vector{Int}(undef, bnlp.meta.nnzj)
jcols = Vector{Int}(undef, bnlp.meta.nnzj)
batch_jac_structure!(bnlp, jrows, jcols)
return (jrows, jcols)
end

"""
(jrows, jcols) = batch_jac_structure!(bnlp, jrows, jcols)

This function is only available if `bnlp.meta.jac_available` is set to `true`.
"""
function batch_jac_structure! end

"""
bjvals = batch_jac_coord(bnlp, bx)

This function is only available if `bnlp.meta.jac_available` is set to `true`.
"""
function batch_jac_coord(bnlp::AbstractBatchNLPModel{T, S}, bx::AbstractVector) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx
bjvals = S(undef, bnlp.meta.nnzj * bnlp.meta.nbatch)
batch_jac_coord!(bnlp, bx, bjvals)
return bjvals
end

"""
bjvals = batch_jac_coord!(bnlp, bx, bjvals)

This function is only available if `bnlp.meta.jac_available` is set to `true`.
"""
function batch_jac_coord! end

"""
bJv = batch_jprod(bnlp, bx, bv)

This function is only available if `bnlp.meta.jprod_available` is set to `true`.
"""
function batch_jprod(bnlp::AbstractBatchNLPModel{T, S}, bx::AbstractVector, bv::AbstractVector) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx bv
bJv = S(undef, bnlp.meta.ncon * bnlp.meta.nbatch)
batch_jprod!(bnlp, bx, bv, bJv)
return bJv
end

"""
bJv = batch_jprod!(bnlp, bx, bv, bJv)

This function is only available if `bnlp.meta.jprod_available` is set to `true`.
"""
function batch_jprod! end

"""
bJtv = batch_jtprod(bnlp, bx, bv)

This function is only available if `bnlp.meta.jtprod_available` is set to `true`.
"""
function batch_jtprod(bnlp::AbstractBatchNLPModel{T, S}, bx::AbstractVector, bv::AbstractVector) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx
@lencheck (bnlp.meta.ncon * bnlp.meta.nbatch) bv
bJtv = S(undef, bnlp.meta.nvar * bnlp.meta.nbatch)
batch_jtprod!(bnlp, bx, bv, bJtv)
return bJtv
end

"""
bJtv = batch_jtprod!(bnlp, bx, bv, bJtv)

This function is only available if `bnlp.meta.jtprod_available` is set to `true`.
"""
function batch_jtprod! end

"""
(hrows, hcols) = batch_hess_structure(bnlp)

This function is only available if `bnlp.meta.hess_available` is set to `true`.
"""
function batch_hess_structure(bnlp::AbstractBatchNLPModel{T,S}) where {T, S}
hrows = Vector{Int}(undef, bnlp.meta.nnzh)
hcols = Vector{Int}(undef, bnlp.meta.nnzh)
batch_hess_structure!(bnlp, hrows, hcols)
return hrows, hcols
end

"""
(hrows, hcols) = batch_hess_structure!(bnlp, hrows, hcols)

This function is only available if `bnlp.meta.hess_available` is set to `true`.
"""
function batch_hess_structure! end

"""
bhvals = batch_hess_coord(bnlp, bx, by, bobj_weight)

This function is only available if `bnlp.meta.hess_available` is set to `true`.
"""
function batch_hess_coord(
bnlp::AbstractBatchNLPModel{T, S},
bx::AbstractVector,
by::AbstractVector,
bobj_weight::AbstractVector,
) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx
@lencheck (bnlp.meta.ncon * bnlp.meta.nbatch) by
@lencheck bnlp.meta.nbatch bobj_weight
bhvals = S(undef, bnlp.meta.nnzh * bnlp.meta.nbatch)
return batch_hess_coord!(bnlp, bx, by, bobj_weight, bhvals)
end

"""
bhvals = batch_hess_coord!(bnlp, bx, by, bobj_weight, bhvals)

This function is only available if `bnlp.meta.hess_available` is set to `true`.
"""
function batch_hess_coord! end

"""
bHv = batch_hprod(bnlp, bx, by, bv, bobj_weight)

This function is only available if `bnlp.meta.hprod_available` is set to `true`.
"""
function batch_hprod(
bnlp::AbstractBatchNLPModel{T, S},
bx::AbstractVector,
by::AbstractVector,
bv::AbstractVector,
bobj_weight::AbstractVector,
) where {T, S}
@lencheck (bnlp.meta.nvar * bnlp.meta.nbatch) bx bv
@lencheck (bnlp.meta.ncon * bnlp.meta.nbatch) by
@lencheck bnlp.meta.nbatch bobj_weight
bHv = S(undef, bnlp.meta.nvar * bnlp.meta.nbatch)
batch_hprod!(bnlp, bx, by, bv, bobj_weight, bHv)
return bHv
end

"""
bHv = batch_hprod!(bnlp, bx, by, bv, bobj_weight, bHv)

This function is only available if `bnlp.meta.hprod_available` is set to `true`.
"""
function batch_hprod! end
Loading
Loading