Skip to content

Fix:Add agenttype_reporters support to batch_run#3095

Merged
EwoutH merged 3 commits intomesa:mainfrom
BhoomiAgrawal12:fix/agenttype-reporters-batch-run
Jan 9, 2026
Merged

Fix:Add agenttype_reporters support to batch_run#3095
EwoutH merged 3 commits intomesa:mainfrom
BhoomiAgrawal12:fix/agenttype-reporters-batch-run

Conversation

@BhoomiAgrawal12
Copy link
Copy Markdown
Contributor

Summary

Fixes agenttype_reporters not collecting data when using batch_run(), making it impossible to use selective agent data collection with parameter sweeps and parallel execution.

Bug / Issue

Closes #2804

Users reported that agenttype_reporters worked perfectly in regular model runs but failed to collect data when using batch_run().

What was expected: Data from agenttype_reporters should appear in batch_run results, just like agent_reporters data does.

What actually happened: The agenttype data was silently dropped - no errors just missing columns in the results DataFrame.

Implementation

The issue was in the _collect_data() helper function in mesa/batchrunner.py. This function extracts data from the DataCollector after model execution, but it only looked at _agent_records and completely ignored _agenttype_records.

Changes made:

  1. Added iteration through dc._agenttype_records in _collect_data()
  2. Process agenttype data using the same structure as agent data
  3. Combine both into the all_agents_data list for consistent output

It handles all edge cases:

  • Models with only agent_reporters
  • Models with only agenttype_reporters
  • Models with both reporter types
  • Models with neither (model-only data)

Testing

Added test coverage in tests/test_batch_run.py:

  1. test_batch_run_agenttype_reporters(): Verifies agenttype_reporters data is collected correctly

    • Tests with different parameter values (n_agents: [3, 5])
    • Validates correct number of rows (8 agents = 8 rows)
    • Confirms all expected columns are present
  2. test_batch_run_agenttype_and_agent_reporters(): Tests mixed usage of both reporter types

    • Ensures both data types coexist in results
    • Verifies no data loss from either reporter type
    • Checks proper handling of duplicate agent entries

Test Results:

  • All 20 batch_run tests pass (18 existing + 2 new)
  • All datacollection tests pass (no regressions)

Copilot AI review requested due to automatic review settings January 9, 2026 07:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where agenttype_reporters data was silently dropped during batch_run() execution, making it impossible to collect type-specific agent data in parameter sweeps and parallel runs.

Key changes:

  • Added agenttype_reporters data collection logic to _collect_data() in mesa/batchrunner.py
  • Added two comprehensive tests validating agenttype_reporters functionality in batch runs

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
mesa/batchrunner.py Extended _collect_data() to iterate through and collect _agenttype_records alongside existing _agent_records collection
tests/test_batch_run.py Added test_batch_run_agenttype_reporters() and test_batch_run_agenttype_and_agent_reporters() to verify agenttype data collection works correctly in batch runs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 9, 2026

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -0.5% [-0.9%, -0.1%] 🔵 -0.4% [-0.5%, -0.3%]
BoltzmannWealth large 🔵 -0.4% [-0.8%, +0.0%] 🔵 -1.0% [-5.1%, +2.2%]
Schelling small 🔵 -1.5% [-2.4%, -0.5%] 🔵 -0.7% [-1.3%, -0.0%]
Schelling large 🔵 +0.5% [+0.2%, +0.7%] 🟢 -8.8% [-10.5%, -7.2%]
WolfSheep small 🔵 +1.8% [+1.5%, +2.1%] 🔵 -0.3% [-0.5%, +0.0%]
WolfSheep large 🔵 -2.1% [-5.0%, -0.1%] 🔵 +3.6% [+1.5%, +5.5%]
BoidFlockers small 🔵 +1.4% [+1.0%, +1.8%] 🔵 -0.4% [-0.6%, -0.2%]
BoidFlockers large 🔵 +1.8% [+1.3%, +2.2%] 🔵 -0.3% [-0.6%, -0.0%]

@quaquel quaquel added the enhancement Release notes label label Jan 9, 2026
Copy link
Copy Markdown
Member

@EwoutH EwoutH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this, this was really long overdue and probably should have been caught directly when implementing #2300.

It does show the fragility of our batch run and datacollector functions, and the often implicit interaction between them. That might support #2972 (comment).

For now, this is a great fix, and we will include/backport this in a new 3.x release.

@EwoutH EwoutH added bug Release notes label and removed enhancement Release notes label labels Jan 9, 2026
@EwoutH EwoutH merged commit ab57603 into mesa:main Jan 9, 2026
16 checks passed
@BhoomiAgrawal12
Copy link
Copy Markdown
Contributor Author

Thanks @EwoutH for considering my contribution! I would like to work more on this project, it would be great if you can suggest me something that I can pick up. I would be happy to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collecting data from different types of agents (agenttype_reporters)

4 participants