-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReducedFunctional.optimize_tape
will optionally _replace_ self.tape with the optimized tape, without modifying original tape.
#171
Conversation
…h optimized tape, but not modify original tape
Is optimizing the tape actually expensive (it involves just a few passes over the tape)? I'd expect it's cheap enough (compared e.g. to a gradient calculation) that is isn't necessary to cache the optimized tape. |
The optional argument to update Otherwise anywhere that I guess the answer in that case would be to make |
What I mean is that, since it's (probably) cheap, the activity analysis can be performed each time a derivative is computed. i.e. I think it makes more sense as an argument, Modifying |
Can you explain this? I don't understand why it would. |
You're correct, I've worked through the second order and I think it's OK. |
…r, and just transfers any package data that doesn't have a copy method
I've tested out having The main issue I ran into is that
|
Closing this PR as it isn't clear how to deal with the issues in the comment above, particularly what it means to copy and optimize a tape with a checkpoint manager. |
This PR addresses #170
Currently
ReducedFunctional.optimize_tape
will modifyself.tape
in-place. This means that if anything else is using the same tape, then they now also have a modified tape.This PR adds an optional
replace
argument tooptimize_tape
to give the option of copying the tape and replacingself.tape
with the optimized tape, without modifying the original tape. The optimized tape is also returned (whether a copy was made or not).I did it this way so that the default call has the same behaviour as before, so it shouldn't break any existing code - unless someone is relying on it returning
None
, but seeing as this is implicit and non-documented behaviour I don't think we care.@dham also suggested that the default behaviour should change so that it doesn't modify
self.tape
, but just returns the optimized tape. Is this something we want to do? If so, should it raise a warning for now that the default behaviour will change in the future, and delay making the change for a bit?I think if this behaviour does change, it would be good to have an
optimize_tape(modify=False)
argument to optionally still updateself.tape
, otherwise we'll probably seeJhat.tape = Jhat.optimize_tape()
popping up all over.