Main Model
abses.core.model.MainModel ¶
MainModel(
parameters=DictConfig({}),
human_class=BaseHuman,
nature_class=BaseNature,
run_id=None,
seed=None,
rng=None,
experiment=None,
**kwargs
)
Bases: Model, BaseStateManager
Base class of a main ABSESpy model.
A MainModel instance represents the core simulation environment that coordinates human and natural subsystems.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Name of the model (defaults to lowercase class name). |
settings |
DictConfig
|
Structured parameters for all model components. Allows nested access like model.nature.params.parameter_name. |
human |
HumanSystemProtocol
|
The Human subsystem module. |
nature |
NatureSystemProtocol
|
The Nature subsystem module. |
time |
TimeDriver
|
Time driver controlling simulation progression. |
params |
DictConfig
|
Model parameters (alias: .p). |
run_id |
int | None
|
Identifier for current model run (useful in batch runs). |
agents |
_ModelAgentsContainer
|
Container for all active agents. Provides methods for agent management. |
actors |
ActorsListProtocol
|
List of all agents currently on the earth (in a PatchCell). |
outpath |
Path
|
Directory path for model outputs. |
version |
str
|
Current version of the model. |
datasets |
DictConfig
|
Available datasets (alias: .ds). |
plot |
DictConfig
|
Visualization interface for the model. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
DictConfig
|
Configuration dictionary for model parameters. |
DictConfig({})
|
human_class
|
Type[HumanSystemProtocol]
|
Class to use for human subsystem (defaults to BaseHuman). |
BaseHuman
|
nature_class
|
Type[NatureSystemProtocol]
|
Class to use for nature subsystem (defaults to BaseNature). |
BaseNature
|
run_id
|
Optional[int]
|
Identifier for this model run. |
None
|
outpath
|
Directory path for model outputs. |
required | |
experiment
|
Optional[ExperimentProtocol]
|
Associated experiment instance. |
None
|
**kwargs
|
Optional[Any]
|
Additional model parameters. |
{}
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If human_class or nature_class are not valid subclasses. |
Source code in abses/core/model.py
name
cached
property
¶
Get the model's name.
Returns:
| Type | Description |
|---|---|
str
|
Model name from settings, or class name if not specified. |
outpath
cached
property
¶
Get the model's output directory path.
Returns:
| Type | Description |
|---|---|
Path
|
Output path from settings, or current directory/model_name if not specified. |
version
cached
property
¶
Get the model's version string.
Returns:
| Type | Description |
|---|---|
str
|
Version from settings, or 'v0' if not specified. |
steps
property
writable
¶
Get the number of steps to run.
Returns:
| Type | Description |
|---|---|
int
|
The configured number of simulation steps. |
run_id
property
¶
The run id of the current model. It's useful in batch run. When running a single model, the run id is None.
settings
property
¶
Structured configuration for all model components.
Allows nested parameter access. Example: If settings = {'nature': {'test': 3}}, Access via: - model.nature.params.test - model.nature.p.test
Returns:
| Type | Description |
|---|---|
DictConfig
|
DictConfig containing all model settings. |
agents
property
¶
Container managing all agents in the model.
Provides methods for: - Accessing agents: agents.select() - Creating agents: agents.new(Actor, num=3) - Registering agent types: agents.register(Actor) - Triggering events: agents.trigger()
Returns:
| Type | Description |
|---|---|
_ModelAgentsContainer
|
The model's agent container instance. |
actors
property
¶
List of all agents currently on the earth.
Returns:
| Type | Description |
|---|---|
ActorsListProtocol
|
ActorsList containing all agents in PatchCells. |
datasets
property
¶
Available datasets for the model.
Returns:
| Type | Description |
|---|---|
DictConfig
|
DictConfig containing dataset configurations. |
do_each ¶
执行每个子系统
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
str | Callable
|
函数名或可调用对象 |
required |
order
|
Tuple[SubSystemName, ...]
|
子系统顺序 |
DEFAULT_RUN_ORDER
|
**kwargs
|
Any
|
其他参数 |
{}
|
Source code in abses/core/model.py
add_name ¶
Add a name to the model's name registry with optional validation.
This method registers names for model components and can enforce uniqueness or existence checks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name to add to the registry. |
required |
check
|
Optional[HowCheckName]
|
Optional validation mode: - 'unique': Raise error if name already exists - 'exists': Raise error if name doesn't exist - None: No validation (default) |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If check method is invalid, or if validation fails. |
Source code in abses/core/model.py
run_model ¶
Executes the model simulation.
Runs through the following phases: 1. Setup phase (model.setup()) 2. Step phase (model.step()) - repeated 3. End phase (model.end())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
Optional[int]
|
Number of steps to run. If None, runs until self.running is False. |
None
|