manim icon indicating copy to clipboard operation
manim copied to clipboard

Hash of plotted curve should be invalidated when function changes (even if it is wrapped)

Open makai410 opened this issue 1 year ago • 4 comments

Description of bug / unexpected behavior

Caches are used in some inproper situations. Like when I had changed a formula that need to be draw on axes, yet not directly changed the curve's arguments, just an independent function having been changed, manim use the caches.

Expected behavior

In that case, manim should reload the codes.

How to reproduce the issue

Code for reproducing the problem
class Prove(Scene):
    def construct(self):
        def f(x):
            return (3*x**2+53/x)
        axes = Axes(x_range=[-1, 8, 1], y_range=[-1, 10, 1], x_length=9, y_length=7)
        curve = axes.plot(lambda x: f(x),x_range=[1, 7], color=DEF_GREEN)
        self.play(
            Create(axes),
            Create(curve)
        )
        self.wait()

For example, just change the function f(x) to this:

        def f(x):
            return (6*x**2+53/x)

then render, manim will use the caches.

System specifications

System Details
  • OS: Windows 10 v2004
  • RAM: 32GB DDR4
  • Python version: 3.11.9
  • Installed modules:
click             8.1.7      
cloup             3.0.5      
colorama          0.4.6      
decorator         5.1.1      
ffmpeg            1.4        
glcontext         2.5.0      
isosurfaces       0.1.2      
manim             0.18.1     
ManimPango        0.5.0      
mapbox-earcut     1.0.1
markdown-it-py    3.0.0
mdurl             0.1.2
moderngl          5.10.0
moderngl-window   2.4.6
multipledispatch  1.0.0
networkx          3.3
numpy             1.26.4
pillow            10.3.0
pip               24.0
pycairo           1.26.0
pydub             0.25.1
pyglet            2.0.15
Pygments          2.18.0
pyrr              0.10.3
rich              13.7.1
scipy             1.13.1
screeninfo        0.8.1
setuptools        65.5.0
skia-pathops      0.8.0.post1
srt               3.5.3
svgelements       1.9.6
tqdm              4.66.4
typing_extensions 4.12.2
watchdog          4.0.1

makai410 avatar Jun 15 '24 02:06 makai410

Welcome cooperation to tackle this :)

makai410 avatar Jun 15 '24 02:06 makai410

I cannot reproduce your problem. I mean the function which you have in your code has not a single visible point within the axes of your scene, neither has your replacement function.

bild

bild

When I toggle between 6*x**2+53/x and 6*x**2+53/x in the following code on my system, caching enabled, Manim always constructs the correct plot.

class Prove(Scene):
    def construct(self):
        def f(x):
            return (6*x**2+53/x)
        axes = Axes(x_range=[-1, 8, 1], y_range=[35, 55, 1], x_length=9, y_length=7)
        curve = axes.plot(lambda x: f(x),x_range=[1, 7], color=GREEN)
        self.play(
            Create(axes),
            Create(curve)
        )
        self.wait()

uwezi avatar Jun 16 '24 08:06 uwezi

Sorry for that I simplified this function while writing this issue; its original formula was:

def f(x):
    return (3*x**2+53/x)/16

If you change it to:

def f(x):
    return (9*x**2+53/x)/16

you will see manim use caches in the log.

makai410 avatar Jun 16 '24 10:06 makai410

It still does not for me - rendered with "3" and manim -pql .\20240613_01.py Prove

bild

https://github.com/ManimCommunity/manim/assets/8582807/e82e3a41-c14a-456d-bf56-64ccae2d5bc1

rendered with "9"

bild

https://github.com/ManimCommunity/manim/assets/8582807/1c3ebb95-5463-4645-b268-5feb2702d8f1

The log-output also suggest that Manim uses some cached parts, but obviously not the function lot itself...

bild

uwezi avatar Jun 16 '24 15:06 uwezi