pyiron_workflow.nodes.transform module
Transformer nodes convert many inputs into a single output, or vice-versa.
- class pyiron_workflow.nodes.transform.DataclassNode(*args, label: str | None = None, parent: Composite | None = None, delete_existing_savefiles: bool = False, autoload: BackendIdentifier | StorageInterface | None = None, autorun: bool = False, checkpoint: BackendIdentifier | StorageInterface | None = None, **kwargs)[source]
Bases:
Transformer,ABCA base class for a node that converts inputs into a dataclass instance.
- dataclass: ClassVar[type]
- process_run_result(run_output: Any | tuple) Any | tuple[source]
What to _do_ with the results of
on_run()once you have them.By extracting this as a separate method, we allow the runnable to pass the actual execution off to another entity and release the python process to do other things. In such a case, this function should be registered as a callback so that the runnable can process the result of that process.
- Parameters:
run_output – The results of a self.on_run(self.run_args) call.
- class pyiron_workflow.nodes.transform.InputsToDataframe(*args, label: str | None = None, parent: Composite | None = None, delete_existing_savefiles: bool = False, autoload: BackendIdentifier | StorageInterface | None = None, autorun: bool = False, checkpoint: BackendIdentifier | StorageInterface | None = None, **kwargs)[source]
Bases:
Transformer,ABCTurns inputs of dictionaries (all with the same keys) into a single
pandas.DataFrame.- process_run_result(run_output: DataFrame) DataFrame[source]
What to _do_ with the results of
on_run()once you have them.By extracting this as a separate method, we allow the runnable to pass the actual execution off to another entity and release the python process to do other things. In such a case, this function should be registered as a callback so that the runnable can process the result of that process.
- Parameters:
run_output – The results of a self.on_run(self.run_args) call.
- class pyiron_workflow.nodes.transform.InputsToDict(*args, label: str | None = None, parent: Composite | None = None, delete_existing_savefiles: bool = False, autoload: BackendIdentifier | StorageInterface | None = None, autorun: bool = False, checkpoint: BackendIdentifier | StorageInterface | None = None, **kwargs)[source]
Bases:
Transformer,ABC- static hash_specification(input_specification: list[str] | dict[str, tuple[Any | None, Any | NotData]])[source]
For generating unique subclass names.
- process_run_result(run_output: Any | tuple) Any | tuple[source]
What to _do_ with the results of
on_run()once you have them.By extracting this as a separate method, we allow the runnable to pass the actual execution off to another entity and release the python process to do other things. In such a case, this function should be registered as a callback so that the runnable can process the result of that process.
- Parameters:
run_output – The results of a self.on_run(self.run_args) call.
- class pyiron_workflow.nodes.transform.InputsToList(*args, label: str | None = None, parent: Composite | None = None, delete_existing_savefiles: bool = False, autoload: BackendIdentifier | StorageInterface | None = None, autorun: bool = False, checkpoint: BackendIdentifier | StorageInterface | None = None, **kwargs)[source]
Bases:
Transformer,ABC- process_run_result(run_output: Any | tuple) Any | tuple[source]
What to _do_ with the results of
on_run()once you have them.By extracting this as a separate method, we allow the runnable to pass the actual execution off to another entity and release the python process to do other things. In such a case, this function should be registered as a callback so that the runnable can process the result of that process.
- Parameters:
run_output – The results of a self.on_run(self.run_args) call.
- class pyiron_workflow.nodes.transform.ListToOutputs(*args, label: str | None = None, parent: Composite | None = None, delete_existing_savefiles: bool = False, autoload: BackendIdentifier | StorageInterface | None = None, autorun: bool = False, checkpoint: BackendIdentifier | StorageInterface | None = None, **kwargs)[source]
Bases:
Transformer,ABC- process_run_result(run_output: dict[str, Any]) dict[str, Any][source]
What to _do_ with the results of
on_run()once you have them.By extracting this as a separate method, we allow the runnable to pass the actual execution off to another entity and release the python process to do other things. In such a case, this function should be registered as a callback so that the runnable can process the result of that process.
- Parameters:
run_output – The results of a self.on_run(self.run_args) call.
- class pyiron_workflow.nodes.transform.Transformer(*args, label: str | None = None, parent: Composite | None = None, delete_existing_savefiles: bool = False, autoload: BackendIdentifier | StorageInterface | None = None, autorun: bool = False, checkpoint: BackendIdentifier | StorageInterface | None = None, **kwargs)[source]
Bases:
StaticNode,ABCTransformers are a special case of
StaticNodenodes that turn many inputs into a single output or vice-versa.- property color: str
For drawing the graph
- pyiron_workflow.nodes.transform.dataclass_node(dataclass: type, use_cache: bool = True, *node_args, **node_kwargs)[source]
Builds a dataclass node from a dataclass – i.e. a node whose inputs correspond to dataclass fields and whose output is an instance of the dataclass.
The underlying dataclass can be accessed on the
dataclassclass attribute of the resulting node.Leverages defaults (default factories) on dataclass fields to populate input channel values at class defintion (instantiation).
- Parameters:
dataclass (type) – A dataclass, i.e. class passing dataclasses.is_dataclass, or class variable that will be automatically passed to dataclasses.dataclass.
use_cache (bool) – Whether this node should default to caching its values. (Default is True.)
*node_args – Other
Nodepositional arguments.**node_kwargs – Other
Nodekeyword arguments.
- Returns:
- An instance of the dynamically created
DataclassNode subclass.
- An instance of the dynamically created
- Return type:
Examples
>>> from dataclasses import dataclass, field >>> >>> from pyiron_workflow import Workflow >>> >>> def some_list(): ... return [1, 2, 3] >>> >>> #@dataclass # Works on actual dataclasses as well as dataclass-like classes >>> class Foo: ... necessary: str ... bar: str = "bar" ... answer: int = 42 ... complex_: list = field(default_factory=some_list) >>> >>> f = Workflow.create.transformer.dataclass_node(Foo, label="my_dc") >>> print(f.readiness_report) my_dc readiness report: ready: False running: False failed: False inputs.necessary: False inputs.bar: True inputs.answer: True inputs.complex_: True
>>> f(necessary="input as a node kwarg") Foo.dataclass(necessary='input as a node kwarg', bar='bar', answer=42, complex_=[1, 2, 3])
- pyiron_workflow.nodes.transform.inputs_to_dataframe(n: int, use_cache: bool = True, *node_args, **node_kwargs)[source]
Creates and returns an instance of a dynamically generated
InputsToDataframesubclass with a specified number of inputs, each being a dictionary to form rows of the dataframe.- Parameters:
n (int) – Number of input channels.
use_cache (bool) – Whether this node should default to caching its values. (Default is True.)
*node_args – Positional arguments for the node instance.
**node_kwargs – Keyword arguments for the node instance.
- Returns:
- An instance of the dynamically created
InputsToDataframesubclass.
- Return type:
- pyiron_workflow.nodes.transform.inputs_to_dict(input_specification: list[str] | dict[str, tuple[Any | None, Any | NotData]], *node_args, class_name_suffix: str | None = None, use_cache: bool = True, **node_kwargs)[source]
Build a new
InputsToDictsubclass and instantiate it.Tries to automatically generate a subclass name by hashing the :param:`input_specification`. If such hashing fails, you will instead _need_ to provide an explicit :param:`class_name_suffix`
- Parameters:
input_specification (list[str] | dict[str, tuple[Any | None, Any | NOT_DATA]]) – The input channel names, or full input specification in the form {key: (type_hint, default_value))}.
*node_args – Other args for the node instance.
class_name_suffix (str | None) – The suffix to use in the class name. (Default is None, try to generate the suffix by hashing :param:`input_specification`.
use_cache (bool) – Whether this node should default to caching its values. (Default is True.)
**node_kwargs – Other kwargs for the node instance.
- Returns:
A new node for transforming inputs into a dictionary.
- Return type:
- pyiron_workflow.nodes.transform.inputs_to_list(n: int, /, *node_args, use_cache: bool = True, content_type_hint: object = NOT_DATA, **node_kwargs)[source]
- Creates and returns an instance of a dynamically generated
InputsToList subclass with a specified number of inputs.
- Parameters:
n (int) – Number of input channels.
use_cache (bool) – Whether this node should default to caching its values. (Default is True.)
content_type_hint (object) – Type hint for the content of the list. Applies to all input channels and the content type of the returned list. (Default is NOT_DATA, which will leave the content type of the list unspecified.)
*node_args – Positional arguments for the node instance.
**node_kwargs – Keyword arguments for the node instance.
- Returns:
- An instance of the dynamically created
InputsToList subclass.
- An instance of the dynamically created
- Return type:
- Creates and returns an instance of a dynamically generated
- pyiron_workflow.nodes.transform.list_to_outputs(n: int, /, *node_args, use_cache: bool = True, content_type_hint: object = NOT_DATA, **node_kwargs) ListToOutputs[source]
Creates and returns an instance of a dynamically generated
ListToOutputssubclass with a specified number of outputs.- Parameters:
n (int) – Number of output channels.
use_cache (bool) – Whether this node should default to caching its values. (Default is True.)
content_type_hint (object) – Type hint for the content of the list. Applies to all output channels and the content type of the provided list. (Default is NOT_DATA, which will leave the content type of the list unspecified.)
*node_args – Positional arguments for the node instance.
**node_kwargs – Keyword arguments for the node instance.
- Returns:
- An instance of the dynamically created
ListToOutputs subclass.
- An instance of the dynamically created
- Return type: