Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
incorporate review findings
  • Loading branch information
Logende committed Dec 24, 2022
commit bfc96c207ce8ccb4baaffaba6c5cce24f9f616b3
8 changes: 4 additions & 4 deletions examples/caching_and_replay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
This example applies caching on the Mesa [Schelling example](https://github.com/projectmesa/mesa-examples/tree/main/examples/Schelling).
It enables a simulation run to be "cached" or in other words recorded. The recorded simulation run is persisted on the local file system and can be replayed at any later point.

It uses the [Mesa-Replay](https://github.com/Logende/mesa-replay) library and puts the Schelling model inside a so-called `CachableModel` wrapper that we name `CachableSchelling`.
From the outside perspective, the new model behaves the same way as the original Schelling model, but additionally supports caching.
It uses the [Mesa-Replay](https://github.com/Logende/mesa-replay) library and puts the Schelling model inside a so-called `CacheableModel` wrapper that we name `CacheableSchelling`.
From the user's perspective, the new model behaves the same way as the original Schelling model, but additionally supports caching.

## Installation

Expand All @@ -31,8 +31,8 @@ Note that this **requires the previous simulation run to have finished** (e.g. a

## Files

* ``run.py``: Launches a model visualization server and uses `CachableModelSchelling` as simulation model
* ``cachablemodel.py``: Implements `CachableModelSchelling` to make the original Schelling model cachable
* ``run.py``: Launches a model visualization server and uses `CacheableModelSchelling` as simulation model
* ``cacheablemodel.py``: Implements `CacheableModelSchelling` to make the original Schelling model cacheable
* ``model.py``: Taken from the original Mesa Schelling example
* ``server.py``: Taken from the original Mesa Schelling example

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from model import Schelling
from mesa_replay import CachableModel, CacheState
from mesa_replay import CacheableModel, CacheState


class CachableSchelling(CachableModel):
"""A wrapper around the original Schelling model to make the simulation cachable and replay-able.
Uses CachableModel from the Mesa-Replay library, which is a decorator that can be put around any regular mesa model
to make it "cachable". From outside, a CachableSchelling instance can be treated like any regular Mesa model.
class CacheableSchelling(CacheableModel):
"""A wrapper around the original Schelling model to make the simulation cacheable and replay-able.
Uses CacheableModel from the Mesa-Replay library, which is a decorator that can be put around any regular mesa model
to make it "cacheable". From outside, a CacheableSchelling instance can be treated like any regular Mesa model.
The only difference is that the model will write the state of every simulation step to a cache file or when in
replay mode use a given cache file to replay that cached simulation run."""

Expand Down
2 changes: 2 additions & 0 deletions examples/caching_and_replay/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mesa
git+https://github.com/Logende/mesa-replay@main#egg=Mesa-Replay
6 changes: 3 additions & 3 deletions examples/caching_and_replay/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
happy_chart,
model_params,
)
from cachablemodel import CachableSchelling
from cacheablemodel import CacheableSchelling

# As 'replay' is a simulation model parameter in this example, we need to make it available as such
model_params["replay"] = mesa.visualization.Checkbox("Replay last run?", False)

server = mesa.visualization.ModularServer(
# Note that Schelling was replaced by CachableSchelling here
CachableSchelling,
# Note that Schelling was replaced by CacheableSchelling here
CacheableSchelling,
[canvas_element, get_happy_agents, happy_chart],
"Schelling",
model_params,
Expand Down