Prerequisites
- Python 3.10.7 or later
- pip or uv
Create the model
An By default the model is configured with the following parameters:
Override any of these with
AgentModel is the central object in every Emergent simulation. It holds your graph, your parameters, and the functions that define how agents behave.simulation.py
| Parameter | Default | Description |
|---|---|---|
num_nodes | 3 | Number of agents in the graph |
graph_type | "complete" | Graph topology ("complete", "cycle", or "wheel") |
convergence_data_key | None | Node attribute to monitor for convergence |
convergence_std_dev | 100 | Standard deviation threshold for convergence |
update_parameters:simulation.py
convergence_data_key must be set to the name of a node attribute before calling run_to_convergence. The simulation stops when the standard deviation of that attribute across all nodes falls below convergence_std_dev.Define agent behaviors
You supply two functions to the model:
initial_data_function— called once per node when the graph is initialized. Returns a dictionary of node attributes.timestep_function— called once per timestep. Updates node attributes in place.
simulation.py
Initialize the graph
initialize_graph creates the networkx graph based on num_nodes and graph_type, then calls your initial_data_function once for each node.simulation.py
simulation.py
Complete example
Here is the full opinion dynamics simulation in a single file:simulation.py
Next steps
Agent model
Full API reference for
AgentModel, including all parameters and methods.Graph structures
Learn about the built-in graph types and how to supply a custom networkx graph.
Defining behaviors
Patterns for writing initial data and timestep functions for complex simulations.
Examples
Explore NK landscape fitness, homogenization, and other ready-to-run examples.