AgentModel is the central class of the Emergent framework. It manages a graph of agents, their data, and the simulation loop, including initialization, per-tick logic, and convergence detection.
Default parameters
The following parameters are set on construction and can be modified at any time viaupdate_parameters or subscript assignment.
| Parameter | Default | Description |
|---|---|---|
num_nodes | 3 | Number of nodes in the graph |
graph_type | "complete" | Graph topology: "complete", "cycle", or anything else (wheel) |
convergence_data_key | None | Node attribute key to watch for convergence |
convergence_std_dev | 100 | Convergence threshold (standard deviation) |
MAX_TIMESTEPS | 100000 | Maximum timesteps before the simulation is forced to stop |
__init__()
Initializes the model with default parameters and an uninitialized graph.None. You must call initialize_graph() before running the simulation. The initial_data_function and timestep_function attributes are also None until explicitly set.
update_parameters
A dictionary of parameter names to their new values. Any key is accepted, including custom keys beyond the four built-in parameters.
delete_parameters
A list of parameter key strings to delete. If omitted or
None, all parameters are reset to their default values. Built-in parameter keys (num_nodes, graph_type, convergence_data_key, convergence_std_dev) and keys that do not exist will raise a KeyError.Returns
True if the deletion was successful.list_parameters
update_parameters.
A list of parameter name strings in their current insertion order.
change_max_timesteps
MAX_TIMESTEPS limit used by run_to_convergence. The default limit is 100000.
The new maximum number of timesteps. The simulation will stop after this many ticks even if convergence has not been reached.
Subscript access — model[key] / model[key] = value
The model supports subscript syntax for reading and writing individual parameters.set_graph
initialize_graph. Use this when you need full control over graph topology.
A NetworkX
Graph instance. Passing a value that is not a nx.Graph raises an Exception.get_graph
The
nx.Graph instance currently held by the model. Returns None if the graph has not been initialized or set.set_initial_data_function
initialize_graph will call once per node to produce its starting data. The function receives the model instance and must return a dictionary.
A callable with the signature
(model: AgentModel) -> dict. The returned dictionary is merged into the node’s attribute store.set_timestep_function
timestep will invoke on each tick. The function receives the model instance and is responsible for updating node data directly on the graph.
A callable with the signature
(model: AgentModel) -> None. The function should mutate node attributes on model.get_graph() directly.initialize_graph
num_nodes and graph_type parameters, then seeds each node by calling initial_data_function once per node.
Supported graph_type values:
| Value | Graph topology |
|---|---|
"complete" | nx.complete_graph — every node connected to every other |
"cycle" | nx.cycle_graph — nodes arranged in a ring |
| anything else | nx.wheel_graph — one hub node connected to all others |
timestep
timestep_function.
run_to_convergence
timestep in a loop until the model is considered converged (via is_converged) or MAX_TIMESTEPS is reached, whichever comes first.
Convergence is determined by convergence_data_key and convergence_std_dev. The loop checks convergence before each tick, so a model that starts converged returns 0.
The number of timesteps executed before the simulation stopped.
is_converged
data_key across all nodes have a standard deviation at or below std_dev.
The node attribute key whose values are collected across all nodes and tested for convergence.
The maximum allowable standard deviation. The model is considered converged when the actual standard deviation is less than or equal to this value.
True if the standard deviation of data_key values across all nodes is less than or equal to std_dev. False otherwise.