Skip to content

← control_flow package

IfElse

If-else conditional control flow aka conditional computation.

This node evaluates what is wired into its "then" branch if the condition was true, and what is wired into the "else" branch if the condition was false. This is called the "taken" branch. Crucially, the non-taken branch is not evaluated (i.e., the nodes do not run). This uses Python conditional evaluation, meaning that an empty list ([]), empty dictionary ({}), empty string (''), or zero value (0 or 0.0) will evaluate to False. If the taken branch has nothing wired into it, then the output defaults to None. If nothing is wired into the condition port or if it receives a None, then the else branch is evaluated and its value returned. Version 1.0.1

Ports/Properties

condition

Input condition.

verbose name
Condition
default value
None
port type
DataPort
value type
object (can be None)
data direction
IN

then_branch

Then branch. Executed if condition is true.

verbose name
Then Branch
default value
None
port type
GraphPort
value type
Graph

else_branch

Else branch. Executed if condition is false.

verbose name
Else Branch
default value
None
port type
GraphPort
value type
Graph

result

Result of the branch that was evaluated.

verbose name
Result
default value
None
port type
DataPort
value type
object (can be None)
data direction
OUT

emit_resets

Emit signal reset notifications when the condition changes. This can be used if the IfElse node controls codepaths through which signals flow and where downstream nodes should reset themselves upon a change of the condition. However, in rare cases this can lead to unexpected behavior: namely, if an IfElse in a machine-learning pipeline is driven by an is_training flag, it will cause a reset when the training flag changes, which leads to a reset of trainable state on the test set (unless the nodes are marked as do not reset model), which then causes retraining on the test set, which is likely a bug (that can give spuriously better results). For this reason, this flag is turned off by default, but it may be enabled if needed.

verbose name
Emit State Resets
default value
False
port type
BoolPort
value type
bool (can be None)

set_breakpoint

Set a breakpoint on this node. If this is enabled, your debugger (if one is attached) will trigger a breakpoint.

verbose name
Set Breakpoint (Debug Only)
default value
False
port type
BoolPort
value type
bool (can be None)

metadata

User-definable meta-data associated with the node. Usually reserved for technical purposes.

verbose name
Metadata
default value
{}
port type
DictPort
value type
dict (can be None)