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

Error with Graph Tree Layout example in the graph.py #3753

Open
dalopezt opened this issue May 7, 2024 · 3 comments
Open

Error with Graph Tree Layout example in the graph.py #3753

dalopezt opened this issue May 7, 2024 · 3 comments

Comments

@dalopezt
Copy link

dalopezt commented May 7, 2024

The following comment in the file https://github.com/ManimCommunity/manim/blob/main/manim/mobject/graph.py

'''
    - Tree Layout: places vertices into a tree with a root node and branches (can only be used with legal trees)

    .. manim:: TreeLayout
        :save_last_frame:

        class TreeLayout(Scene):
            def construct(self):
                graph = Graph(
                    [1, 2, 3, 4, 5, 6, 7],
                    [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)],
                    layout="tree",
                    layout_config={"root_vertex": 1},
                    labels=True
                )
                self.add(graph)
'''

Doesn't work properly and raise the following exception:

Traceback (most recent call last):
╭──────────────────────────────────────────────────────────────────────────────────────╮
│ File "c:\users\dalopezt\appdata\local\programs\python\python37\lib\site-packages\mani│
│m\cli\render\commands.py", line 121, in render                                        │
│    118             try:                                                              │
│    119                 with tempconfig(config):                                      │
│    120                     scene = SceneClass()                                      │
│  ❱ 121                     scene.render()                                            │
│    122             except Exception:                                                 │
│    123                 error_console.print_exception()                               │
│    124                 sys.exit(1)                                                   │
│ File "c:\users\dalopezt\appdata\local\programs\python\python37\lib\site-packages\mani│
│m\scene\scene.py", line 222, in render                                                │
│     219         """
│     220         self.setup()                                                         │
│     221         try:                                                                 │
│  ❱  222             self.construct()                                                 │
│     223         except EndSceneEarlyException:                                       │
│     224             pass                                                             │
│     225         except RerunSceneException as e:                                     │
│ File "C:\Users\dalopezt\manim\test.py", line 9, in construct                         │
│     6             [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)],                  │
│     7             layout="tree",                                                     │
│     8             layout_config={"root_vertex": 1},                                  │
│  ❱  9             labels=True                                                        │
│    10         )                                                                      │
│    11         self.add(graph)                                                        │
│ File "c:\users\dalopezt\appdata\local\programs\python\python37\lib\site-packages\mani│
│m\mobject\graph.py", line 519, in __init__                                            │
│     516             layout_scale=layout_scale,                                       │
│     517             layout_config=layout_config,                                     │
│     518             partitions=partitions,                                           │
│  ❱  519             root_vertex=root_vertex,                                         │
│     520         )                                                                    │
│     521                                                                              │
│     522         if isinstance(labels, dict):                                         │
│ File "c:\users\dalopezt\appdata\local\programs\python\python37\lib\site-packages\mani│
│m\mobject\graph.py", line 64, in _determine_graph_layout                              │
│      61         return {k: np.append(v, [0]) for k, v in auto_layout.items()}        │
│      62     elif layout == "tree":                                                   │
│      63         return _tree_layout(                                                 │
│  ❱   64             nx_graph, root_vertex=root_vertex, scale=layout_scale, **layout_c│
│      65         )                                                                    │
│      66     elif layout == "partite":                                                │
│      67         if partitions is None or len(partitions) == 0:                       │
╰──────────────────────────────────────────────────────────────────────────────────────╯
TypeError: _tree_layout() got multiple values for keyword argument 'root_vertex'
@dalopezt
Copy link
Author

dalopezt commented May 7, 2024

Quick Fix

Using directly the root_vertex param instead of using the layout_config param works just fine.
I suggest revisit the examples in the code and check if some of them are deprecated.

from manim import *
class TreeLayout(Scene):
    def construct(self):
        graph = Graph(
            [1, 2, 3, 4, 5, 6, 7],
            [(1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7)],
            layout="tree",
            root_vertex=1,
            labels=True
        )
        self.add(graph)

@Nikhil-42
Copy link
Contributor

@dalopezt Which version of Manim are you using? Make sure it is the same version as the documentation you are reading. Graph layouts were redone in v0.18.1 so if your version of Manim is older you should look at the older documentation.

@uwezi
Copy link
Contributor

uwezi commented May 28, 2024

The code from the example scene works fine in the current version 0.18.1 - this can also be checked with the interactive rendering from within the documentation.

image

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

No branches or pull requests

3 participants