Ryven icon indicating copy to clipboard operation
Ryven copied to clipboard

Node not updated after loading from saved project

Open sphh opened this issue 2 years ago • 3 comments

I have the following node, which makes a dictionary from two input values:

from ryven import NENV

class MakeDict(NENV.Node):

    title = 'Make dictionary'
    init_inputs = [
        NENV.NodeInputBP(
            dtype=NENV.dtypes.Float(),
            label='a'),
        NENV.NodeInputBP(
            dtype=NENV.dtypes.Float(),
            label='b')]
    init_outputs = [
        NENV.NodeOutputBP(label='abc')]

    def update_event(self, inp=-1):
        a = self.input(0)
        b = self.input(1)

        self.set_output_val(0, {'a': a, 'b': b})

NENV.export_nodes(MakeDict,)
  1. I can add this node to a flow and after filling in the two values for a and b (let's say I use 0 and 1), the output is {'a': 0, 'b': 1}.
  2. I then save the project to a file.
  3. I close and restart Ryven and load the saved project file.
  4. The input of the MakeDict node have the values 0 and 1 filled in, but the output is None! I would expect the output to be {'a': 0, 'b': 1}.

sphh avatar May 26 '22 12:05 sphh

The value of an output usually depends on the most recent node update. A node is updated when input data changes. However, when loading a project the input data is already set (input values are preserved when saving, output values are not) and thus the node is updated again. You can get the desired behavior by updating explicitly

    def place_event(self):
        self.update()

The reason for this is that updating the node can have undesired effects for stateful nodes, this way you just have more control.

A note to myself on this: when the graph is reconstructed, the nodes are added first and then the connections. Adding the connections, however, does indeed cause updates unless self.block_init_updates is set to True. While potentially causing performance issues for simple projects, it may be more consistent here to also force node updates when input values are set (and prevent those as well when block_init_updates is set). I'll keep this open, thanks for the example.

leon-thomm avatar Jun 02 '22 10:06 leon-thomm

Thanks for explaining.

I would have thought, that after loading the project the project will be in the same state as when saving. If there are reasons for not recalculating the whole project, at least the user should get the option to do so. One option would be to be ask the user: ‘Recalculate project?’ → Yes|No. This could be done via a dialog box in the GUI.

sphh avatar Jun 03 '22 08:06 sphh

Adding

def place_event(self):
        self.update()

To my nodes on both sides of a connection still resulted in the output of the 2nd Node being None after loading from a save. Am I misunderstanding? If every node has this code, shouldn't there be no None values at the outputs of any Node?

kevinlinxc avatar Dec 15 '22 00:12 kevinlinxc