Population Managers
The Population class is the central engine of AMBER’s high-performance architecture. It implements the Structure of Arrays (SoA) memory layout using Polars DataFrames and provides the interface for vectorized state updates.
Population
- class ambr.population.Population(schema: Dict[str, Type] = None)[source]
Bases:
objectManages the columnar state of all agents using Polars DataFrames. Acts as the single point of truth for agent data.
Prefer writing through the model/view API (
model.agents.col = ...,agents.set(...),agents.commit(...), orModel._set_frame) so the snapshot-view contract can observe commits. Assigningpopulation.data = ...still works but is deprecated and invisible toModel.run(contract=...); use the view API instead.- add_agent(agent_id: int, step: int = 0, **attributes)[source]
Adds a single agent to the population.
- batch_add_agents(count: int, step: int = 0, **attributes)[source]
Adds multiple agents efficiently.
- batch_update(updates: Dict[str, ndarray | list], selector: Expr | None = None)[source]
Deprecated: use
agents.set(**cols)oragents.where(...).set(...).
- batch_update_by_ids(ids: list | ndarray, data: Dict[str, list | ndarray | Any])[source]
Deprecated: use
agents.at[ids].set(**data).
- create_batch_context()[source]
Legacy batched-update context manager.
Deprecated since version Prefer: the vectorized view API:
model.agents.at[ids].col = valuesormodel.agents.at[ids].scatter_add(col=delta). The view API flushes through the same hash-join path but is discoverable via attribute access rather than a context manager.
- property data: DataFrame
Read the agent table (single system of record).
- replace_frame(df: DataFrame) None[source]
Replace the table without deprecation (Model write path only).