Skip to content

Add deprecation warnings to model.step() and run_model() - #3330

Closed
codebyNJ wants to merge 2 commits into
mesa:mainfrom
codebyNJ:deprecate-step-run-model
Closed

codebyNJ wants to merge 2 commits into
mesa:mainfrom
codebyNJ:deprecate-step-run-model

Conversation

@codebyNJ

Copy link
Copy Markdown
Contributor

Summary

  • Add FutureWarning to model.step() and model.run_model(), guiding users toward model.run_for() / model.run_until()
  • Update internal Mesa code (batchrunner.py) to use run_for(1) instead of step()
  • Migrate tests from model.step() to model.run_for(1) and add deprecation warning tests

Addresses the tracking item in #3132:

  • Add deprecation warnings to model.step() and run_model()

Changes

File Change
mesa/model.py FutureWarning in _wrapped_step() and run_model()
mesa/batchrunner.py model.step() → model.run_for(1) internally
tests/test_model.py Migrated to run_for(1), added 2 deprecation warning tests
tests/test_schedule_run.py m1.step() → m1.run_for(1)
tests/test_lifespan.py self.step() → self.run_for(1)
tests/experimental/test_meta_agents.py model.step() → model.run_for(1)
tests/test_datacollector.py Added pytestmark to filter FutureWarning
tests/experimental/test_datarecorder.py Added pytestmark to filter FutureWarning

Design decisions

  • FutureWarning (not DeprecationWarning): Visible to end users by default, consistent with the Simulator deprecation pattern in Mesa
  • run_model() bypasses self.step(): Calls self._advance_time() directly to avoid emitting a double warning (one from run_model + one from step)
  • Tests use filterwarnings where model.step() is not the focus of the test (e.g., DataCollector tests), and migrated to run_for(1) where feasible

Test plan

  • All 437 core tests pass with -Werror (matching CI configuration)
  • test_step_deprecation_warning verifies model.step() emits FutureWarning
  • test_run_model_deprecation_warning verifies model.run_model() emits FutureWarning

@codebyNJ
codebyNJ marked this pull request as draft February 17, 2026 03:48
@github-actions

Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.4% [-2.8%, -2.0%] 🔵 +0.2% [-0.2%, +0.6%]
BoltzmannWealth large 🔵 -2.3% [-2.7%, -1.9%] 🔵 -0.9% [-1.2%, -0.7%]
Schelling small 🔵 -1.0% [-1.3%, -0.8%] 🔵 +0.7% [+0.5%, +0.8%]
Schelling large 🔵 -1.0% [-1.4%, -0.6%] 🔵 +0.9% [+0.4%, +1.5%]
WolfSheep small 🔵 -1.4% [-1.6%, -1.1%] 🔵 -1.9% [-2.1%, -1.8%]
WolfSheep large 🔵 -0.9% [-1.6%, -0.2%] 🔵 -2.4% [-2.6%, -2.1%]
BoidFlockers small 🔵 -1.3% [-1.6%, -1.0%] 🔵 -0.1% [-0.3%, +0.0%]
BoidFlockers large 🔵 -1.3% [-1.6%, -1.0%] 🔵 -0.1% [-0.4%, +0.2%]

@quaquel

quaquel commented Feb 17, 2026

Copy link
Copy Markdown
Member

main is already on 4.0, so these warnings are not useful here. Rather, we want to first develop 4.0, and then once we have a fair sense of everything that is changing, we can work on the 3.x branch and add in warnings there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants