Skip to content

Make simulation time step configurable end to end (#8) - #97

Merged
Kamal-uva merged 5 commits into
mainfrom
8/configurable-time-step
Oct 25, 2026
Merged

Kamal-uva merged 5 commits into
mainfrom
8/configurable-time-step

Conversation

@pranavvadd

Copy link
Copy Markdown
Contributor

Summary

Makes the simulation time step work end to end. RaceConfig.time_step_minutes already
existed, but weather data was always generated at 1-minute spacing, so any other step
gave a wrong time axis and wrong distance/SoC. Example: with a 5-minute step the race
ended after about 29 minutes of race time (should be about 160) and covered 142 km
instead of 196 km.

Changes

  • sim/weather.py: new resample_to_time_step(), applied to both synthetic and API
    weather. Steps over 1 minute average the data (preserves solar energy), steps under
    1 minute interpolate, and a 1-minute step is unchanged.
  • sim/main.py: new --time-step-minutes option (default 1.0, must be a finite number
    above 0). It replaces the three hardcoded 1.0 values and works for single runs,
    --plan and --speed-sweep.
  • README.md: documents the flag.
  • tests/test_time_step.py: 158 new pytest tests.

Testing

python3 -m pytest tests/test_time_step.py passes. After the fix, distance is 196.2-196.4 km
at every step from 0.5 to 10 minutes. The tests also fail (48 failures) if the old behavior is
restored. They cover resampling, synthetic and API weather, the simulator against a
1-minute baseline, all four strategies, interval-hold, and the CLI.

Related Issue

Closes #8

Notes

  • Adaptive strategies (pi, stepped, interval-hold) react per step, so coarse steps
    aren't identical to the 1-minute run. The tests allow up to 10% distance difference.
  • Add CLI Option To Run Simulator Without Weather API #46 (--no-api-weather) also changes sim/main.py, in different lines. Whichever of the
    two PRs merges second may need a small conflict fix.

pranavvadd and others added 3 commits October 18, 2026 00:42
Weather data was always generated at 1-minute spacing, so any
time_step_minutes other than 1 produced a wrong time axis and wrong
distance/SoC. Resample weather onto the configured step (averaging for
coarser steps, interpolating for finer) and expose --time-step-minutes
on the CLI for single runs, --plan and --speed-sweep.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keep both --no-api-weather and --time-step-minutes flags and both README sections.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pranavvadd
pranavvadd changed the base branch from main to 46/cli-no-weather-api October 18, 2026 21:24
@Kamal-uva

Copy link
Copy Markdown
Contributor

yeah I merged the other one first, so small change for that and another small bug fix, the commits u make on the branch will show up here so we can marge once its handled:

Overall looks good! The test coverage is especially thorough.

One edge case I noticed in resample_to_time_step(): when the time step doesn't evenly divide the race duration (e.g., 7 minutes for a 480-minute race), the final step is treated as a full interval. Since the simulator uses the full dt_minutes for every step, the race can run past its intended end time and overestimate distance and energy consumption.

Could we handle the final partial step and add a test to verify the simulated race duration stays correct for non-divisible time steps?

Otherwise, good

pranavvadd and others added 2 commits October 24, 2026 04:46
With e.g. a 7-minute step over a 480-minute race, the last step was
simulated as a full 7 minutes, so the race ran 3 minutes past its end and
overestimated distance and energy use. Use the real remaining time for the
final step. Adds tests for non-divisible steps (end time, distance, energy,
all strategies).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pranavvadd
pranavvadd changed the base branch from 46/cli-no-weather-api to main October 24, 2026 08:53
@Kamal-uva
Kamal-uva merged commit c674704 into main Oct 25, 2026
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.

Make time step configurable

2 participants