`num_of_loaded_sims` counts the blank lines of an outputs log

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

メンテナーはふだん 3 日以内に返信

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

評価

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

調査の方向性

まず、issueで言及されているoutput_fileセッターと_read_log_fileおよび_checkpoint_rowsリーダーを読んでください。セッターが.txtと.csvのログの行数を数える方法と、これらのリーダーが返す行(空行を含む)を比較してください。num_of_loaded_simsが両方の形式で読み込まれた行数と一致し、再現手順がsimulateの呼び出しまで進めば完了です。

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

説明

Describe the bug

set_num_of_loaded_sims counts every line of a .txt outputs log, blank ones included, and every line after the header of a .csv one. _read_log_file and _checkpoint_rows skip blank lines, so a log with one has a num_of_loaded_sims larger than len(outputs_log).

simulate_convergence uses that count as its budget, and info() and the message printed when a log is loaded report it.

To Reproduce

import pathlib
import tempfile

from rocketpy import MonteCarlo


def simulate(**kwargs):
    raise RuntimeError("simulate called")


folder = pathlib.Path(tempfile.mkdtemp())
(folder / "study.outputs.txt").write_text(
    '{"index": 0, "apogee": 1.0}\n\n{"index": 1, "apogee": 2.0}\n\n'
)
mc = MonteCarlo.__new__(MonteCarlo)
mc.filename = folder / "study"
mc.simulate = simulate

history = mc.simulate_convergence(
    target_attribute="apogee", tolerance=1e-9, max_simulations=4, batch_size=2
)
# A total of 4 simulation results were loaded from: .../study.outputs.txt
print(len(mc.outputs_log), mc.num_of_loaded_sims, history)  # 2 4 []

No RuntimeError, so simulate is never called. __new__ and the replaced simulate only keep flights out of the example; the count comes from the output_file setter. A .csv log with a blank line between two rows counts 3.

Run on develop at d3cf83a7.

Expected behavior

num_of_loaded_sims matches the rows the readers return. The example above then goes on to simulate, where the stub raises instead of running two more flights.

Additional context

Raised in the review of #1198: https://github.com/RocketPy-Team/RocketPy/pull/1198#issuecomment-7365111426. On that branch the new "The logs already hold N simulations" warning reads this count, so the example above also warns that the logs hold 4.

主要言語
Python
スター
1.1k
フォーク
280
平均マージ
3日 2時間
マージ済み PR(30日)
24

環境構築

はじめの一歩

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

RocketPy-Team/RocketPy のほかの issue

RocketPy-Team/RocketPy の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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