Skip to content

Commit

Permalink
Merge pull request #146 from sghelichkhani/rol2.0-revert-restart
Browse files Browse the repository at this point in the history
Fixing restart cases that revert
  • Loading branch information
dham authored Jun 5, 2024
2 parents 003bbbb + 492e287 commit 849ee3e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pyadjoint/optimization/rol_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ def update(self, x, flag, iteration):
self._val = self.rf(x.dat)
self._tape_trial = self.rf.tape.checkpoint_block_vars(self.rf.controls)
elif flag == ROL.UpdateType.Revert:
# revert back to the cached value
self._val = self._cache
self.rf.tape.restore_block_vars(self._tape_cache)
# If we have cached value revert back to the cached value from _cache
if hasattr(self, "_tape_cache"):
self._val = self._cache
self.rf.tape.restore_block_vars(self._tape_cache)
# else (e.g., when we are unfortunate and restore from a reverted checkpoint)
# repopulate the tape for x.dat, and put them on _cache and _tape_cache
# as they were the last UpdateType.Accept values
else:
self._val = self.rf(x.dat)
self._cache = self._val
self._tape_cache = self._tape_trial

self._flag = flag

Expand Down

0 comments on commit 849ee3e

Please sign in to comment.