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

Node not updated after loading from saved project #114

Open
sphh opened this issue May 26, 2022 · 3 comments
Open

Node not updated after loading from saved project #114

sphh opened this issue May 26, 2022 · 3 comments

Comments

@sphh
Copy link
Contributor

sphh commented May 26, 2022

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}.
@leon-thomm
Copy link
Owner

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.

@sphh
Copy link
Contributor Author

sphh commented Jun 3, 2022

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.

@kevinlinxc
Copy link

kevinlinxc commented Dec 15, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants