Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new constructor for custom KKT type #232

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/IPM/IPM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ function MadNLPSolver(nlp::AbstractNLPModel{T}; kwargs...) where T
return MadNLPSolver{T,KKTSystem}(nlp, opt_ipm, opt_linear_solver; logger=logger)
end

# Constructor for unregistered KKT systems
function MadNLPSolver{T, KKTSystem}(nlp::AbstractNLPModel{T}; options...) where {T, KKTSystem}
opt_ipm, opt_linear_solver, logger = load_options(; options...)
@assert is_supported(opt_ipm.linear_solver, T)
return MadNLPSolver{T,KKTSystem}(nlp, opt_ipm, opt_linear_solver; logger=logger)
end

# Inner constructor
function MadNLPSolver{T,KKTSystem}(
nlp::AbstractNLPModel,
Expand Down
10 changes: 9 additions & 1 deletion test/madnlp_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ end
end
end

@testset "MadNLP: custom KKT constructor" begin
T, VT, MT = Float64, Vector{Float64}, Matrix{Float64}
nlp = MadNLPTests.DenseDummyQP{T}(; n=10, m=5)
KKT = MadNLP.DenseKKTSystem{T, VT, MT}
solver = MadNLPSolver{T, KKT}(nlp; linear_solver=LapackCPUSolver)
@test isa(solver.kkt, KKT)
end

@testset "MadNLP: restart (PR #113)" begin
n, m = 10, 5
nlp = MadNLPTests.DenseDummyQP(; n=n, m=m)
Expand All @@ -133,7 +141,7 @@ end

solver = MadNLPSolver(nlp; sparse_options...)
MadNLP.solve!(solver)

# Restart (should hit MadNLP.reinitialize function)
res = MadNLP.solve!(solver)
@test solver.status == MadNLP.SOLVE_SUCCEEDED
Expand Down