Skip to content

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

Open
pranavvadd wants to merge 5 commits into
46/cli-no-weather-apifrom
8/configurable-time-step
Open

pranavvadd wants to merge 5 commits into
46/cli-no-weather-apifrom
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 5 commits October 18, 2026 00:18
TrackConfig gained a required file_path_name field in #60; the test
hit a TypeError before reaching the lap-distance validation it checks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fix test_invalid_track_config for required file_path_name
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

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