AgentModel instance. It owns the graph of agents, the parameters that control topology and convergence, and the two functions you supply to define agent behavior.
Lifecycle
A simulation follows three stages in order:Initialize
Call After this call the graph is accessible via
initialize_graph() to build the networkx graph and seed every node with data from your initial_data_function.model.get_graph() and every node has the attributes your function returned.Default parameters
A freshly createdAgentModel starts with these built-in parameters:
num_nodes
num_nodes
Number of nodes (agents) to create when
initialize_graph() builds the graph. Has no effect if you supply a custom graph via set_graph().graph_type
graph_type
Topology used by
initialize_graph(). Accepted values are "complete", "cycle", and "wheel". See Graph structures for details on each topology.convergence_data_key
convergence_data_key
The node attribute that
run_to_convergence() and is_converged() monitor. Must be set before calling run_to_convergence(). See Convergence.convergence_std_dev
convergence_std_dev
Standard deviation threshold for convergence. The simulation is considered converged when the standard deviation of
convergence_data_key across all nodes is less than or equal to this value.MAX_TIMESTEPS (default 100000) is not a parameter stored in the parameter dict. Change it with model.change_max_timesteps(n).Accessing and setting parameters
You can read and write any parameter using subscript notation, the same way you access a dictionary:update_parameters and list_parameters. See Parameters for the full parameter API.
Attaching behavior functions
Two functions drive the simulation. Both receive theAgentModel instance as their only argument, giving them full access to the graph and all parameters.
initial_data_function
Called once per node duringinitialize_graph(). Must return a dictionary whose keys become node attributes.
timestep_function
Called once per timestep (each call totimestep() or each iteration of run_to_convergence()). Modifies the graph in place.
Working with the graph directly
Afterinitialize_graph(), retrieve the underlying networkx graph with get_graph():
set_graph(). See Custom graphs for the correct pattern — initialize_graph() always builds a new graph from num_nodes and graph_type, so you must seed the nodes manually when using a custom graph.