Skip to content

add next_scheduled_time property to EventGenerator#3423

Merged
quaquel merged 4 commits intomesa:mainfrom
souro26:event-generator-introspection
Mar 4, 2026
Merged

add next_scheduled_time property to EventGenerator#3423
quaquel merged 4 commits intomesa:mainfrom
souro26:event-generator-introspection

Conversation

@souro26
Copy link
Copy Markdown
Contributor

@souro26 souro26 commented Mar 3, 2026

Summary

This PR adds a property next_scheduled_time to EventGenerator. It exposes the time of the next scheduled execution, or None if no event is currently scheduled.

Part of the event generator improvements in #3420.

Motive

Currently there is no simple way to inspect when an EventGenerator will execute next without accessing internal attributes such as _current_event. For debugging, monitoring, or higher-level scheduling logic it is useful to know when the next execution is scheduled. This change exposes that information through a small explicit public API.

Implementation

A new read-only property next_scheduled_time was added to EventGenerator. It returns the time of the currently scheduled event and None when no event is scheduled. It relies on the existing internal _current_event state.

Usage Examples

gen = EventGenerator(model, fn, Schedule(interval=2.0))
gen.start()
print(gen.next_scheduled_time)  # for example 2.0
gen.stop()
print(gen.next_scheduled_time)  # None

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 3, 2026

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -3.3% [-4.0%, -2.5%] 🔵 -3.1% [-3.6%, -2.6%]
BoltzmannWealth large 🔵 -1.5% [-2.4%, -0.4%] 🔵 -4.0% [-6.8%, -1.1%]
Schelling small 🔵 +1.5% [+1.0%, +1.9%] 🔵 +1.1% [+0.9%, +1.3%]
Schelling large 🔵 +0.2% [-0.3%, +0.9%] 🔵 +0.3% [-1.4%, +1.8%]
WolfSheep small 🔵 -0.6% [-1.0%, -0.1%] 🔵 -1.2% [-1.4%, -1.0%]
WolfSheep large 🔵 -0.2% [-2.0%, +1.2%] 🔵 -0.1% [-2.2%, +1.9%]
BoidFlockers small 🔵 +1.4% [+0.9%, +1.9%] 🔵 -0.3% [-0.5%, -0.2%]
BoidFlockers large 🔵 +2.3% [+1.7%, +2.8%] 🔵 -0.8% [-1.0%, -0.6%]

return self._current_event.time

@property
def is_scheduled(self) -> bool:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this not redundant with is_active?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right it slipped my mind, they are redundant. i'll remove is_scheduled

return self._execution_count

@property
def next_time(self) -> float | None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def next_time(self) -> float | None:
def next_scheduled_time(self) -> float | None:

@souro26 souro26 force-pushed the event-generator-introspection branch from 55d8d61 to 4545145 Compare March 3, 2026 14:15
@quaquel
Copy link
Copy Markdown
Member

quaquel commented Mar 4, 2026

  1. Please update your tests. They are failing because you still test for is_scheduled
  2. Update the pr description so it reflects the actual thing done in this PR.

@souro26 souro26 force-pushed the event-generator-introspection branch from 96c1191 to 4c0aa26 Compare March 4, 2026 08:39
@souro26 souro26 changed the title add next_time and is_scheduled properties to EventGenerator add next_scheduled_time property to EventGenerator Mar 4, 2026
@souro26
Copy link
Copy Markdown
Contributor Author

souro26 commented Mar 4, 2026

thanks for the review, i've updated the PR title, description and tests.

@quaquel quaquel merged commit bfda9f2 into mesa:main Mar 4, 2026
14 checks passed
@EwoutH EwoutH added the enhancement Release notes label label Mar 13, 2026
@EwoutH
Copy link
Copy Markdown
Member

EwoutH commented Mar 13, 2026

@quaquel feel free to (also) tag me as a reviewer on time / event PRs.

@EwoutH EwoutH mentioned this pull request Mar 13, 2026
42 tasks
EwoutH pushed a commit that referenced this pull request Mar 15, 2026
* add next_time and is_scheduled properties to EventGenerator

* changed property name

* improved tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
EwoutH pushed a commit that referenced this pull request Mar 15, 2026
* add next_time and is_scheduled properties to EventGenerator

* changed property name

* improved tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Release notes label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants