nodify.node.FuncNode

class nodify.node.FuncNode(*args, func: Callable, **kwargs)[source]

Bases: Node

__init__(*args, **kwargs)

Methods

__init__(*args, **kwargs)

evaluate_input_node(node)

from_func([func, context, module])

Builds a node from a function.

function(*args, func, **kwargs)

get()

Returns the output of the node, possibly running the computation.

get_diagram_label()

Returns the label to be used in diagrams when displaying this node.

get_input(key)

get_tree()

is_output_outdated(evaluated_inputs)

Checks if the node needs to be ran

map_inputs(inputs, func[, only_nodes, exclude])

Maps all inputs of the node applying a given function.

recursive_update_inputs([cls])

Updates the inputs of the node recursively.

setup(*args, **kwargs)

Sets up the node based on its initial inputs.

update_inputs(**inputs)

Updates the inputs of the node.

Attributes

DELETE_KWARG

context

default_inputs

get_syntax

inputs

last_log

Last time the logs of this node were updated

logs

classmethod from_func(func: Callable | None = None, context: dict | None = None, module: str | None = None)

Builds a node from a function.

Parameters:
  • func (function, optional) –

    The function to be converted to a node.

    If not provided, the return of this method is just a lambda function that expects the function. This is useful if you want to use this method as a decorator while also providing extra arguments (like the context argument).

  • context (dict, optional) – The context to be used as the default for the node class that will be created.

get()

Returns the output of the node, possibly running the computation.

The computation of the node is only performed if the output is outdated, otherwise this function just returns the stored output.

get_diagram_label()

Returns the label to be used in diagrams when displaying this node.

is_output_outdated(evaluated_inputs: Dict[str, Any])

Checks if the node needs to be ran

property last_log: float

Last time the logs of this node were updated

map_inputs(inputs: Dict[str, Any], func: Callable, only_nodes: bool = False, exclude: Sequence[str] = ()) Dict[str, Any]

Maps all inputs of the node applying a given function.

It considers the args and kwargs keys.

Parameters:
  • inputs (Dict[str, Any]) – The inputs of the node.

  • func (Callable) – The function to apply to each value.

  • only_nodes (bool, optional) – Whether to apply the function only to nodes, by default False.

  • exclude (Sequence[str], optional) – The keys to exclude from the mapping. This means that these keys are returned as they are.

recursive_update_inputs(cls: Type | Tuple[Type, ...] | None = None, **inputs)

Updates the inputs of the node recursively.

This method updates the inputs of get node and all its children.

Parameters:
  • cls (Optional[Union[Type, Tuple[Type, ...]]], optional) – Only update nodes of this class. If None, update all nodes.

  • inputs (Dict[str, Any]) – The inputs to update.

setup(*args, **kwargs)

Sets up the node based on its initial inputs.

update_inputs(**inputs)

Updates the inputs of the node.

Note that you can not pass positional arguments to this method. The positional arguments must be passed also as kwargs.

This is because there would not be a well defined way to update the variadic positional arguments.

E.g. if the function signature is (a: int, *args), there is no way to pass *args without passing a value for a.

This means that one must also pass the *args also as a key: update_inputs(args=(2, 3)). Beware that functions not necessarily name their variadic arguments args. If the function signature is (a: int, *arguments) then the key that you need to use is arguments.

Similarly, the **kwargs can be passed either as a dictionary in the key kwargs (or whatever the name of the variadic keyword arguments is). This indicates that the whole kwargs is to be replaced by the new value. Alternatively, you can pass the kwargs as separate key-value arguments, which means that you want to update the kwargs dictionary, but keep the old values. In this second option, you can indicate that a key should be removed by passing Node.DELETE_KWARG as the value.

Parameters:

**inputs – The inputs to update.