Skip to content

Commit 6bb3f18

Browse files
committed
Refactor interface to have problem, algorithm, state
1 parent 7aa39b7 commit 6bb3f18

1 file changed

Lines changed: 31 additions & 32 deletions

File tree

src/interface/interface.jl

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
_doc_init_state = """
2-
s = initialize_state(p::Problem, a::Algorithm; kwargs...)
3-
initialize_state!(s::State, p::Problem, a::Algorithm; kwargs...)
2+
state = initialize_state(problem::Problem, algorithm::Algorithm; kwargs...)
3+
state = initialize_state!(state::State, problem::Problem, algorithm::Algorithm; kwargs...)
44
5-
Initialize a [`State`](@ref) `s` base on a [`Problem`](@ref) `p` and an [`Algorithm`](@ref).
5+
Initialize a [`State`](@ref) based on a [`Problem`](@ref) and an [`Algorithm`](@ref).
66
The `kwargs...` should allow to initialize for example the initial point.
7-
This can be done in-place of `s`, then only values that did change have to be provided.
7+
This can be done in-place for `state`, then only values that did change have to be provided.
88
"""
99

1010
function initialize_state end
@@ -15,59 +15,58 @@ initialize_state(::Problem, ::Algorithm; kwargs...)
1515
function initialize_state! end
1616

1717
@doc "$(_doc_init_state)"
18-
initialize_state!(::State, ::Problem, ::Algorithm; kwargs...)
18+
initialize_state!(::Problem, ::Algorithm, ::State; kwargs...)
1919

2020
@doc """
21-
is_finished(p::Problem, a::Algorithm, s::State)
21+
is_finished(problem::Problem, algorithm::Algorithm, state::State) -> Bool
2222
23-
Return `true` if the [`Algorithm`](@ref) `a` solving the [`Problem`](@ref) `p`
24-
with current [`State`](@ref) `s` is finished
23+
Return `true` if the [`Algorithm`](@ref) solving the [`Problem`](@ref) at the current [`State`](@ref) is finished.
2524
"""
26-
function is_finished(p::Problem, a::Algorithm, s::State)
27-
scs = get_stopping_criterion_state(s)
28-
sc = get_stopping_criterion(a)
29-
return scs(p, a, s, sc)
25+
function is_finished(problem::Problem, algorithm::Algorithm, state::State)
26+
scs = get_stopping_criterion_state(state)
27+
sc = get_stopping_criterion(algorithm)
28+
return scs(problem, algorithm, state, sc)
3029
end
3130

3231
# has to be defined before used in solve but is documented alphabetically after
3332

3433
@doc """
35-
solve(p::Problem, a::Algorithm; kwargs...)
34+
solve(problem::Problem, algorithm::Algorithm; kwargs...)
3635
37-
Solve the [`Problem`](@ref) `p` using the [`Algorithm`](@ref) `a`.
36+
Solve the [`Problem`](@ref) using an [`Algorithm`](@ref).
3837
The keyword arguments `kwargs...` have to provide enough details such that
39-
the corresponding state initialisation [`initialize_state`](@ref)`(p,a)`
38+
the corresponding state initialisation [`initialize_state`](@ref)`(problem, algorithm)`
4039
returns a state.
4140
4241
By default this method continues to call [`solve!`](@ref).
4342
"""
44-
function solve(p::Problem, a::Algorithm; kwargs...)
45-
s = initialize_state(p, a; kwargs...)
46-
return solve!(s, p, a; kwargs...)
43+
function solve(problem::Problem, algorithm::Algorithm; kwargs...)
44+
state = initialize_state(problem, algorithm; kwargs...)
45+
return solve!(state, problem, algorithm; kwargs...)
4746
end
4847

4948
@doc """
50-
solve!(p::Problem, a::Algorithm, s::State; kwargs...)
49+
solve!(problem::Problem, algorithm::Algorithm, state::State; kwargs...)
5150
52-
Solve the [`Problem`](@ref) `p` using the [`Algorithm`](@ref) `a`
53-
modifying on the [`State`](@ref).
51+
Solve the [`Problem`](@ref) using an [`Algorithm`](@ref), starting from a given [`State`](@ref).
52+
The state is modified in-place.
5453
55-
All keyword arguments are passed to the [`initialize_state!`](@ref)`(s, p, a)` function.
54+
All keyword arguments are passed to the [`initialize_state!`](@ref)`(problem, algorithm, state)` function.
5655
"""
57-
function solve!(s::State, p::Problem, a::Algorithm; kwargs...)
58-
initialize_state!(s, p, a; kwargs...)
59-
while !is_finished(p, a, s)
60-
increment!(s)
61-
step!(p, a, s)
56+
function solve!(problem::Problem, algorithm::Algorithm, state::State; kwargs...)
57+
initialize_state!(problem, algorithm, state; kwargs...)
58+
while !is_finished(problem, algorithm, state)
59+
increment!(state)
60+
step!(problem, algorithm, state)
6261
end
63-
return s
62+
return state
6463
end
6564

6665
function step! end
6766
@doc """
68-
step!(s::State, p::Problem, a::Algorithm)
67+
step!(problem::Problem, algorithm::Algorithm, state::State)
6968
70-
Perform the current step of an [`Algorithm`](@ref) `a` solving [`Problem`](@ref) `p`
71-
modifying the algorithms [`State`](@ref) `s`.
69+
Perform the current step of an [`Algorithm`](@ref) solving a [`Problem`](@ref)
70+
modifying the algorithm's [`State`](@ref).
7271
"""
73-
step!(s::State, p::Problem, a::Algorithm)
72+
step!(problem::Problem, algorithm::Algorithm, state::State)

0 commit comments

Comments
 (0)