Skip to content

Add keyword arguments to fixedpoint for hasconverged and shouldstop stopping criteria#397

Merged
pbrehmer merged 7 commits into
mainfrom
pb-stopping-criteria
Jul 3, 2026
Merged

Add keyword arguments to fixedpoint for hasconverged and shouldstop stopping criteria#397
pbrehmer merged 7 commits into
mainfrom
pb-stopping-criteria

Conversation

@pbrehmer

Copy link
Copy Markdown
Collaborator

This PR adds the possibility for customized converging and stopping criteria through OptimKit's hasconverged and shouldstop keyword arguments. This can be very usefu e.g.l if one would like to do early stopping of an optimization based on converging energies or if the optimization gets stuck in linesearching and thereby produces vanishing energy differences.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/algorithms/optimization/peps_optimization.jl 94.73% <100.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread test/examples/heisenberg.jl
Comment on lines +177 to +179
# default stopping criteria initialized on alg parameters that have to be select first
isnothing(hasconverged) && (hasconverged = OptimKit.DefaultHasConverged(alg.optimizer_alg.gradtol))
isnothing(shouldstop) && (shouldstop = OptimKit.DefaultShouldStop(alg.optimizer_alg.maxiter))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit annoying. Can we get around this by not setting any default kwarg values at all here, deleting (; finalize!, hasconverged, shouldstop) from the kwargs passed to select_algorithm, and then do the opposite (only retain (; finalize!, hasconverged, shouldstop)) and when returning fixedpoint(operator, peps₀, env₀, alg; kwargs...)? Or would this be just as annoying?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave this a go and I think I prefer your suggestion. It's still a bit annoying having to filter the kwargs but I think it's less annoying that way and saves lines.

Comment thread src/algorithms/select_algorithm.jl Outdated
Comment on lines +170 to +172
extra_kwarg_keys = (:finalize!, :hasconverged, :shouldstop) # these will not be passed to `select_algorithm`, only to the 2nd `fixedpoint` call
alg = select_algorithm(fixedpoint, env₀; filter(kw -> !(first(kw) in extra_kwarg_keys), kwargs)...)
return fixedpoint(operator, peps₀, env₀, alg; filter(kw -> first(kw) in extra_kwarg_keys, kwargs)...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not beautiful, but I think it's slightly less hacky than setting the nothing defaults first and then replacing them.

Maybe @lkdvos can give an independent opinion?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I can come up with much better, the only alternative I could think off is to explicitly put the optimization keywords into the alg, so we don't have to peel them but I think this is probably fine?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that but was ultimately against it because I felt that having Functions as fields could become annoying.

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a small suggestion for the example, and @leburgel's comment about kwargs seems to not be resolved yet, otherwise good to go for me!

Comment thread test/examples/heisenberg.jl Outdated
@pbrehmer pbrehmer merged commit a302ce0 into main Jul 3, 2026
125 of 127 checks passed
@pbrehmer pbrehmer deleted the pb-stopping-criteria branch July 3, 2026 14:59
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.

3 participants