jaxabm.Model
- class jaxabm.Model(parameters=None, seed=None)[source]
Bases:
objectBase class for agent-based models in JaxABM.
This class provides an AgentPy-like interface for creating and running agent-based models.
Example
```python class MyModel(Model):
- def setup(self):
self.agents = self.add_agents(10, MyAgent) self.env.temperature = 25.0
- def step(self):
# Agents are stepped automatically by default # Add additional model logic here self.env.temperature += 0.1
# Record data self.record(‘temperature’, self.env.temperature)
model = MyModel(parameters) results = model.run() ```
Methods
__init__([parameters, seed])Initialize model.
add_agents(n, agent_class[, name])Add agents to the model.
batch_run(parameter_ranges[, repetitions])Run model with multiple parameter combinations.
compute_metrics(env_state, agent_states, ...)Compute model metrics.
end()Execute code at the end of a simulation.
get_agent(collection_name, agent_id)Get an agent instance by collection name and ID.
record(name, value)Record data for later analysis.
run([steps])Run the model for the specified number of steps.
setup()Set up model.
step()Execute a single time step.
update_state(env_state, agent_states, ...)Update model environment state.
- step()[source]
Execute a single time step.
Override this method to define model behavior. By default, it steps all agent lists.
- Return type:
- end()[source]
Execute code at the end of a simulation.
Override this method to define behavior at the end of a simulation.
- Return type:
- update_state(env_state, agent_states, model_params, key)[source]
Update model environment state.
This method is called by the JAX model to update the environment state based on agent states. By default, it returns the environment state unchanged. Override this method to define custom state update logic.
- compute_metrics(env_state, agent_states, model_params)[source]
Compute model metrics.
This method is called by the JAX model to compute metrics from model state. By default, it returns an empty dictionary. Override this method to define custom metrics.
- get_agent(collection_name, agent_id)[source]
Get an agent instance by collection name and ID.
This allows accessing agent instances for calling custom methods.