align AgentDataSet with NumpyAgentDataSet by supporting agent class input
Summary
This change allows AgentDataSet to accept an agent class. When a class is passed, agents are retrieved using model.agents_by_type. This brings it in line with how NumpyAgentDataSet works.
Fixes part of #3341
Motivation
AgentDataSet and NumpyAgentDataSet currently use different inputs (AgentSet vs agent class). This makes their APIs inconsistent and harder to use together. This change makes both datasets follow the same pattern.
Implementation
- AgentDataSet now accepts either an AgentSet or an agent class
- When given a class, agents are taken from model.agents_by_type
- Existing behavior using AgentSet is unchanged
Performance benchmarks:
| Model | Size | Init time [95% CI] | Run time [95% CI] |
|---|---|---|---|
| BoltzmannWealth | small | π΅ +0.8% [+0.5%, +1.1%] | π΅ +0.0% [-0.1%, +0.2%] |
| BoltzmannWealth | large | π΅ -1.0% [-1.6%, -0.3%] | π΅ +1.1% [+0.4%, +2.3%] |
| Schelling | small | π΅ -0.8% [-0.9%, -0.6%] | π΅ -0.0% [-0.1%, +0.1%] |
| Schelling | large | π΅ -0.5% [-1.1%, -0.1%] | π΅ +2.1% [+1.9%, +2.4%] |
| WolfSheep | small | π΅ +0.8% [+0.5%, +1.0%] | π΅ +0.9% [+0.7%, +1.1%] |
| WolfSheep | large | π΄ +8.3% [+6.7%, +9.6%] | π΄ +16.4% [+15.0%, +17.9%] |
| SugarscapeG1mt | small | π΄ +3.6% [+3.1%, +4.0%] | π΅ +1.6% [+1.4%, +1.8%] |
| SugarscapeG1mt | large | π΅ +2.4% [+0.9%, +4.0%] | π΅ +1.2% [+0.9%, +1.5%] |
| BoidFlockers | small | π΅ -1.9% [-2.3%, -1.6%] | π΅ -0.5% [-0.6%, -0.3%] |
| BoidFlockers | large | π΅ -1.9% [-2.5%, -1.3%] | π΅ -0.8% [-1.0%, -0.6%] |
I am not sure this PR achieves its stated aims. I wanted to primarily change AgentDataSet, not track_agents.
my idea here was to keep the change at the registry level so users could pass either an AgentSet or an Agent class without changing the dataset api. since most usage goes through DataRegistry anyway, i thought that it was simplest way to line up AgentDataSet and NumpyAgentDataSet from the outside.
looking at it again, this doesnβt really align the datasets themselves, it just hides the difference at the entry point. it also ends up pulling the model into the registry just to resolve agent classes, which isnβt great either. i'll move this towards updating AgentDataSet to take an agent class directly and keep the registry thin.
@quaquel Apologies for the delay, I was wrapping up my proposal. I've updated the PR to align AgentDataSet with NumpyAgentDataSet and cleaned up the implementation and tests. Everything should be ready for review now, thanks.