Module#

class braincore.Module(name=None, mode=None)#

The Module class for the whole ecosystem.

The Module is the base class for all the objects in the ecosystem. It provides the basic functionalities for the objects, including:

  • states(): Collect all states in this node and the children nodes.

  • nodes(): Collect all children nodes.

  • update(): The function to specify the updating rule.

  • init_state(): State initialization function.

  • save_state(): Save states as a dictionary.

  • load_state(): Load states from the external objects.

init_state(*args, **kwargs)[source]#

State initialization function.

load_state(state_dict, **kwargs)[source]#

Load states from the external objects.

Return type:

Optional[Tuple[Sequence[str], Sequence[str]]]

property mode#

Mode of the model, which is useful to control the multiple behaviors of the model.

property name#

Name of the model.

nodes(method='absolute', level=-1, include_self=True, unique=True)[source]#

Collect all children nodes.

Parameters:
  • method (str) – The method to access the nodes.

  • level (int) – The hierarchy level to find nodes.

  • include_self (bool) – Whether include the self.

  • unique (bool) – Whether return the unique variables.

Returns:

gather – The collection contained (the path, the node).

Return type:

DictManager

save_state(**kwargs)[source]#

Save states as a dictionary.

Return type:

Dict

states(method='absolute', level=-1, include_self=True, unique=True)[source]#

Collect all states in this node and the children nodes.

Parameters:
  • method (str) – The method to access the variables.

  • level (int) – The hierarchy level to find variables.

  • include_self (bool) – Whether include the variables in the self.

  • unique (bool) – Whether return the unique variables.

Returns:

states – The collection contained (the path, the variable).

Return type:

StateDictManager

update(*args, **kwargs)[source]#

The function to specify the updating rule.