jchanvfx / NodeGraphQt

Node graph framework that can be re-implemented into applications that supports PySide2
http://chantonic.com/NodeGraphQt/
MIT License
1.3k stars 266 forks source link

Auto Node Layout fails for cyclic graphs #393

Open xraybrian opened 1 year ago

xraybrian commented 1 year ago

I have implemented a data analysis framework that allows node computation and back propagation of derivatives for optimization of parameters by subclassing NodeGraph and BaseNode. This required allowing cyclic graphs so that the optimizer node can connect back to optimizable parameter nodes. Functionally, everything is working very well.

However, the auto node layout method produces a recursion error for a cyclic graph.

Any chance of supporting auto node layout for cyclic graphs?

J-Arnold commented 7 months ago

I have the same issue I like to virtualize a kind of workflow program, there I need to create loops but this is not possible at the moment. Screenshot 2024-04-03 205255

J-Arnold commented 7 months ago

Hi, I tested out some ways to create a loop my development. To test you add the following lines to the basic_example.py

    n_basic_b1 = graph.create_node('nodes.basic.BasicNodeB', name='custom icon')
    n_basic_b2 = graph.create_node('nodes.basic.BasicNodeB', name='custom icon')
    n_basic_b3 = graph.create_node('nodes.basic.BasicNodeB', name='custom icon')
    n_basic_b4 = graph.create_node('nodes.basic.BasicNodeB', name='custom icon')

    n_basic_b1.set_output(0, n_basic_b2.input(2))
    n_basic_b2.set_output(0, n_basic_b3.input(2))
    n_basic_b3.set_output(0, n_basic_b1.input(2))
Loop_OK

If you try to connect another output to one of the loop inputs the Editor crashes.

Loop_Fail

Also the Program crashes if you add the connection by development adding the line:

n_basic_b4.set_output(0, n_basic_b1.input(0))

In some of my tests I got the following Error output:

Windows fatal exception: stack overflow
Main thread:
Current thread 0x0000913c (most recent call first):
  ....\Python310\lib\site-packages\NodeGraphQt\base\port.py", line 101 in name
  ....\Python310\lib\site-packages\NodeGraphQt\nodes\base_node.py", line 620 in <dictcomp>
  ....\Python310\lib\site-packages\NodeGraphQt\nodes\base_node.py", line 620 in inputs
  ....\Python310\lib\site-packages\NodeGraphQt\base\port.py", line 210 in connected_ports
  ....\Python310\lib\site-packages\NodeGraphQt\nodes\base_node.py", line 716 in connected_output_nodes
  ....\Python310\lib\site-packages\NodeGraphQt\base\graph.py", line 2149 in _update_node_rank
  ....\Python310\lib\site-packages\NodeGraphQt\base\graph.py", line 2163 in _update_node_rank
  ....\Python310\lib\site-packages\NodeGraphQt\base\graph.py", line 2163 in _update_node_rank
  ....\Python310\lib\site-packages\NodeGraphQt\base\graph.py", line 2163 in _update_node_rank
  ( this last line is repeated a lot of times )
  ...
Restarting kernel...

Another issue is that the Auto layouter is not able to create a layout all notes are stacking over each other.

Stacking
jchanvfx commented 7 months ago

Hi @J-Arnold,

Thanks for providing the examples and test 😃 this is really helpful, I'll try to look into this issue when I can.

Cheers, Johnny

J-Arnold commented 5 months ago

Hi, I tried the newest NodeGraphQt Version 0.6.36 but unfortunately it did not fixed my issue the programm is still crashing.

Did you got time to look into this issue ?

Thanks Jens