Don't use saved_output to create checkpoints for timesteps #206
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.
We have a few blocks,
T
(the BC function) <-AssignBlock
(for T += 1), <-DirichletBCBlock
<-AssignBlock
<-DirichletBCBlock
. At the end of timestep 0 (or the beginning of timestep 1), we have the first 3 of these blocks on tape. During theadd_dependency
phase of the solve, theDirichletBCBlock
was also checkpointed, so its associated block variable has a_checkpoint
member which is just theT
function (https://github.com/firedrakeproject/firedrake/blob/a9f2c621633f0e56c69c9ab42c6f2343051f4839/firedrake/adjoint_utils/dirichletbc.py#L36-L43)Now, when timestep 1 is due to begin, the
process_taping
method checkpoints all the blocks:pyadjoint/pyadjoint/checkpointing.py
Lines 203 to 204 in 0b13480
This process goes through the
saved_output
property:pyadjoint/pyadjoint/tape.py
Lines 839 to 840 in 0b13480
Let's consider when
var
here is the block variable associated with theDirichletBC
. Thesaved_output
property will use the existing checkpoint:pyadjoint/pyadjoint/block_variable.py
Lines 57 to 62 in 0b13480
This has the effect of calling
DirichletBCMixin._ad_restore_at_checkpoint
on a checkpointed function: https://github.com/firedrakeproject/firedrake/blob/a9f2c621633f0e56c69c9ab42c6f2343051f4839/firedrake/adjoint_utils/dirichletbc.py#L45-L48Because of the use of
set_value
here, theDirichletBC
is then modified (and refers to the previous value ofT
). It seems like the weak checkpointing inDirichletBC
is probably correct, which points to the accessing ofsaved_output
duringTimeStep.checkpoint
being incorrect. I'm really unclear about what's checkpointed and when and when to use.output
vs..saved_output
, etc. I don't know if there are further implications for this change.