Backends¶
PiperABM stores model state directly on NetworkX graphs for interoperability and custom analysis.
Infrastructureuses a NetworkX undirected graph (Graph) accessible viamodel.infrastructure.G.Societyuses a NetworkX undirected multigraph (MultiGraph) accessible viamodel.society.G.
Node and edge attributes are stored directly on these graphs. This enables tight integration with the NetworkX ecosystem and supports bulk / vectorized workflows. Direct graph manipulation bypasses validation performed by the high-level API and is therefore intended for advanced users.
Example: validated API vs direct graph access¶
# Safe, validated API
food = model.society.get_resource(agent_id, "food")
model.society.set_resource(agent_id, "food", value=food / 10)
# Advanced usage: direct graph access (bypasses validation)
G = model.society.G
food = G.nodes[agent_id]["food"]
G.nodes[agent_id]["food"] = food / 10
Bulk updates (example)¶
G = model.society.G
for node_id, attrs in G.nodes(data=True):
if attrs.get("type") == "agent" and attrs.get("alive", True):
attrs["food"] *= 0.9