-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Unified time and event scheduling API v2 #2932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
EwoutH
wants to merge
7
commits into
projectmesa:main
Choose a base branch
from
EwoutH:unified_time_api_v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces a unified time and event scheduling API directly into the Model class, eliminating the need for separate Simulator objects. The core insight is that users shouldn't need to manage two objects (Model and Simulator) to run a simulation. By integrating scheduling into Model, we get a cleaner API: model.run(until=100) instead of creating a simulator, calling setup(), then run_until(). Implementation uses composition: a new Scheduler class handles all event scheduling and execution logic, while Model provides thin delegation methods. This keeps Model focused on agents and state while Scheduler handles time. Key changes: - Add Scheduler class in mesa/experimental/devs/scheduler.py - Add Model.schedule() for event scheduling (at= or after= syntax) - Add Model.run() with multiple termination options - Add Model.cancel() for canceling scheduled events - Deprecate ABMSimulator/DEVSimulator (still functional with warnings) Part of the unified time/event scheduling proposal (projectmesa#2921).
Fixes three issues: 1. The `_simulator` attribute was removed but tests still expect it 2. The `step()` method doesn't increment `steps` anymore when using the new event-driven approach 3. Tests expect the simulator to control time via `_simulator` attribute ## Issues ### 1. Missing `_simulator` attribute The new implementation removed `model._simulator` but some tests still check for it. Since the Simulator classes are now deprecated wrappers, we don't need this attribute. ### 2. `step()` doesn't increment counters In the new implementation, when a model has an overridden `step()` method without `@scheduled`, it wraps it to auto-increment. However, the base `Model.step()` is just a pass, so calling it directly doesn't do anything. ### 3. Time management changed The new design uses the Scheduler internally, so there's no `_simulator` attribute to track. ## Fixes The three failing tests were fixed by: 1. **`test_model_set_up` - Missing `_simulator` attribute**: Added `self._simulator = None` in `Model.__init__()` for backward compatibility with existing tests. 2. **`test_model_time_increment` - Steps counter not incrementing**: Modified `_setup_step_handling()` to wrap even the base `Model.step()` method in legacy mode. This ensures that calling `model.step()` directly (as tests do) still increments `steps` and `time`. 3. **`test_model_time_with_simulator` - Simulator not setting `_simulator`**: Modified `Simulator.setup()` to set `model._simulator = self` and `Simulator.reset()` to clear it with `model._simulator = None`. The key insight is that the implementation needs to maintain backward compatibility with: - Direct calls to `model.step()` (legacy behavior) - Tests checking for `model._simulator` - The Simulator API setting `_simulator` All of this is done while still supporting the new `@scheduled` decorator and event-driven approaches for new code.
Not something we're going to support anymore
|
Performance benchmarks:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Second implementation of #2921.
All existing tests pass!