jaxabm.agentpy.AgentList

class jaxabm.agentpy.AgentList(model, n, agent_class, **kwargs)[source]

Bases: object

Container for managing collections of agents.

This class provides an AgentPy-like interface for managing groups of agents.

Example

```python # In Model.setup(): self.agents = AgentList(self, 10, MyAgent)

# Access agent attributes: x_positions = self.agents.x # Returns array of x values

# Filter agents: active_agents = self.agents.select(lambda agents: agents.active) ```

__init__(model, n, agent_class, **kwargs)[source]

Initialize agent list.

Parameters:
  • model (Model) – The model the agents belong to.

  • n (int) – Number of agents to create.

  • agent_class (Type[Agent]) – The Agent class to use.

  • **kwargs – Parameters to pass to the agents.

Methods

__init__(model, n, agent_class, **kwargs)

Initialize agent list.

select(condition)

Select agents that satisfy a condition.

Attributes

states

Get all agent states.

property states: Dict[str, Any]

Get all agent states.

Returns:

Dictionary of agent state variables.

__getattr__(name)[source]

Get agent attribute for all agents.

This allows getting arrays of attribute values, e.g., agents.x.

Parameters:

name (str) – Attribute name.

Return type:

Any

Returns:

Array of attribute values.

Raises:

AttributeError – If attribute not found.

__len__()[source]

Get number of agents.

Return type:

int

Returns:

Number of agents.

select(condition)[source]

Select agents that satisfy a condition.

Parameters:

condition (Callable[[Any], Any]) – Function that takes agent attributes and returns a boolean array or mask.

Return type:

AgentList

Returns:

New AgentList with selected agents.

__iter__()[source]

Allow iteration over agents.

This returns the actual agent instances stored in the model, allowing access to custom methods.

Yields:

Agent instances with appropriate state.