Report error for bigger timesteps

オープン 初心者向け
#250 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

simba/report.pyの、report.generate内のSoCスライスと末尾値のロジック付近(275~293行あたり)から始めてください。空のスライスとNoneのみのスライスがどのように動作するかを確認し、その後、interval > 1で、1つのintervalより短いローテーションを使ったテストを追加してください。完了条件は、レポートの生成が完了し、ローテーションの最小値と到着時SoCが少なくとも1つの値から計算されることです。

索引モデルが issue の本文から書いたものです。

説明

bug low prio

Report crashes with IndexError if a rotation is shorter than the simulation interval

Description

With a larger simulation interval (e.g. interval = 15), the report mode aborts while
building the per-rotation SoC time series:

[ERROR] IndexError during report: list index out of range
Traceback (most recent call last):
  File "simba/simulate.py", line 111, in modes_simulation
    schedule, scenario = func(schedule, scenario, args, i)
  File "simba/simulate.py", line 301, in report
    report.generate(schedule, scenario, args)
  File "simba/report.py", line 293, in generate
    rotation_soc_ts[last_known_idx + 1:] = i * [rotation_soc_ts[last_known_idx]]
IndexError: list index out of range

The simulation itself finishes. Only the report is incomplete: rotation_summary,
rotation_socs, cost outputs and everything generated after this point are missing.

Cause

report.generate (simba/report.py, around lines 275–293) cuts the vehicle SoC time series to
the rotation:

start_idx = (rotation.departure_time - sim_start_time) // interval
end_idx = start_idx + ((rotation.arrival_time - rotation.departure_time) // interval)
...
rotation_soc_ts = vehicle_soc[start_idx:end_idx]

for i, soc in enumerate(reversed(rotation_soc_ts)):
    if soc is not None:
        break
last_known_idx = len(rotation_soc_ts) - 1 - i
rotation_soc_ts[last_known_idx + 1:] = i * [rotation_soc_ts[last_known_idx]]

If a rotation is shorter than one interval, end_idx == start_idx and rotation_soc_ts is
empty. Then:

  • the for loop does not run, so i keeps its value from a previous rotation (or is undefined
    for the first rotation, which gives a NameError),
  • last_known_idx becomes negative,
  • rotation_soc_ts[last_known_idx] on the empty list raises IndexError.

A related edge case: if all values in the slice are None, the loop ends without break and
last_known_idx is -1. The trailing values are then filled from the last element (None),
so no crash, but no meaningful SoC either.

With interval = 1 this practically never happens. With interval = 15 short rotations
(e.g. a 10-minute empty run between two depots) are common.

Steps to reproduce

  1. Use a schedule that contains a rotation shorter than 15 minutes.
  2. Set interval = 15 and mode = ["sim", "report"].
  3. Run SimBA. The report aborts with the IndexError above.

Expected behaviour

The report is generated for any interval. A rotation shorter than one interval gets at least
one SoC value (e.g. the value at the step containing its departure), and its Minimum_SOC /
SOC_at_arrival are computed from that.

Possible fix

  • Make the slice contain at least one step, e.g. end_idx = max(end_idx, start_idx + 1)
    (round the arrival up to the next step instead of down).
  • Handle an empty or all-None slice explicitly instead of relying on the loop variable i
    after the loop.
  • Add a test with interval > 1 and a rotation shorter than one interval.

Related observation

Larger intervals also change the simulation results systematically: arrivals and departures are
handled at full time steps, so vehicles with short standing times lose charging time. In a
comparison of interval = 1 vs. interval = 15 on the same schedule, the number of rotations
with negative SoC increased several-fold, while charged energy (±0.2 %) and peak power of large
depots (±3 %) barely changed. This is a modelling limitation rather than a bug, but could be
mentioned in the docs for interval.

主要言語
Python
スター
4
フォーク
1
平均マージ
2日 21時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rl-institut/SimBA のほかの issue

rl-institut/SimBA の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。