Group#

class liesel.model.nodes.Group(name, **nodes_and_vars)[source]#

Bases: object

A group holds a collection of related Var and/or Node objects.

They allow you to do three basic things:

  1. Store related nodes together for easier access.

  2. Access their member nodes and variables via group["name"], where "name" is the group-specific name, which can be different from the Var.name / Node.name.

  3. Easily retrieve a variable’s or a node’s value from a Model.state based on their group-specific name via value_from().

Parameters:
  • name (str) – The group’s name. Must be unique among the groups of its members, and within a model.

  • **nodes_and_vars (Node | Var) – An arbitrary number of nodes or variables. The keywords will be used as the group-specific names of the respective objects.

See also

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<demo_group>

Access the variable by its group-specific name:

>>> grp["short_name"]
Var<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

name

The group's name.

nodes

A mapping of the nodes in the group with their names as keys.

nodes_and_vars

A mapping of all group members with their names as keys.

vars

A mapping of the variables in the group with their names as keys.