Skip to content

Simplification: node creation works the same from Composite class or instance #115

@liamhuber

Description

@liamhuber

Right now we have a create method on the Composite class (a parent of both workflows and macros) for making new nodes (and executors, and eventually other things); but when you instantiate one of these, this method gets overridden with an OwnedCreator such that using it to create new nodes both creates and parents them. I've come around to the point of view that this is a bad idea -- the infrastructure cost is too high a price to pay for this "convenience", and anyhow the convenience violates "better explicit than implicit".

I would like to get rid of this behaviour entirely so create is always just making a clean (unparented) instance, and you need to explicitly parent it somehow. i.e. the Workflow docstring would be updated accordingly:

NEW:

We allow adding nodes to workflows in four equivalent ways:

from pyiron_workflow.workflow import Workflow

@Workflow.wrap_as.single_value_node()
def fnc(x=0):
    return x + 1

# (1) As *args at instantiation
n1 = fnc(label="n1")
wf = Workflow("my_workflow", n1)

# (2) Being passed to the `add` method
n2 = wf.add(fnc(label="n2"))  # Actually I want to rename this to add_node

# (3) By attribute assignment 
wf.n4 = fnc(label="anyhow_n4_gets_used")

# (4) By specifying the parent kwarg
n5 = fnc(label="n5", parent=wf)

OLD (i.e. current):

We allow adding nodes to workflows in five equivalent ways:

from pyiron_workflow.workflow import Workflow

def fnc(x=0):
    return x + 1

# (1) As *args at instantiation
n1 = Workflow.create.Function(fnc, label="n1")
wf = Workflow("my_workflow", n1)

# (2) Being passed to the `add` method
added = wf.add(Workflow.create.Function(fnc, label="n2"))

# (3) Calling `create` from the _workflow instance_ that will own the node
added = wf.create.Function(fnc, label="n3")  # Instantiating from add

# (4) By attribute assignment (here the node can be created from the
# workflow class or instance and the end result is the same
wf.n4 = wf.create.Function(fnc, label="anyhow_n4_gets_used")

# (5) By creating from the workflow class but specifying the parent kwarg
added = Workflow.create.Function(fnc, label="n5", parent=wf)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions