Skip to content

Commit 5ffb5af

Browse files
committed
introduce a stopped_at function for solver states.
1 parent 0e7305a commit 5ffb5af

7 files changed

Lines changed: 27 additions & 4 deletions

File tree

Changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ The file was started with Version `0.4`.
66
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
77
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [0.5.36] April 24, 2026
10+
11+
### Added
12+
13+
* a function `stopped_at(state)` to access the number of iterations it took a solver to stop.
14+
15+
### Fixed
16+
17+
* a small bug where `get_count(sc::StopWhenAny, Val(:Iteration))` wrongly reported it stopped before the first iteration when it actually did not yet stop.
18+
919
## [0.5.35] April 16, 2026
1020

1121
### Changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Manopt"
22
uuid = "0fc0a36d-df90-57f3-8f93-d78a9fc72bb5"
3-
version = "0.5.35"
3+
version = "0.5.36"
44
authors = [{family-names = "Bergmann", given-names = "Ronny", alias = "kellertuer", city = "Trondheim", affiliation = "Norwegian University of Science and Technology", country = "NO", email = "manopt@ronnybergmann.net", orcid = "https://orcid.org/0000-0001-8342-7218", website = "https://ronnybergmann.net"}]
55

66
[workspace]

src/Manopt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export StopAfter,
587587
StopWhenSwarmVelocityLess,
588588
StopWhenTrustRegionIsExceeded
589589
export get_active_stopping_criteria,
590-
get_stopping_criteria, get_reason, get_stopping_criterion
590+
get_stopping_criteria, get_reason, get_stopping_criterion, stopped_at
591591
#
592592
# Exports
593593
export asymptote_export_S2_signals, asymptote_export_S2_data, asymptote_export_SPD

src/plans/solver_state.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,18 @@ Make a copy of tangent vector `X` from manifold `M` for storage in [`StoreStateA
329329
_storage_copy_vector(M::AbstractManifold, X) = copy(M, X)
330330
_storage_copy_vector(::AbstractManifold, X::Number) = StorageRef(X)
331331

332+
@doc """
333+
stopped_at(state::AbstractManoptSolverState)
334+
335+
Return the number of iterations the solver represented by the `state` took to stop.
336+
If the solver has not yet stopped, this function returns `-1`.
337+
338+
By default, this function calls `get_count` function on the state's stopping criterion to access its `:Iteration` count.
339+
"""
340+
function stopped_at(state::AbstractManoptSolverState)
341+
return get_count(get_stopping_criterion(state), Val(:Iterations))
342+
end
343+
332344
@doc """
333345
StoreStateAction <: AbstractStateAction
334346

src/plans/stopping_criterion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1181,7 +1181,7 @@ function has_converged(c::StopWhenAny)
11811181
end
11821182
function get_count(c::StopWhenAny, v::Val{:Iterations})
11831183
iters = filter(x -> x > 0, [get_count(ci, v) for ci in c.criteria])
1184-
(length(iters) == 0) && (return 0)
1184+
(length(iters) == 0) && (return -1) # None indicated to stop yet, so we also do not
11851185
return minimum(iters)
11861186
end
11871187
function show(io::IO, c::StopWhenAny)

test/plans/test_gradient_plan.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using ManifoldsBase, Manopt, Test
1616
stopping_criterion = StopAfterIteration(20),
1717
stepsize = Manopt.ConstantStepsize(M),
1818
)
19+
@test stopped_at(gst) == -1
1920
set_iterate!(gst, M, q)
2021
@test get_iterate(gst) == q
2122
set_gradient!(gst, M, p, [1.0, 0.0])

test/plans/test_state.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct NoIterateState <: AbstractManoptSolverState end
7272
@test_throws ErrorException get_iterate(s2)
7373
end
7474

75-
@testset "Iteration and Gradient setters" begin
75+
@testset "Iterate and Gradient setters" begin
7676
M = Euclidean(3)
7777
s1 = NelderMeadState(M)
7878
s2 = GradientDescentState(M)

0 commit comments

Comments
 (0)