validate.logs#
Maintain the logs of an analysis.
Error log: Text file recording per-patient errors only (one line each), one per invocation.
Task log: task_log.yaml in the analysis directory, written only by the tool. Holds one settings hash per tab (decides whether that tab’s runs may resume), one entry per invocation with the tab that ran, its provenance ID, software commits and hardware, and per-patient results:
patients: pt001: segment: {<AI model>: {status, run, files, labels, warnings}} ntcp: {status, value | message, run, warnings}
Results recorded to the task log are tied to the chosen settings. Modifying the settings clears associated results from the task log (after you confirm), so the two always match. Output files are kept until the tab is re-run.
Functions
|
Provenance of one AI model install: its number, name, install folder, code commit (and whether it has uncommitted changes), and hashes of its models.yaml and weights. |
|
Remove a tab's results from every patient in task_log.yaml and forget its settings hash, so the tab can run with new settings. |
Collect the messages of UserWarnings raised inside the block, without printing them, so they can be written to task_log.yaml. |
|
|
Mark this invocation as finished and write task_log.yaml. |
|
Write segment_summary.csv in analysisDir from the task log's segment results: one row per patient, AI model, output file and label. |
|
True if aiModel ran successfully for patientId and all its recorded output files (relative to analysisDir) still exist. |
|
|
|
Model-tab provenance: the hash of the dosimetric model file. |
|
Return the task log in analysisDir, or None if there is none yet. |
|
Store one patient's result and write task_log.yaml. |
|
Store run-level warnings (e.g. from building the DataCapsule) under this invocation's entry and write task_log.yaml. |
|
{tab: SHA-256 of the settings that tab's results depend on (core.analysis.tabSettings)}, in canonical form, so formatting, key order and comments don't change them. |
|
Open task_log.yaml for a new invocation of a tab. |
|
Write task_log.yaml atomically (temporary file, then rename). |
Classes
|
Per-invocation failure log: one line per per-patient error, nothing else. |
Exceptions
|
A tab's settings changed since its results in task_log.yaml were made. |
- class validate.logs.ErrorLog(analysisDir)[source]#
Bases:
objectPer-invocation failure log: one line per per-patient error, nothing else.
- exception validate.logs.SettingsChangedError(tab, path)[source]#
Bases:
ValueErrorA tab’s settings changed since its results in task_log.yaml were made. Its results can be cleared (clearResults) so the tab can run again.
- validate.logs.settingsHashes(settingsPath)[source]#
{tab: SHA-256 of the settings that tab’s results depend on (core.analysis.tabSettings)}, in canonical form, so formatting, key order and comments don’t change them.
- validate.logs.readTaskLog(analysisDir)[source]#
Return the task log in analysisDir, or None if there is none yet.
- Raises:
ValueError – task_log.yaml can’t be read, isn’t a task log, or was written by an earlier version of validate.
- validate.logs.startRun(analysisDir, settingsPath, tab, errorLogPath=None, details=None)[source]#
Open task_log.yaml for a new invocation of a tab.
Creates task_log.yaml, or resumes it if the tab’s settings hash matches the current settings (or the tab hasn’t run yet). Appends this invocation’s tab, provenance, device, hardware and error log file.
- Parameters:
analysisDir (str) – analysis folder holding task_log.yaml.
settingsPath (str) – path to the analysis settings file.
tab (str) – “segment” or “model”.
errorLogPath (str or None) – this invocation’s error log; recorded relative to analysisDir.
details (dict or None) – tab-specific provenance added to the software provenance (see modelFileProvenance, aiModelProvenance).
- Returns:
(taskLog, runIndex) – the task log dict and this invocation’s index in taskLog[“runs”].
- Raises:
SettingsChangedError – the tab’s settings changed since its results were made.
ValueError – task_log.yaml exists but can’t be read or isn’t a task log.
- validate.logs.clearResults(analysisDir, tab)[source]#
Remove a tab’s results from every patient in task_log.yaml and forget its settings hash, so the tab can run with new settings. Runs (provenance) are kept.
- Returns:
dict or None – the updated task log, or None if there is none.
- validate.logs.recordResult(analysisDir, taskLog, runIndex, patientId, section, result, key=None, warningMessages=None)[source]#
Store one patient’s result and write task_log.yaml.
The result is stored under taskLog[“patients”][patientId][section], or [section][key] when key is given (e.g. the AI model’s name under “segment”), with the run that made it and any warnings.
- validate.logs.isSegmented(analysisDir, taskLog, patientId, aiModel)[source]#
True if aiModel ran successfully for patientId and all its recorded output files (relative to analysisDir) still exist.
- validate.logs.generateSummary(analysisDir)[source]#
Write segment_summary.csv in analysisDir from the task log’s segment results: one row per patient, AI model, output file and label.
- Returns:
str – path to the CSV.
- Raises:
FileNotFoundError – there is no task log in analysisDir yet.
- validate.logs.recordRunWarnings(analysisDir, taskLog, runIndex, warningMessages)[source]#
Store run-level warnings (e.g. from building the DataCapsule) under this invocation’s entry and write task_log.yaml.
- validate.logs.collectWarnings()[source]#
Collect the messages of UserWarnings raised inside the block, without printing them, so they can be written to task_log.yaml.
Usage:
with collectWarnings() as messages: ... # messages now holds the unique warning texts, in order
- validate.logs.finishRun(analysisDir, taskLog, runIndex)[source]#
Mark this invocation as finished and write task_log.yaml.
- validate.logs.writeTaskLog(analysisDir, taskLog)[source]#
Write task_log.yaml atomically (temporary file, then rename).
- validate.logs.modelFileProvenance(modelFile)[source]#
Model-tab provenance: the hash of the dosimetric model file.
- validate.logs.aiModelProvenance(aiModel, installDir, weightsSha256=None)[source]#
Provenance of one AI model install: its number, name, install folder, code commit (and whether it has uncommitted changes), and hashes of its models.yaml and weights. weightsSha256 comes from the install record, since hashing the weights on every run is slow.