Skip to content

Human Modules

Major human module

Bases: CompositeModule, HumanModule, _LinkContainer

The Base Human Module.

Source code in abses/human.py
def __init__(self, model: MainModel[Any, Any], name: str = "human"):
    HumanModule.__init__(self, model, name)
    CompositeModule.__init__(self, model, name=name)
    _LinkContainer.__init__(self)

Human submodule

Bases: Module

The Human sub-module base class.

Note

Look at this tutorial to understand the model structure.

Attributes:

Name Type Description
agents _AgentsContainer

The agents container of this ABSESpy model.

collections Set[str]

Actor collections defined.

Source code in abses/human.py
def __init__(self, model: MainModel[Any, Any], name: Optional[str] = None):
    Module.__init__(self, model, name)
    self._collections: Dict[str, Selection] = {}

agents property

agents

The agents container of this ABSESpy model.

collections property

collections

Actor collections defined.

actors

actors(name=None)

Different selections of agents

Source code in abses/human.py
def actors(self, name: Optional[str] = None) -> ActorsList[Actor]:
    """Different selections of agents"""
    if name is None:
        return self.agents.get()
    if name not in self._collections:
        raise KeyError(f"{name} is not defined.")
    selection = self._collections[name]
    return self.actors().select(selection)

define

define(name, selection)

Define a query of actors and save it into collections.

Parameters:

Name Type Description Default
name str

defined name of this group of actors.

required
selection Selection

Selection query of Actor.

required

Raises:

Type Description
KeyError

If the name is already defined.

Returns:

Type Description
ActorsList[Actor]

The list of actors who are satisfied the query condition.

Example
# Create 5 actors to query
model=MainModel()
model.agents.new(Actor, 5)

module = HumanModule(model=model)
actors = module.define(name='first', selection='ids=0')
>>> len(actors)
>>> 1

>>> module.actors('first') == actors
>>> True
Source code in abses/human.py
def define(self, name: str, selection: Selection) -> ActorsList[Actor]:
    """Define a query of actors and save it into collections.

    Parameters:
        name:
            defined name of this group of actors.
        selection:
            Selection query of `Actor`.

    Raises:
        KeyError:
            If the name is already defined.

    Returns:
        The list of actors who are satisfied the query condition.

    Example:
        ```
        # Create 5 actors to query
        model=MainModel()
        model.agents.new(Actor, 5)

        module = HumanModule(model=model)
        actors = module.define(name='first', selection='ids=0')
        >>> len(actors)
        >>> 1

        >>> module.actors('first') == actors
        >>> True
        ```
    """
    if name in self._collections:
        raise KeyError(f"{name} is already defined.")
    selected = self.actors().select(selection)
    self._collections[name] = selection
    return selected