3 ms·
I agree about being explicit with this, though I will warn about using the python functools caching, because it changes the logic of your program. Because it do
by IanCal 3y ago
I agree about being explicit with this, though I will warn about using the python functools caching, because it changes the logic of your program. Because it doesn't copy data, any return that's mutable is risky. It's also not obvious this happens, and even less obvious if you're not keenly aware of this kind of issue being likely.
- westurner 3y agoDoes any cache imply invariance, which DbC like icontract can be used to check for really only within one program execution?
- IanCal 3y agoPlenty of caches are built that have this property. Streamlit for example offers two different caching helpers, one is faster but only safe if you don't mutate the return value and one is slower but safer as it makes a copy. Diskcache, my go-to, appears to be safe with regards to this too.
- westurner 3y agoRegardless of cache implementation, if the notebook input cells are run in a different sequence like 0,1,2,2,2,3 the output with caching there is not necessarily same as without caching and not necessarily the same as 0,1,2,2,3 ; caching alone does not achieve functional idempotency, in fact that's many more partners that can diverge when the interest is parametric reproducibility (and notebooks are already a strange abstraction for computation graphs complex enough to justify e.g. dask.cache.Cache() for, and there are reasons to not always enable dask.cache.Cache() globally (if the argument were whether auto-caching is safe enough to be the default behavior in notebooks))