`num_of_loaded_sims` counts the blank lines of an outputs log

未關閉 適合新手
#1,255 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 3 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
76/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
backend, data

研究方向

首先閱讀 issue 中提到的 output_file setter,以及 _read_log_file 和 _checkpoint_rows reader。比較 setter 對 .txt 和 .csv 記錄行數的計算方式,與這些 reader 傳回的行數(包括空白行)。當 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 小時
30 天內合併 PR
24

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

RocketPy-Team/RocketPy 的其他 Issue

查看 RocketPy-Team/RocketPy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。