BUG: Honor StopOptimization from IterationEvent in v4 optimizers#6328
Conversation
|
| Filename | Overview |
|---|---|
| Modules/Numerics/Optimizersv4/include/itkExhaustiveOptimizerv4.hxx | Adds m_Stop check after IterationEvent, but calls StopWalking() (which fires EndEvent) even though an observer that called StopWalking() already fired it — resulting in a double EndEvent. |
| Modules/Numerics/Optimizersv4/include/itkOnePlusOneEvolutionaryOptimizerv4.hxx | Adds correct m_Stop guard after IterationEvent; breaks to the single EndEvent call at the bottom of StartOptimization, so EndEvent fires exactly once. |
| Modules/Numerics/Optimizersv4/include/itkPowellOptimizerv4.hxx | Adds correct m_Stop guard after IterationEvent; explicitly fires EndEvent once and returns, consistent with the other early-exit paths in StartOptimization. |
Sequence Diagram
sequenceDiagram
participant Observer
participant ResumeWalking
participant StopWalking
ResumeWalking->>ResumeWalking: InvokeEvent(IterationEvent())
Note over ResumeWalking: observer is notified
ResumeWalking->>Observer: IterationEvent callback
Observer->>StopWalking: "StopWalking() [sets m_Stop=true]"
StopWalking-->>Observer: "InvokeEvent(EndEvent()) fires #1"
Observer-->>ResumeWalking: returns
ResumeWalking->>ResumeWalking: if (m_Stop) — true
ResumeWalking->>StopWalking: StopWalking() [m_Stop already true]
StopWalking-->>ResumeWalking: "InvokeEvent(EndEvent()) fires #2 (bug)"
ResumeWalking->>ResumeWalking: break
Reviews (1): Last reviewed commit: "BUG: Honor StopOptimization from Iterati..." | Re-trigger Greptile
Add an immediate m_Stop check after InvokeEvent(IterationEvent()) in ExhaustiveOptimizerv4, PowellOptimizerv4, and OnePlusOneEvolutionaryOptimizerv4. Previously these optimizers would continue advancing after an observer called StopOptimization() (or StopWalking()) during IterationEvent, making it impossible to halt from a callback. This is the companion change to cf929f2 which added the same pattern to the GradientDescentOptimizerv4 family. All v4 optimizers now consistently stop before taking another step when Stop is requested from an IterationEvent observer.
4faefbe to
ddaffa1
Compare
hjmjohnson
left a comment
There was a problem hiding this comment.
Thank you @blowekamp . I don't see any issues.
|
ITK.Pixi / Pixi-Cxx (windows-2022) failures are un-related to this PR.
Additional improvements inspired by reviewing MSVC cache missins in should provide additional improvements in both disk space allocation and .obj file size. |
b3342c8
into
InsightSoftwareConsortium:main
Summary
Add an immediate
m_Stopcheck afterInvokeEvent(IterationEvent())inExhaustiveOptimizerv4,PowellOptimizerv4, andOnePlusOneEvolutionaryOptimizerv4.Previously these optimizers would continue advancing after an observer called
StopOptimization()(orStopWalking()) duringIterationEvent, making it impossible to halt from a callback.This is the companion change to #6196 (commit cf929f2) which added the same pattern to the
GradientDescentOptimizerv4family.Behavior Table
After this PR, all v4 optimizers that support stopping now behave consistently when
StopOptimization()is called from anIterationEventobserver:GetCurrentIteration()at stopStopOptimization()StopOptimization()StopOptimization()StopOptimization()StopWalking()StopOptimization()StopOptimization()References
Testing/Unit/sitkImageRegistrationMethodTests.cxx—StopRegistration