Repository navigation
fix(model): preserve float type for model.time in _advance_time - #4057
sundeep8967 wants to merge 2 commits into
Conversation
|
Performance benchmarks:
|
|
Thanks for the clear explanation of the bug and for adding tests for both cases ! One question: the fix casts when model.time is assigned. Would it be better to also convert to a float when the event is created? In schedule_event, at is passed straight into Event(...), so event.time can still be an int (for example at=2). Any other code that reads event.time would still see an int. |
dd190c4 to
20428a2
Compare
|
Good catch @arzaanxeng! That makes complete sense. I have updated |
|
#4052 also fixes #4051, with conversion only when assigning Automated triage note, written by an AI model for the Mesa maintainers. It can be wrong, and it doesn't make decisions: maintainers do. If it missed the point, say so here. |
Fixes mesa#4051 Ensure model.time remains a float when time is advanced with integer values in run_until() or when events are scheduled at integer timestamps. Previously, _advance_time directly assigned until and event.time without casting, clobbering the annotated float type and propagating integer time to subsequent step() calls and data recorders. Signed-off-by: sundeep8967 <[email protected]>
20428a2 to
082bee1
Compare
|
With #4052 merged, I fail to see the relevance of this. |
Pre-PR Checklist
[x] This PR is a bug fix, not a new feature or enhancement.
Summary
Ensure
model.timeremains a float when time is advanced with integer values inrun_until()or when events are scheduled at integer timestamps.Bug / Issue
Fixes #4051
In
Model._advance_time():self.time = event.timewas assigned without casting.self.time = untilassigneduntildirectly.run_until(5)or scheduled at an integer time,self.timebecame anint, clobbering the annotatedfloattype._wrapped_step()advances time viaself.time + 1, subsequent steps remainedint(5 + 1 = 6), causing mixed int/float types in outputs such asJSONDataRecorder.Implementation
until = float(until)andself.time = float(event.time)inmesa/model.py.tests/test_schedule_run.pycoveringrun_untilwith integer times and scheduled events with integer timestamps, verifying thatmodel.timeretains float type and continues to advance as float.Testing
uv run pytest tests/test_schedule_run.py: 25 passed.uv run --with pre-commit pre-commit run --files mesa/model.py tests/test_schedule_run.py: all hooks passed (ruff check, ruff format, pyupgrade, trim trailing whitespace, codespell).