Group#
- class liesel.model.nodes.Group(name, **nodes_and_vars)[source]#
Bases:
object
A group holds a collection of related
Var
and/orNode
objects.They allow you to do three basic things:
Store related nodes together for easier access.
Access their member nodes and variables via
group["name"]
, where"name"
is the group-specific name, which can be different from theVar.name
/Node.name
.Easily retrieve a variable’s or a node’s value from a
Model.state
based on their group-specific name viavalue_from()
.
- Parameters:
See also
Node.groups
andVar.groups
areMappingProxyType
objects (basically read-only dictionaries) of the groups whose member the respective object is.GraphBuilder.groups()
andModel.groups()
are methods that collect and return all groups within the graph/model.
Notes
Note the following:
Groups can only be filled upon initialization.
After initialization, variables and nodes cannot be removed from a group.
Examples
Add a variable to a group:
>>> my_var = lsl.Var(0.0, name="long_unique_variable_name") >>> grp = lsl.Group(name="demo_group", short_name=my_var) >>> grp Group(name="demo_group")
Access the variable by its group-specific name:
>>> grp["short_name"] Var(name="long_unique_variable_name")
Retrieve the value of a variable from a model state:
>>> model_state = {my_var.value_node.name: lsl.NodeState(10., False)} >>> grp.value_from(model_state, "short_name") 10.0
Methods
value_from
(model_state, name)Retrieves the value of a node or variable that is a member of the group from a model state.
Attributes
The group's name.
A mapping of the nodes in the group with their names as keys.
A mapping of all group members with their names as keys.
A mapping of the variables in the group with their names as keys.