Skip to content
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

Generation of scenes mixing via API in high traffic #23

Open
marcelo-earth opened this issue Jun 25, 2024 · 4 comments
Open

Generation of scenes mixing via API in high traffic #23

marcelo-earth opened this issue Jun 25, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@marcelo-earth
Copy link
Owner

In some cases, the scenes returned by the API can be mixed when there are multiple requests.

Example:

image

Code:

class GraphArrow(Scene):
    def construct(self):
        # Create axes and labels
        axes = Axes(x_range=[0, 10], y_range=[0, 10])
        x_label = MathTex(r'\text{Espaço}').scale(0.575)
        y_label = MathTex(r'\text{Tempo}').scale(0.75)
        labels = VGroup(x_label.next_to(axes.x_axis, RIGHT), y_label.next_to(axes.y_axis, UP))

        # Create dots
        d = Dot(color=WHITE, radius=0.1)
        d.move_to([0, 0, 0])
        d2 = Dot(color=WHITE, radius=0.1)
        d2.move_to([-1, 0, 0])

        # Group dots
        g = VGroup(d, d2)
        g.arrange()

        # Create traced paths
        trace = VMobject()
        trace2 = VMobject()

        trace_points = []
        trace2_points = []

        def update_trace(trace):
            trace_points.append(d.get_center())
            if len(trace_points) > 1:
                new_path = DashedVMobject(Line(trace_points[-2], trace_points[-1]), num_dashes=1, equal_lengths=True)
                trace.add(new_path)

        def update_trace2(trace2):
            trace2_points.append(d2.get_center())
            if len(trace2_points) > 1:
                new_path = DashedVMobject(Line(trace2_points[-2], trace2_points[-1]), num_dashes=1, equal_lengths=True)
                trace2.add(new_path)

        trace.add_updater(update_trace)
        trace2.add_updater(update_trace2)

        # Add elements to the scene
        self.play(Write(axes), Write(labels))
        self.add(d, d2, trace, trace2)
        self.wait(2)
        self.play(d.animate.move_to([0, 3, 0]), d2.animate.move_to([0, 2, 0]))
        self.wait(2)
        self.play(d.animate.move_to([0, -3, 0]), d2.animate.move_to([0, -2, 0]))
        self.wait(2)
        trace.clear_updaters()
        trace2.clear_updaters()

Video:

video-GenScene-GenScene-338.1.mp4
@marcelo-earth marcelo-earth added the bug Something isn't working label Jun 25, 2024
@LucaM185
Copy link

LucaM185 commented Aug 6, 2024

I might know what's happening here, i tried building exactly that last year...
i had the problem that the first scene rendered had a name and the next ones kept the name of the first (for some dumb reason this is the default behaviour of manim) i fixed it by setting

force_output_as_scene_name = True

in manim. i literally ctrl-clicked my way from Scene->CairoRenderer->SceneFileWriter, ctrl-f "force" and you should find it.
it requires some changes to the structure of the code.

i didn't look at your code too closely, but having built this before, it seems like that kind of issue, since you are likely running in docker you will have to find a smarter way to do this...

@marcelo-earth
Copy link
Owner Author

I might know what's happening here, i tried building exactly that last year... i had the problem that the first scene rendered had a name and the next ones kept the name of the first (for some dumb reason this is the default behaviour of manim) i fixed it by setting

force_output_as_scene_name = True

in manim. i literally ctrl-clicked my way from Scene->CairoRenderer->SceneFileWriter, ctrl-f "force" and you should find it. it requires some changes to the structure of the code.

i didn't look at your code too closely, but having built this before, it seems like that kind of issue, since you are likely running in docker you will have to find a smarter way to do this...

Hi @LucaM185!, thank you so much!, I've thought about rewriting the scene name to make it different before.
I didn't think Manim would have this option, but I guess it has to do with speeding up the rendering process and not re-rendering already made scenes (I think).

@LucaM185
Copy link

Yes, if you reuse the same scene name it intelligently reuses previous partial_movie_files if they have the same hash. This is obviously not useful if you have completely different scenes, so I don't see a performance penalty in using different names... Just make sure you delete the folders after a while because of storage costs

@marcelo-earth
Copy link
Owner Author

Yes, if you reuse the same scene name it intelligently reuses previous partial_movie_files if they have the same hash. This is obviously not useful if you have completely different scenes, so I don't see a performance penalty in using different names... Just make sure you delete the folders after a while because of storage costs

Great, thanks a lot @LucaM185, we will start implementing the force_output_as_scene_name = True instruction in the following days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants