Test that control checkpoints survive recompute (fixes #5082)#5093
Open
sghelichkhani wants to merge 1 commit into
Open
Test that control checkpoints survive recompute (fixes #5082)#5093sghelichkhani wants to merge 1 commit into
sghelichkhani wants to merge 1 commit into
Conversation
The clear-down assertions in _check_forward, _check_recompute, and _check_reverse swept every block variable and required _checkpoint to be None after recompute. That codified the pre-fix behaviour where the checkpoint manager would silently clobber the control's checkpoint during forward replay. Now that the manager goes through the BlockVariable setter and respects the is_control guard, the control's block variable legitimately retains the user-supplied value across replays. The helpers now take an optional list of controls and skip those block variables. Also add a regression test for #5082: a 4-step model with J = sum(m**2) evaluated at m0 = 2 must have derivative 16 (the bug produced 8 because the adjoint replay saw the original m = 1).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Companion to dolfin-adjoint/pyadjoint#257, which fixes the underlying bug in
CheckpointManagerwhere direct writes toBlockVariable._checkpointbypassed theis_controlguard and wiped the user-supplied control value during forward replay. With that pyadjoint fix in place the control's checkpoint now legitimately survives across replays, which makes two changes necessary here.The first is that
_check_forward,_check_recomputeand_check_reverseintests/firedrake/adjoint/test_burgers_newton.pywere asserting that every block-variable checkpoint must beNoneafter replay. That assertion codified the buggy behaviour — under the fix, the control's block variable correctly retains its checkpoint between calls torf(new_value)andrf.derivative(). The helpers now take an optional list of controls (accepting eitherControlobjects or the underlying overloaded variables) and skip those block variables in the clear-down sweeps. All existing call sites intest_burgers_newton.pyandtest_checkpointing_multistep.pyare updated to thread the controls through.The second is a regression test
test_control_value_survives_recomputeintest_checkpointing_multistep.pythat captures Steph's MFE from #5082 directly: four timesteps ofJ = sum_k m**2, evaluated atm0 = 2, must give a derivative of16. Before the pyadjoint fix this returned8because the adjoint replay saw the stale underlyingm = 1.Depends on dolfin-adjoint/pyadjoint#257 — without it the new regression test will fail.