@@ -43,13 +43,19 @@ function solve(problem::Problem, algorithm::Algorithm; kwargs...)
4343 # obtain logger once to minimize overhead from accessing ScopedValue
4444 # additionally handle logging initialization to enable stateful LoggingAction
4545 logger = algorithm_logger ()
46- # initialize_logger(logger, problem, algorithm, state)
4746
4847 # initialize the state and emit message
4948 state = initialize_state (problem, algorithm; kwargs... )
5049 emit_message (logger, problem, algorithm, state, :Start )
5150
52- return _solve_body! (problem, algorithm, state, logger)
51+ # main loop
52+ state = solve_loop! (problem, algorithm, state)
53+
54+ # emit message about finished state
55+ output = finalize_state! (problem, algorithm, state)
56+ emit_message (logger, problem, algorithm, state, :Stop )
57+
58+ return output
5359end
5460
5561@doc """
@@ -64,34 +70,41 @@ function solve!(problem::Problem, algorithm::Algorithm, state::State; kwargs...)
6470 # obtain logger once to minimize overhead from accessing ScopedValue
6571 # additionally handle logging initialization to enable stateful LoggingAction
6672 logger = algorithm_logger ()
67- # initialize_logger(logger, problem, algorithm, state)
6873
6974 # initialize the state and emit message
7075 initialize_state! (problem, algorithm, state; kwargs... )
7176 emit_message (logger, problem, algorithm, state, :Start )
7277
73- return _solve_body! (problem, algorithm, state, logger)
78+ # main loop
79+ state = solve_loop! (problem, algorithm, state)
80+
81+ # emit message about finished state
82+ output = finalize_state! (problem, algorithm, state)
83+ emit_message (logger, problem, algorithm, state, :Stop )
84+
85+ return output
7486end
7587
76- function _solve_body! (problem:: Problem , algorithm:: Algorithm , state:: State , logger)
77- # main body of the algorithm
88+ """
89+ solve_loop!(problem::Problem, algorithm::Algorithm, state::State)
90+
91+ Provide the main loop of the iterative `algorithm` for a given `problem` and starting `state`.
92+
93+ This loop consists of:
94+ 1. Checking for convergence with [`is_finished!`](@ref)
95+ 2. Incrementing the state [`increment!`](@ref)
96+ 3. Performing a step [`step!`](@ref)
97+ 4. Repeat
98+ """
99+ function solve_loop! (problem:: Problem , algorithm:: Algorithm , state:: State )
100+ logger = algorithm_logger ()
78101 while ! is_finished! (problem, algorithm, state)
79- # logging event between convergence check and algorithm step
80102 emit_message (logger, problem, algorithm, state, :PreStep )
81-
82- # algorithm step
83103 increment! (state)
84104 step! (problem, algorithm, state)
85-
86- # logging event between algorithm step and convergence check
87105 emit_message (logger, problem, algorithm, state, :PostStep )
88106 end
89-
90- # emit message about finished state
91- output = finalize_state! (problem, algorithm, state)
92- emit_message (logger, problem, algorithm, state, :Stop )
93-
94- return output
107+ return state
95108end
96109
97110function step! end
0 commit comments