-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Making Model reactive #3211
Copy link
Copy link
Closed
Description
As part of various ongoing conversations, it has been suggested to make the Model reactive. Specifically, the idea is that model.time becomes observable and that whenever agents are registered or deregistered, also a signal is emitted.
I started some pathfinding for this.
- Making time observable is trivial. Just let Model extend
HasObservables, and declaretimeas observable is all that is needed. - Making agent registration and deregistration is not straightforward. Mesa signals are built around class-level declarations that stuff is observable. But for
agents, this is currently not easy to do. It is possible to hack around this by just adding "agents" toself.observableswith 2 possible signals (AGENT_ADDEDandAGENT_REMOVED). However, a cleaner solution would be nice. - We recently shifted to using enums for declaring signal types. But the typing for this is tricky. For example,
self.notifyspecifies signal_type to be either aSignalTypeor astr, but for themodel.agentstuff, I declare a new model-specific ModelSignals enum, which breaks typing. - The performance overhead is not bad. Testing locally, I get the numbers below. The init times, I wouldn't worry about much. The main conversation will focus on the wolf-sheep runtime. Here, we see a clear performance loss at runtime. This is due to agents dying and being born, which call
register_agentandderegister_agent, which in turn trigger the emit logic. Some further profiling is probably needed because the overhead is larger than I expected. Remember, in these benchmarks, nothing is listening to these signals.
| Model | Size | Init time [95% CI] | Run time [95% CI] |
|---|---|---|---|
| BoltzmannWealth | small | 🔴 +14.5% [+13.0%, +15.9%] | 🔴 +3.6% [+3.1%, +4.2%] |
| BoltzmannWealth | large | 🔴 +17.8% [+16.0%, +19.3%] | 🔵 +1.8% [-2.9%, +6.3%] |
| Schelling | small | 🔴 +7.8% [+7.0%, +8.5%] | 🔵 +0.1% [-0.8%, +1.1%] |
| Schelling | large | 🔴 +7.5% [+4.9%, +9.8%] | 🔵 +1.2% [-3.8%, +6.1%] |
| WolfSheep | small | 🔴 +21.5% [+20.8%, +22.2%] | 🔴 +4.3% [+3.6%, +5.0%] |
| WolfSheep | large | 🔴 +27.1% [+25.1%, +29.1%] | 🔴 +16.3% [+13.3%, +19.1%] |
| BoidFlockers | small | 🔴 +19.0% [+18.0%, +19.9%] | 🔵 +2.4% [+1.6%, +3.2%] |
| BoidFlockers | large | 🔴 +18.5% [+17.7%, +19.2%] | 🔵 +1.8% [+1.0%, +2.7%] |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels