larvaworld.lib.model.object =========================== .. py:module:: larvaworld.lib.model.object Classes ------- .. autoapisummary:: larvaworld.lib.model.object.Object larvaworld.lib.model.object.GroupedObject Module Contents --------------- .. py:class:: Object(model: Any | None = None, unique_id: Any | None = None, id: str = 'Object', **kwargs: Any) Bases: :py:obj:`larvaworld.lib.param.NestedConf` Basic Class for all Larvaworld model objects. This class extends the agentpy Object class by allowing the recording of nested attributes. Parameters ---------- model : object, optional The model this object belongs to. id : str, optional The unique identifier for this object. Attributes ---------- id : str The unique identifier for this object. type : str The name of the object's class. log : dict A dictionary for recording log data. model : object The model this object belongs to. p : object 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 .. py:attribute:: unique_id .. py:attribute:: id :value: 'Object' .. py:attribute:: type :value: 'Object' .. py:attribute:: log .. py:attribute:: model :value: None .. py:property:: vars :type: list[str] .. py:method:: 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) .. py:method:: 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 :class:`Agent` or :func:`Model.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 .. py:class:: GroupedObject(**kwargs: Any) Bases: :py:obj:`Object` A grouped simulation object that extends the NamedObject class. Attributes ---------- group : str, optional The unique ID of the entity's group. Methods ------- Inherits methods from NamedObject class. .. py:attribute:: group