Skip to content

Add eachstep iterator and implement solve through it - #41

Draft
lkdvos wants to merge 2 commits into
layered-loggingfrom
eachstep
Draft

lkdvos wants to merge 2 commits into
layered-loggingfrom
eachstep

Conversation

@lkdvos

@lkdvos lkdvos commented Nov 6, 2026

Copy link
Copy Markdown
Member

Builds on #40.

This PR adds eachstep(problem, algorithm; kwargs...), which initializes the state and returns an iterator that performs one step per iteration and yields the state.
This allows running arbitrary code in between steps, without having to write a new algorithm or logging action:

iterator = eachstep(problem, algorithm; iterate = x0)
for state in iterator
    state.iteration % 10 == 0 && save_checkpoint(state.iterate)
end
result = finalize_state!(iterator)
  • The loop body runs before the next stopping check, so it may modify the state.
  • Breaking out of the loop keeps the iterator resumable, and finalize_state!(iterator) emits :Stop if needed and returns the result.
  • initialize_state!(iterator; kwargs...) prepares the iterator for another run.
  • solve and solve! are now implemented through this iterator.
  • solve_loop! is deprecated. Since solve no longer calls it, methods added to it have no effect; a custom main loop is now provided by specializing Base.iterate on the iterator.

The docs have a new section on driving the loop yourself.

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.15686% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/interface/iterator.jl 88.57% 4 Missing ⚠️
Files with missing lines Coverage Δ
src/AlgorithmsInterface.jl 100.00% <ø> (ø)
src/deprecated.jl 100.00% <100.00%> (ø)
src/interface/interface.jl 100.00% <100.00%> (ø)
src/interface/iterator.jl 88.57% <88.57%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant