-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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)