Get started in 5 minutes¶
Get ABSESpy
running¶
In progress
This document is a work in progress if you see any errors, or exclusions or have any problems, please get in touch with us.
Assuming you've successfully installed ABSESpy
, along with all its dependencies, and properly configured the environment to import the module into your workspace. Running the first blank model that performs no action is straightforward - simply import, initialize, and run...
# %pip install abses
from abses import MainModel
# Initialize a model instance
model = MainModel()
# You can check state of the model by `.summary()`.
model.summary()
Using ABSESpy version: v0.6.2
name MainModel state init tick 0 dtype: object
# run it for 5 steps.
model.run_model(steps=5)
ABSESpy two basic modules¶
type(model.human)
abses.human.BaseHuman
type(model.nature)
abses.nature.BaseNature
The default BaseNature and BaseHuman classes can be used to build custom classes that better reflect the needs of a particular application. In order to use a custom module must be passed to the MainModel
constructor as keyword arguments human
and nature
.
from abses import BaseNature, BaseHuman
class Nature(BaseNature):
"""A custom Nature module."""
def step(self):
print(f"Nature in the step {self.time.tick}")
class Human(BaseHuman):
"""A custom Human module."""
def step(self):
print(f"Human in the step {self.time.tick}")
model = MainModel(human_class=Human, nature_class=Nature)
model.run_model(steps=3)
Nature in the step 0 Human in the step 0 Nature in the step 1 Human in the step 1 Nature in the step 2 Human in the step 2
ABSESpy will also log certain messages to allow a better, real-time understanding of the model's progression.
from abses import Actor, MainModel
class MyActor(Actor):
"""A customized actor"""
def say_hi(self) -> str:
print(f"Hello, world! I'm a new {self.breed}!")
model = MainModel()
actors = model.agents.new(Actor, 5)
my_actor = model.agents.new(MyActor, singleton=True)
my_actor.say_hi()
print(model.agents)
Hello, world! I'm a new MyActor! ModelAgents
from abses import MainModel, Actor
class MyModel(MainModel):
"""Customized model."""
def setup(self):
n_agents = self.params.get("init_agents")
self.agents.new(Actor, n_agents)
def step(self):
# `p` is a shortcut for `params`
n_agents = self.p.get("n_agents")
self.agents.new(Actor, n_agents)
def end(self):
n_agents = len(self.agents)
print(f"At step {self.time.tick}, there are {n_agents} actors.")
parameters = {
"time": {
"start": "2000-01-01",
"end": "2003-03-21",
"months": 8,
"years": 2,
},
"model": {"init_agents": 5, "n_agents": 1},
}
model = MyModel(parameters=parameters)
model.run_model()
At step 2, there are 7 actors.
model.summary(verbose=True)
Using ABSESpy version: v0.6.2
name MyModel state complete tick 2 Actor 7 model_vars () agent_vars () dtype: object