Overview
AgentModel is the single object that ties your simulation together. It holds:
- A parameter store for controlling model behavior
- A NetworkX graph where each node represents one agent
- A pluggable initial data function and timestep function
- Built-in convergence detection
Parameters
Parameters are stored in an internal key-value dictionary. Four keys are built-in and always present:
You can add any additional parameters your simulation needs:
Accessing parameters
Use dictionary-style access to read or set individual parameters:The graph
Emergent uses NetworkX graphs internally. Each node is an agent; node data is a dictionary you populate via your initial data function and mutate in your timestep function.Built-in graph types
Setgraph_type before calling initialize_graph():
Custom graphs
You can bypass the built-in types and provide your own NetworkX graph directly:When using a custom graph, call
set_graph() before initialize_graph(). The initialize_graph() call will populate nodes with data using your initial data function but will not recreate the graph topology.Simulation functions
Initial data function
Called once per node duringinitialize_graph(). Returns a dictionary that is merged into the node’s data store.
Timestep function
Called once per call totimestep(). Receives the model and should mutate graph node data directly.
Convergence
run_to_convergence() runs timesteps in a loop and stops when the standard deviation of a tracked node attribute drops to or below convergence_std_dev.