mesa icon indicating copy to clipboard operation
mesa copied to clipboard

align AgentDataSet with NumpyAgentDataSet by supporting agent class input

Open souro26 opened this issue 8 months ago β€’ 4 comments

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

souro26 avatar Mar 10 '26 10:03 souro26

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%]

github-actions[bot] avatar Mar 10 '26 10:03 github-actions[bot]

I am not sure this PR achieves its stated aims. I wanted to primarily change AgentDataSet, not track_agents.

quaquel avatar Mar 19 '26 13:03 quaquel

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.

souro26 avatar Mar 19 '26 14:03 souro26

@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.

souro26 avatar Mar 28 '26 11:03 souro26