Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ against `tests/baselines/nordic_baseline.npz` via `tools/compare_trj.py`.
`-1` and a message naming `sim_minmaxvolt`; a run that completes cleanly is
the regression. `RAMSESError` is not exported at package level: import it
from `stepss.globals`.
- **A 0 flag does not mean the run reached STOP.** Up to RAMSES 3.84 the
engine ended a run on `Divergence. Simulation stopped` by setting its end
flag alone, so `ramses()` returned 0 exactly as for a finished run; later
engines return -1 with the message in `getLastErr()`. Older engines, and
any other early end the engine does not flag, are why `execSim()` and
`contSim()` also compare `getSimTime()` with the STOP time of the `.dst`
and raise `RAMSESError`, quoting the engine's last `t = ...` line from the
trace file, when the run fell short. Keep that check even once the bundled
engine flags divergence. `endSim()` skips the check
(ending early is its job), and so does `$LATENCY` early stopping, which the
engine logs as `All equipment is latent`. `tests/test_divergence.py` drives
the engine's divergence branch with an unreachable `$NEWTON_TOLER` and
accepts either route, and pins the STOP-time check against a fake engine.
- **Do not call `endSim()` after the trip.** It raises a second, unrelated
`RAMSESError` ("Load records") that masks the real result. `obs.trj` is
already complete without it.
Expand Down
27 changes: 27 additions & 0 deletions src/stepss/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ def _dstProblem(dstfile):
'ends at its STOP time, so add a line such as "240.0 STOP".' % dstfile)


def _dstStopTime(dstfile):
"""Return the time of the first STOP record in *dstfile*, or None.

Reads the file the way :func:`_dstProblem` does. None means there is no
STOP time to compare against (unreadable file, no STOP, or a STOP whose
time is not a number), which callers take as "do not check".

:param str dstfile: path to the disturbance file.
:rtype: float or None
"""
try:
with open(dstfile, 'r', encoding='utf-8', errors='replace') as records_file:
for line in records_file:
text = line.strip()
if not text or text[0] in '#!':
continue
time, space, description = text.partition(' ')
if space and 'STOP' in description:
try:
return float(time)
except ValueError:
return None
except IOError:
pass
return None


class cfg(object):
"""Simulation case configuration.

Expand Down
Loading
Loading