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

CompatHelper: bump compat for SolverCore to 0.3, (keep existing compat) #222

Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MINLPTests = "~0.5"
MadNLPTests = "~0.3"
MathOptInterface = "1"
NLPModels = "~0.17.2, 0.18, 0.19"
SolverCore = "~0.1,~0.2"
SolverCore = "~0.3"
julia = "1.6"

[extras]
Expand Down
42 changes: 18 additions & 24 deletions src/IPM/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ function madnlp(model::AbstractNLPModel; kwargs...)
return solve!(solver)
end

function solve!(
model::AbstractNLPModel,
solver::MadNLPSolver,
nlp::AbstractNLPModel;
x = get_x0(nlp),
y = get_y0(nlp),
zl= nothing,
zu= nothing,
solve!(nlp::AbstractNLPModel, solver::AbstractMadNLPSolver; kwargs...) = solve!(
nlp, solver, MadNLPExecutionStats(solver);
kwargs...)
solve!(solver::AbstractMadNLPSolver; kwargs...) = solve!(
solver.nlp, solver;
kwargs...)

@assert solver.nlp == nlp

solve!(
solver;
x = x, y = y,
zl = zl, zu = zu,
kwargs...
)
end

function initialize!(solver::AbstractMadNLPSolver{T}) where T
# initializing slack variables
Expand Down Expand Up @@ -110,23 +98,25 @@ end

# major loops ---------------------------------------------------------
function solve!(
solver::AbstractMadNLPSolver;
nlp::AbstractNLPModel,
solver::AbstractMadNLPSolver,
stats::MadNLPExecutionStats;
x = nothing, y = nothing,
zl = nothing, zu = nothing,
kwargs...
)

if x != nothing
solver.x[1:get_nvar(solver.nlp)] .= x
solver.x[1:get_nvar(nlp)] .= x
end
if y != nothing
solver.y[1:get_ncon(solver.nlp)] .= y
solver.y[1:get_ncon(nlp)] .= y
end
if zl != nothing
solver.zl[1:get_nvar(solver.nlp)] .= zl
solver.zl[1:get_nvar(nlp)] .= zl
end
if zu != nothing
solver.zu[1:get_nvar(solver.nlp)] .= zu
solver.zu[1:get_nvar(nlp)] .= zu
end

if !isempty(kwargs)
Expand Down Expand Up @@ -184,8 +174,12 @@ function solve!(
solver.opt.disable_garbage_collector &&
(GC.enable(true); @warn(solver.logger,"Julia garbage collector is turned back on"))
finalize(solver.logger)

update!(stats,solver)
end
return MadNLPExecutionStats(solver)


return stats
end


Expand Down
24 changes: 17 additions & 7 deletions src/IPM/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct MadNLPExecutionStats{T} <: AbstractExecutionStats
mutable struct MadNLPExecutionStats{T} <: AbstractExecutionStats
status::Status
solution::Vector{T}
objective::T
Expand All @@ -13,11 +13,6 @@ struct MadNLPExecutionStats{T} <: AbstractExecutionStats
elapsed_time::Real
end

struct InvalidNumberException <: Exception
callback::Symbol
end
struct NotEnoughDegreesOfFreedomException <: Exception end

MadNLPExecutionStats(solver::MadNLPSolver) =MadNLPExecutionStats(
solver.status,
_madnlp_unsafe_wrap(solver.x, get_nvar(solver.nlp)),
Expand All @@ -29,10 +24,26 @@ MadNLPExecutionStats(solver::MadNLPSolver) =MadNLPExecutionStats(
solver.cnt.k, get_counters(solver.nlp),solver.cnt.total_time
)

function update!(stats::MadNLPExecutionStats, solver::MadNLPSolver)
stats.status = solver.status
stats.objective = solver.obj_val
stats.dual_feas = solver.inf_du
stats.primal_feas = solver.inf_pr
stats.iter = solver.cnt.k
stats.elapsed_time = solver.cnt.total_time
return stats
end

get_counters(nlp::NLPModels.AbstractNLPModel) = nlp.counters
get_counters(nlp::NLPModels.AbstractNLSModel) = nlp.counters.counters
getStatus(result::MadNLPExecutionStats) = STATUS_OUTPUT_DICT[result.status]

# Exceptions
struct InvalidNumberException <: Exception
callback::Symbol
end
struct NotEnoughDegreesOfFreedomException <: Exception end

# Utilities
has_constraints(solver) = solver.m != 0

Expand Down Expand Up @@ -181,4 +192,3 @@ function string(solver::AbstractMadNLPSolver)
end
print(io::IO,solver::AbstractMadNLPSolver) = print(io, string(solver))
show(io::IO,solver::AbstractMadNLPSolver) = print(io,solver)

2 changes: 1 addition & 1 deletion src/MadNLP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Base: string, show, print, size, getindex, copyto!, @kwdef
import SuiteSparse: UMFPACK
import NLPModels
import NLPModels: finalize, AbstractNLPModel, obj, grad!, cons!, jac_coord!, hess_coord!, hess_structure!, jac_structure!, NLPModelMeta, get_nvar, get_ncon, get_minimize, get_x0, get_y0, get_nnzj, get_nnzh, get_lvar, get_uvar, get_lcon, get_ucon, Counters as _Counters # get_zl,get_zu
import SolverCore: AbstractExecutionStats, getStatus
import SolverCore: solve!, getStatus, AbstractOptimizationSolver, AbstractExecutionStats

const MOI = MathOptInterface
const MOIU = MathOptInterface.Utilities
Expand Down