Skip to content

Commit f18fc61

Browse files
committed
avoid double initialize_state call in solve
1 parent b639b69 commit f18fc61

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

src/interface/interface.jl

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,33 @@ returns a state.
4040
By default this method continues to call [`solve!`](@ref).
4141
"""
4242
function solve(problem::Problem, algorithm::Algorithm; kwargs...)
43+
# obtain logger once to minimize overhead from accessing ScopedValue
44+
# additionally handle logging initialization to enable stateful LoggingAction
45+
logger = algorithm_logger()
46+
# initialize_logger(logger, problem, algorithm, state)
47+
48+
# initialize the state and emit message
4349
state = initialize_state(problem, algorithm; kwargs...)
44-
return solve!(problem, algorithm, state; kwargs...)
50+
emit_message(logger, problem, algorithm, state, :Start)
51+
52+
# main body of the algorithm
53+
while !is_finished!(problem, algorithm, state)
54+
# logging event between convergence check and algorithm step
55+
emit_message(logger, problem, algorithm, state, :PreStep)
56+
57+
# algorithm step
58+
increment!(state)
59+
step!(problem, algorithm, state)
60+
61+
# logging event between algorithm step and convergence check
62+
emit_message(logger, problem, algorithm, state, :PostStep)
63+
end
64+
65+
# emit message about finished state
66+
output = finalize_state!(problem, algorithm, state)
67+
emit_message(logger, problem, algorithm, state, :Stop)
68+
69+
return output
4570
end
4671

4772
@doc """

0 commit comments

Comments
 (0)