Skip to content

Reject negative time_delta in schedule_event_relative#2999

Merged
EwoutH merged 2 commits intomesa:mainfrom
Nithin9585:fix-devs-time-travel
Dec 23, 2025
Merged

Reject negative time_delta in schedule_event_relative#2999
EwoutH merged 2 commits intomesa:mainfrom
Nithin9585:fix-devs-time-travel

Conversation

@Nithin9585
Copy link
Copy Markdown
Contributor

Fixes #2998
Adds validation to DEVSimulator.schedule_event_relative() to reject negative time_delta values that would schedule events in the past, preventing causality violations.

Changes

  • mesa/experimental/devs/simulator.py: Added check if time_delta < 0: raise ValueError(...) in schedule_event_relative()
  • tests/test_devs.py: Added test case verifying negative time deltas are rejected

Why This Is Needed

Without this check, users can accidentally schedule events in the past (e.g., when calculating delays for deadlines that have already passed). This causes simulation time to rewind, violating DES causality principles.

Testing

  • All existing tests pass
  • New test case added for negative time delta rejection

@github-actions
Copy link
Copy Markdown

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -1.8% [-2.2%, -1.4%] 🔵 -0.5% [-0.6%, -0.4%]
BoltzmannWealth large 🔵 +1.5% [-0.6%, +4.7%] 🔵 -1.9% [-3.6%, -0.4%]
Schelling small 🔵 -0.1% [-1.2%, +1.0%] 🔵 +1.2% [+0.5%, +1.8%]
Schelling large 🔵 +1.5% [-0.8%, +4.5%] 🔵 +1.5% [-0.1%, +3.2%]
WolfSheep small 🔵 -1.1% [-2.0%, -0.5%] 🔵 -1.3% [-1.9%, -0.6%]
WolfSheep large 🔵 -1.8% [-5.9%, +0.7%] 🔵 +0.1% [-1.1%, +1.3%]
BoidFlockers small 🔵 +1.0% [+0.7%, +1.4%] 🔵 +1.3% [+1.1%, +1.5%]
BoidFlockers large 🔵 +1.5% [+0.9%, +2.0%] 🔵 +1.7% [+1.4%, +2.0%]

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.

Bit of an edge case, but sure.

Thanks for the PR! Could you rebase the PR to handle the test file movement?

@Nithin9585
Copy link
Copy Markdown
Contributor Author

Nithin9585 commented Dec 23, 2025

@EwoutH done! ,any other changes required ?

@EwoutH EwoutH added bug Release notes label maintenance Release notes label and removed bug Release notes label labels Dec 23, 2025
@EwoutH EwoutH changed the title Fix: Reject negative time_delta in schedule_event_relative (Issue #2998) Reject negative time_delta in schedule_event_relative Dec 23, 2025
@EwoutH EwoutH merged commit afaff2c into mesa:main Dec 23, 2025
14 of 15 checks passed
@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Dec 23, 2025

Thanks!

@quaquel in your experience, do these if tests have any noticeable impact on performance?

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Dec 23, 2025

No, this adds virtually no overhead.

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

Labels

maintenance Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DEVSimulator allows time travel (causality violation) with negative time deltas

3 participants