Skip to content

Commit

Permalink
Change order of arguments in timelog
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelma committed Dec 5, 2024
1 parent 840757d commit d97c585
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/run_spineopt_basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ function _do_solve_model!(
end
end
_save_window_state(m, k; write_as_roll, resume_file_path)
if @timelog log_level 2 "Rolling $model_name temporal structure...\n" !roll_temporal_structure!(m, k) stats
if @timelog log_level 2 "Rolling $model_name temporal structure...\n" stats !roll_temporal_structure!(m, k)
@log log_level 2 "Rolling complete\n"
break
end
Expand Down Expand Up @@ -638,18 +638,18 @@ function optimize_model!(
# NOTE: The above results in a lot of Warning: Variable connection_flow[...] is mentioned in BOUNDS,
# but is not mentioned in the COLUMNS section.
model_name = _model_name(m)
@timelog log_level 0 "Optimizing $model_name..." optimize!(m) stats
@timelog log_level 0 "Optimizing $model_name..." stats optimize!(m)
termination_st = termination_status(m)
if termination_st in (MOI.OPTIMAL, MOI.TIME_LIMIT)
if result_count(m) > 0
solution_type = termination_st == MOI.OPTIMAL ? "Optimal" : "Feasible"
@log log_level 1 "$solution_type solution found, objective function value: $(objective_value(m))"
m.ext[:spineopt].has_results[] = true
@timelog log_level 2 "Saving $model_name results..." _save_model_results!(m) stats
@timelog log_level 2 "Saving $model_name results..." stats _save_model_results!(m)
calculate_duals && _calculate_duals(m; log_level=log_level)
if save_outputs
@timelog log_level 2 "Postprocessing $model_name results..." postprocess_results!(m) stats
@timelog log_level 2 "Saving $model_name outputs..." _save_outputs!(m, output_suffix) stats
@timelog log_level 2 "Postprocessing $model_name results..." stats postprocess_results!(m)
@timelog log_level 2 "Saving $model_name outputs..." stats _save_outputs!(m, output_suffix)
end
else
m.ext[:spineopt].has_results[] = false
Expand Down Expand Up @@ -1267,12 +1267,14 @@ update constraints and update objective.
function update_model!(m; log_level=3, update_names=false, stats=nothing)
model_name = _model_name(m)
if update_names
@timelog log_level 2 "Updating $model_name variable names..." _update_variable_names!(m) stats
@timelog log_level 2 "Updating $model_name constraint names..." _update_constraint_names!(m) stats
@timelog log_level 2 "Updating $model_name variable names..." stats _update_variable_names!(m)
@timelog log_level 2 "Updating $model_name constraint names..." stats _update_constraint_names!(m)
end
m.ext[:spineopt].has_results[] || return
@timelog log_level 2 "Fixing $model_name history..." _fix_history!(m) stats
@timelog log_level 2 "Applying $model_name non-anticipativity constraints..." apply_non_anticipativity_constraints!(m) stats
@timelog log_level 2 "Fixing $model_name history..." stats _fix_history!(m)
@timelog log_level 2 "Applying $model_name non-anticipativity constraints..." stats begin
apply_non_anticipativity_constraints!(m)
end
end

function _update_variable_names!(m, names=keys(m.ext[:spineopt].variables))
Expand Down
11 changes: 8 additions & 3 deletions src/util/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ end
"""
@timelog(level, threshold, msg, expr)
"""
macro timelog(level, threshold, msg, expr, stats=nothing)
macro timelog(level, threshold, msg, expr)
quote
@timelog $(esc(level)) $(esc(threshold)) $(esc(msg)) nothing $(esc(expr))
end
end
macro timelog(level, threshold, msg, stats, expr)
quote
if $(esc(level)) >= $(esc(threshold))
@timemsg $(esc(msg)) $(esc(expr)) $(esc(stats))
@timemsg $(esc(msg)) $(esc(stats)) $(esc(expr))
else
$(esc(expr))
end
Expand All @@ -45,7 +50,7 @@ end
"""
@timemsg(msg, expr)
"""
macro timemsg(msg, expr, stats=nothing)
macro timemsg(msg, stats, expr)
quote
local msg = $(esc(msg))
local stats = $(esc(stats))
Expand Down

0 comments on commit d97c585

Please sign in to comment.