Skip to content

Commit

Permalink
Merge pull request #1051 from NREL-Sienna/jd/xpress_patch
Browse files Browse the repository at this point in the history
add xpress patch
  • Loading branch information
jd-lara authored Feb 9, 2024
2 parents d993157 + 0a15ae6 commit d807a50
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/core/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const NO_SERVICE_NAME_PROVIDED = ""
const CONTAINER_KEY_EMPTY_META = ""
const UPPER_BOUND = "ub"
const LOWER_BOUND = "lb"
const MAX_OPTIMIZE_TRIES = 2

# File Names definitions
const PROBLEM_SERIALIZATION_FILENAME = "operation_problem.bin"
Expand Down
52 changes: 39 additions & 13 deletions src/core/optimization_container.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,35 @@ function solve_impl!(container::OptimizationContainer, system::PSY.System)
optimizer_stats = get_optimizer_stats(container)

jump_model = get_jump_model(container)
_,
optimizer_stats.timed_solve_time,
optimizer_stats.solve_bytes_alloc,
optimizer_stats.sec_in_gc = @timed JuMP.optimize!(jump_model)
model_status = JuMP.primal_status(jump_model)
if model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
@error "Optimizer returned $model_status"
if get_calculate_conflict(get_settings(container))
compute_conflict!(container)

model_status = MOI.NO_SOLUTION::MOI.ResultStatusCode
conflict_status = MOI.COMPUTE_CONFLICT_NOT_CALLED

try_count = 0
while model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
_,
optimizer_stats.timed_solve_time,
optimizer_stats.solve_bytes_alloc,
optimizer_stats.sec_in_gc = @timed JuMP.optimize!(jump_model)
model_status = JuMP.primal_status(jump_model)

if model_status != MOI.FEASIBLE_POINT::MOI.ResultStatusCode
if get_calculate_conflict(get_settings(container))
@warn "Optimizer returned $model_status computing conflict"
conflict_status = compute_conflict!(container)
if conflict_status == MOI.CONFLICT_FOUND
return RunStatus.FAILED
end
else
@warn "Optimizer returned $model_status trying optimize! again"
end

try_count += 1
if try_count > MAX_OPTIMIZE_TRIES
@error "Optimizer returned $model_status after $MAX_OPTIMIZE_TRIES optimize! attempts"
return RunStatus.FAILED
end
end
return RunStatus.FAILED
end

status = RunStatus.SUCCESSFUL
Expand All @@ -699,13 +717,19 @@ end

function compute_conflict!(container::OptimizationContainer)
jump_model = get_jump_model(container)
settings = get_settings(container)
JuMP.unset_silent(jump_model)
jump_model.is_model_dirty = false
conflict = container.infeasibility_conflict
try
JuMP.compute_conflict!(jump_model)
if MOI.get(jump_model, MOI.ConflictStatus()) != MOI.CONFLICT_FOUND
@error "No conflict could be found for the model. $(MOI.get(jump_model, MOI.ConflictStatus()))"
conflict_status = MOI.get(jump_model, MOI.ConflictStatus())
if conflict_status != MOI.CONFLICT_FOUND
@error "No conflict could be found for the model. Status: $conflict_status"
if !get_optimizer_solve_log_print(settings)
JuMP.set_silent(jump_model)
end
return conflict_status
end

for (key, field_container) in get_constraints(container)
Expand All @@ -718,6 +742,8 @@ function compute_conflict!(container::OptimizationContainer)
end
end
@error "$(conflict)"

return conflict_status
catch e
jump_model.is_model_dirty = true
if isa(e, MethodError)
Expand All @@ -727,7 +753,7 @@ function compute_conflict!(container::OptimizationContainer)
end
end

return
return MOI.NO_CONFLICT_EXISTS
end

function write_optimizer_stats!(container::OptimizationContainer)
Expand Down
2 changes: 2 additions & 0 deletions src/core/optimizer_stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mutable struct OptimizerStats
has_duals::Bool
# Candidate solution
objective_bound::Union{Missing, Float64}
relative_gap::Union{Missing, Float64}
# Use missing instead of nothing so that CSV writting doesn't fail
dual_objective_value::Union{Missing, Float64}
# Work counters
Expand Down Expand Up @@ -37,6 +38,7 @@ function OptimizerStats()
false,
missing,
missing,
missing,
NaN,
missing,
missing,
Expand Down
1 change: 0 additions & 1 deletion src/operation/decision_model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ function solve!(
@info "\n$(RUN_OPERATION_MODEL_TIMER)\n"
catch e
@error "Decision Problem solve failed" exception = (e, catch_backtrace())
# TODO: Run IIS here if the solve called failed
set_run_status!(model, RunStatus.FAILED)
end
end
Expand Down
4 changes: 4 additions & 0 deletions src/operation/operation_model_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ function solve_impl!(model::OperationModel)
settings = get_settings(model)
model_name = get_name(model)
ts = get_current_timestamp(model)
output_dir = get_output_dir(model)
infeasible_opt_path = joinpath(output_dir, "infeasible_$(model_name)_$(ts).json")
serialize_optimization_model(container, infeasible_opt_path)
@error("Infeasible Problem Serialized at $(infeasible_opt_path)")
if !get_allow_fails(settings)
error("Solving model $(model_name) failed at $(ts)")
else
Expand Down
1 change: 1 addition & 0 deletions src/utils/jump_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ function _summary_to_dict!(optimizer_stats::OptimizerStats, jump_model::JuMP.Mod
:objective_bound, # Union{Missing,Float64}
:dual_objective_value, # Union{Missing,Float64}
# Work counters
:relative_gap, # Union{Missing,Int}
:barrier_iterations, # Union{Missing,Int}
:simplex_iterations, # Union{Missing,Int}
:node_count, # Union{Missing,Int}
Expand Down

0 comments on commit d807a50

Please sign in to comment.