-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterface.jl
More file actions
65 lines (51 loc) · 2.39 KB
/
interface.jl
File metadata and controls
65 lines (51 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
_doc_init_state = """
state = initialize_state(problem::Problem, algorithm::Algorithm; kwargs...)
state = initialize_state!(state::State, problem::Problem, algorithm::Algorithm; kwargs...)
Initialize a [`State`](@ref) based on a [`Problem`](@ref) and an [`Algorithm`](@ref).
The `kwargs...` should allow to initialize for example the initial point.
This can be done in-place for `state`, then only values that did change have to be provided.
"""
function initialize_state end
@doc "$(_doc_init_state)"
initialize_state(::Problem, ::Algorithm; kwargs...)
function initialize_state! end
@doc "$(_doc_init_state)"
initialize_state!(::Problem, ::Algorithm, ::State; kwargs...)
# has to be defined before used in solve but is documented alphabetically after
@doc """
solve(problem::Problem, algorithm::Algorithm; kwargs...)
Solve the [`Problem`](@ref) using an [`Algorithm`](@ref).
The keyword arguments `kwargs...` have to provide enough details such that
the corresponding state initialisation [`initialize_state`](@ref)`(problem, algorithm)`
returns a state.
By default this method continues to call [`solve!`](@ref).
"""
function solve(problem::Problem, algorithm::Algorithm; kwargs...)
state = initialize_state(problem, algorithm; kwargs...)
return solve!(problem, algorithm, state; kwargs...)
end
@doc """
solve!(problem::Problem, algorithm::Algorithm, state::State; kwargs...)
Solve the [`Problem`](@ref) using an [`Algorithm`](@ref), starting from a given [`State`](@ref).
The state is modified in-place.
All keyword arguments are passed to the [`initialize_state!`](@ref)`(problem, algorithm, state)` function.
"""
function solve!(problem::Problem, algorithm::Algorithm, state::State; kwargs...)
initialize_state!(problem, algorithm, state; kwargs...)
log!(problem, algorithm, state; context = :Start)
while !is_finished!(problem, algorithm, state)
log!(problem, algorithm, state; context = :PreStep)
increment!(state)
step!(problem, algorithm, state)
log!(problem, algorithm, state; context = :PostStep)
end
log!(problem, algorithm, state; context = :Stop)
return state
end
function step! end
@doc """
step!(problem::Problem, algorithm::Algorithm, state::State)
Perform the current step of an [`Algorithm`](@ref) solving a [`Problem`](@ref)
modifying the algorithm's [`State`](@ref).
"""
step!(problem::Problem, algorithm::Algorithm, state::State)