Package: dworp
DworpFlexible framework for building agent-based modeling simulations.Requirementspython 3InstallationInstall using pip (maybe be pip3 on some platforms):pipinstalldworpTo install with the optional plotting capability:pipinstalldworp[plot]This will install dependencies required bydworp.plot(currently only matplotlib).UsingDworp defines basic interfaces for building simulations and provides some
default components to support rapid creation of agent-based models.AgentAnAgentupdates its state in thestep()function.
The update may depend on the environment, its neighbors, past history, or other features.An agent has two optional functionsinit()andcomplete().
Theinit()function is called when an agent is added to the simulation.
Thecomplete()function is called at the end of a time step.classMyAgent(dworp.Agent):defstep(self,now,env):# ToDo add example herepassVisibility of Agent StateWhen agents are updating their state based on their neighbors' state,
you may want to use a two stage update mechanism.
In the first stage, the agents update their state privately so that their neighbors
cannot see the new state.
In the second stage, the agents make that state public to prepare for the next time step.EnvironmentTheEnvironmentcaptures all simulation state that does not live in the agents.
This includes serving as a container for network or spatial information for determining neighbors.TimeTimedrives the simulation and implements an iterator interface.
It can be fixed in length or infinite.
Time steps can be fixed in length or variable.
Time can be integer or floating point.SpaceAgents can observe or interact with other agents based on neighborhoods.
A neighborhood may be defined on a network using various graph frameworks like igraph or snap.
A neighborhood can also be spatially defined on a grid or continuous space.TerminatorTo stop the simulation when some condition is met, use aTerminator.ScheduleThe order that agents update and which agents update is determined by theScheduler.
Some basic schedulers are provided for round robin updates in random order or uniformly sampling.ObserverAnObserverruns after each time step.
It is designed for capturing data for further processing.
It has access to the agents and the environment.
Multiple observers can be chained together usingChainedObserver.SimulationTheSimulationinterface defines a single realization of an agent-based simulation.
Basic implementations for single stage and double stage updates are provided.
Usually, you will want to inherit from one of those to define your simulation.LoggingEach component has its own logger:self.logger.info("Agent{}set activity to{}".format(self.agent_id,self.activity))The logging level can be controlled at the framework level:logging.getLogger('dworp').setLevel(logging.WARN)or at the individual component level:logging.getLogger('dworp.agent').setLevel(logging.DEBUG)For more information on log levels or log configuration, read thepython logging docs.ExamplesThe best way to learn the framework is by looking at the example models and their documentation.TestingInstall the test requirements:pipinstall-rtest_requirements.txtThen to run the tests (while in the base directory):nosetestsThis will run all the tests.
To skip the plotting unit tests which require matplotlib, do this:nosetests-a'!plot'To get a report on unit test coverage:nosetests--with-coverage--cover-package=dworpDevelopmentTo install in editable model so that changes to the framework are instantly reflected:pipinstall-e.The code mostly follows thePEP8 coding standard.
If you are using PyCharm, it will highlight PEP8 issues.
You can also manually run style checks with flake8 (pip install flake8):flake8dworpThe docstrings are using theGoogle standard.