larvaworld.lib.model.object
Classes
Basic Class for all Larvaworld model objects. |
|
A grouped simulation object that extends the NamedObject class. |
Module Contents
- class larvaworld.lib.model.object.Object(model: Any | None = None, unique_id: Any | None = None, id: str = 'Object', **kwargs: Any)
Bases:
larvaworld.lib.param.NestedConfBasic Class for all Larvaworld model objects.
This class extends the agentpy Object class by allowing the recording of nested attributes.
Parameters
- modelobject, optional
The model this object belongs to.
- idstr, optional
The unique identifier for this object.
Attributes
- idstr
The unique identifier for this object.
- typestr
The name of the object’s class.
- logdict
A dictionary for recording log data.
- modelobject
The model this object belongs to.
- pobject
The parameters of the model.
Methods
- __repr__()
Return a string representation of the object.
- __getattr__(key)
Raise an AttributeError for unknown attributes.
- __getitem__(key)
Get an attribute value.
- __setitem__(key, value)
Set an attribute value.
- _set_var_ignore()
Store current attributes to separate them from custom variables.
- vars
Get a list of attribute names.
- _log
Access the log data.
- extend_log(l, k, N, v)
Extend log data with a new value.
- connect_log(ls)
Connect the log to the model’s dictionary of logs.
- nest_record(reporter_dic)
Record nested attributes.
- setup(**kwargs)
Initialize object attributes and actions.
Examples
The following setup initializes an object with three variables:
- def setup(self, y):
self.x = 0 # Value defined locally self.y = y # Value defined in kwargs self.z = self.p.z # Value defined in parameters
- unique_id
- id = 'Object'
- type = 'Object'
- log
- model = None
- property vars: list[str]
- nest_record(reporter_dic: dict[str, str]) None
Records an object’s variables at the current time-step. Recorded variables can be accessed via the object’s log attribute and will be saved to the model’s output at the end of a simulation.
- Arguments:
- reporter_dic (dict):
Dict of Names of the variables to be recorded.
- Notes:
Recording mutable objects like lists can lead to wrong results if the object’s content will be changed during the simulation. Make a copy of the list or record each list entry seperately.
- Examples:
Record the existing attributes x and y of an object a:
a.nest_record(['x', 'y'])
Record a variable z with the value 1 for an object a:
a.nest_record('z', 1)
Record all variables of an object:
a.nest_record(a.vars)
- setup(**kwargs: Any) None
This empty method is called automatically at the objects’ creation. Can be overwritten in custom sub-classes to define initial attributes and actions.
- Arguments:
- **kwargs: Keyword arguments that have been passed to
AgentorModel.add_agents(). If the original setup method is used, they will be set as attributes of the object.
- Examples:
The following setup initializes an object with three variables:
def setup(self, y): self.x = 0 # Value defined locally self.y = y # Value defined in kwargs self.z = self.p.z # Value defined in parameters