manim icon indicating copy to clipboard operation
manim copied to clipboard

LinearTransformationSceneExample does not work in Colab

Open BAREJAA opened this issue 4 years ago • 5 comments

Description of bug / unexpected behavior

I'm trying to change the base configurations for LinearTransformationScene, but I get an error. This was not the case when I was using the previous version of Manim a few days ago

Expected behavior

I was hoping to change the configs without getting an error

How to reproduce the issue

Following is some example code taken from the docs. The first line was to get it to run in Google Colab (as described in the tutorials section)

 %%manim LinearTransformationSceneExample
 
 class LinearTransformationSceneExample(LinearTransformationScene):
            def __init__(self):
                LinearTransformationScene.__init__(
                    self,
                    show_coordinates=True,
                    leave_ghost_vectors=True,
                )

            def construct(self):
                matrix = [[1, 1], [0, 1]]
                self.apply_matrix(matrix)
                self.wait()

Logs

Terminal output
TypeError: __init__() got an unexpected keyword argument 'renderer'

System specifications

System Details

Google Colab's settings

Python version

python3
FFMPEG

Output of ffmpeg -version:

ffmpeg version 3.4.8-0ubuntu0.2 

Additional comments

BAREJAA avatar Sep 05 '21 19:09 BAREJAA

Can you try to change the code to

class LinearTransformationSceneExample(LinearTransformationScene):
    def __init__(self, **kwargs):
        LinearTransformationScene.__init__(
            self,
            show_coordinates=True,
            leave_ghost_vectors=True,
            **kwargs,
        )

    def construct(self):
        matrix = [[1, 1], [0, 1]]
        self.apply_matrix(matrix)
        self.wait()

and see whether this helps?

behackl avatar Sep 05 '21 20:09 behackl

Yes! That fixed it. Could you briefly explain why?

Thanks!

BAREJAA avatar Sep 05 '21 21:09 BAREJAA

Yes! That fixed it. Could you briefly explain why?

Thanks!

Of course! Apologies for the delay: When rendering a scene in Colab (or generally in Jupyter Notebooks), the renderer gets passed to the scene as an additional keyword argument; this is part of the %%manim IPython magic.

The way the example in the documentation is currently written does not allow for additional keyword arguments; by adding **kwargs to both the custom __init__ of your scene, as well as to the corresponding LinearTransformationScene.__init__ call, the keyword is propagated properly.

The issue should remain open (and I've also renamed it a bit) until the example in the documentation is changed accordingly.

behackl avatar Sep 07 '21 11:09 behackl

Thank you for your clear explanation!

BAREJAA avatar Sep 08 '21 12:09 BAREJAA

I could write about it in the docs, but let me check if I understand correctly what is going on: By default, the cell magic %%manim feeds the constructor with the appropriate renderer to display the output in the IPython cell. So basically only the example needs to be changed or should also contain a note pointing out to this detail?

Tsukalos avatar Jun 27 '22 17:06 Tsukalos

@Tsukalos @behackl Do you need any help with this issue? I can work on it

detective-sokka avatar Apr 15 '23 21:04 detective-sokka