`num_of_loaded_sims` counts the blank lines of an outputs log

Offen Anfängerfreundlich
#1,255 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python
Bereich
backend, data

Rechercherichtung

Lies zuerst den output_file-Setter sowie die im Issue erwähnten Reader _read_log_file und _checkpoint_rows. Vergleiche, wie der Setter die Zeilen in .txt- und .csv-Logs zählt, mit den Zeilen, die diese Reader zurückgeben, einschließlich Leerzeilen. Fertig ist die Arbeit, wenn num_of_loaded_sims bei beiden Formaten mit den geladenen Zeilen übereinstimmt und die Reproduktion anschließend simulate aufruft.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.

Vorherrschende Sprache
Python
Sterne
1.1k
Forks
280
Ø Merge
3 T. 2 Std.
Gemergte PRs (30 T.)
24

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus RocketPy-Team/RocketPy

Alle Issues in RocketPy-Team/RocketPy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.