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

draft of section group feature #3990

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

barollet
Copy link

Overview:

Adds a group decorator to Scene that are basically "sections group".

class SceneWithGroupAPI(Scene):
    groups_api = True # groups are read from top to bottom

    def __init__(self):
        super().__init__()

        self.square = Square()
        self.circle = Circle()

    @group
    def transform(self):
        self.play(TransformFromCopy(self.square, self.circle))

    @group
    def back_transform(self):
        self.play(Transform(self.circle, self.square))


class SceneWithGroupList(Scene):
    section_groups = ["transform", "back_transform"] # group order is specified by user (groups may even be repeated)

    def __init__(self):
        super().__init__()

        self.square = Square()
        self.circle = Circle()

    @group
    def back_transform(self):
        self.play(Transform(self.circle, self.square))

    @group
    def transform(self):
        self.play(TransformFromCopy(self.square, self.circle))

Motivation and Explanation: Why and how do your changes improve the library?

For long videos you may want to have 2 levels of granularity for skipping/animation parts of the videos. Sections are the basic building block like a few animations and they are rendered in the same way as before.
You may add groups that behave like "chapters". They are a sequence of sections (you can still put sections inside groups) and the skipping/animation of section groups takes precedence over the individual section skipping/animation.

To make the distinction between sections and section groups the experimental API for sections is used. This way creating section is unchanged and we can gain the flexibility of the experimental API. Actually most of the code for the definition of a SectionGroup is taken from the experimental Section object.

Links to added or changed documentation pages

The documentation must be done but the API is not stabilized. I'll wait for the namming to be correct before documenting.
It should go in the section page I think.

Additional comments

There is a feature in the SectionGroup object to make it become a full member of the Scene instance that I couldn't make work.
For now section groups must be called like group(self).

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

manim/scene/groups.py Dismissed Show dismissed Hide dismissed
This is called implicitly by python when methods are being bound.
"""
return self # HELPME use binding
return self.bind(instance)

Check warning

Code scanning / CodeQL

Unreachable code Warning

This statement is unreachable.
def group(
func: Callable[P, T],
**kwargs: Unpack[SectionGroupData],
) -> SectionGroup[P, T]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
def group(
func: None = None,
**kwargs: Unpack[SectionGroupData],
) -> Callable[[Callable[P, T]], SectionGroup[P, T]]: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
@@ -50,6 +50,7 @@
from ..utils.family_ops import restructure_list_to_exclude_certain_family_members
from ..utils.file_ops import open_media_file
from ..utils.iterables import list_difference_update, list_update
from .groups import SectionGroup

Check failure

Code scanning / CodeQL

Module-level cyclic import Error

'SectionGroup' may not be defined if module
manim.scene.groups
is imported before module
manim.scene.scene
, as the
definition
of SectionGroup occurs after the cyclic
import
of manim.scene.scene.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

Successfully merging this pull request may close these issues.

1 participant