-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
ImageMobjects are not properly hashed #2924
Comments
@huguesdevimeux As you are the caching expert, do you have an idea why pixel_array is in the exclude list ? |
If im not mistaken, it may have something to do with the fact that numpy arrays are not hashable. >>> from functools import cache
>>> cache(lambda i:i)(np.array([1,2,3]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'numpy.ndarray' |
For reference, here's what happens to ndarrays that aren't filtered out: Lines 210 to 215 in b26137e
|
I think the issue what they were too large, so there is a workaround. Hope it's clear. ÉDIT : @icedcoffeeee It's an old piece of code, but I don't think it's related to the hashability of an np array. It's really just a matter of size ÉDIT 2 : this issue looks interesting, I will definetly take a look when I can ! |
Hello and sorry, this went off my mind. I think the most straightforward and logical thing would be to exclude |
My proposal would be to generate a short random sequence as an, hash for every pixel_array, in order to invalidate the cache systematically. That's the most straightforward and simple solution I can think. |
Description of bug / unexpected behavior
I found that certain operations on
ImageMobject
s do not invalidate the animation cache, that is, they don't change the mobject's hash value.In consequence, in a typical workflow of repeated renders, Manim sometimes generates videos that do not match the code they were generated with.
This is because the
pixel_array
is explicitly filtered out of the hashing operation:manim/manim/utils/hashing.py
Lines 21 to 26 in b26137e
Expected behavior
All (visible) modifications to an
ImageMobject
should result in its hash being different.How to reproduce the issue
Code for reproducing the problem
manim filename.py
without amanim.cfg
)Additional comments
The most obvious “fix” would be to remove
"pixel_array"
from the exclude list – which, considering that #2923 works, doesn't break Manim – but I assume it's there for a reason.Edit: As you can see in the code snipped below, #2923 “works”, because a
repr
of the (truncated) array is hashed, not all of its values. In other words, this only works if you're lucky.The text was updated successfully, but these errors were encountered: