-
Notifications
You must be signed in to change notification settings - Fork 35
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
Semi-automatic caching of outputs by input hash. #13
Comments
Hi Michael, It looks interesting and doable. I think it would be better to implement that in a new cell magic like Otherwise, I think this magic could work exactly as you describe:
When multiple cells have exactly the same contents, would it be conceivable for you to put a comment like |
I am not sure that using It is quite a common strategy (at least for me!) to use comments to make cells of identical code look different, so I think that is perfectly feasible. |
It's a bit different from I imagine we could have |
Of course you are correct. To be completely analogous one should probably also be able to do something like |
I would like to be able to cache the output of several different cells. The problem is that each cache file seems to store exactly one output so that I must use a different file for each cell, which is cumbersome.
Ideally, I would like to be able to first specify a cache file (not sure the optimal syntax) like:
Then cache several output cells with something as simple as:
Another cell might be
Ideally, each output would be stored in a dictionary who's key is a hash of the cell's input so that the cell is executed if needed, but -- more importantly -- the appropriate output is restored if one has several cells.
This mechanism would be defeated by cells that have identical inputs:
but I could live with that. (To get around this, some sort of context of the cell in the original notebook would be needed, but I think this might be a can of worms.)
Backwards Compatibility
I have not delved into the source yet, so I am not sure how easy this would be to implement, however, I propose as a minimal syntax that this feature would only work if one first specifies a cache file with
--set-cache "my_cache.pkl"
, otherwise the default behaviour continues. Only if this has been set would a blank%%cache
line work as described (otherwise, the usual error would be raised).Is this feasible, or is there a better way to "freeze" the output of calculations?
Michael.
P.S. My use case is interactive profiling and improving code. I want to freeze the previous profiling outputs so that the notebook becomes a log of the profiling process. I don't yet see much of a need for caching variables, but need to cache the output, so perhaps this extension is not the best fit for my needs, but it almost works.
The text was updated successfully, but these errors were encountered: