Skip to content

Commit dd1d146

Browse files
committed
Add run settings persistence for interleaved Cellpose cache
1 parent 09af3fa commit dd1d146

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/napari_tmidas/processing_functions/cellpose_segmentation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,33 @@ def _prepare_runtime_distributed_mask(
10471047
os.makedirs(slab_output_root, exist_ok=True)
10481048
print(f"Interleaved slab output cache: {slab_output_root}")
10491049

1050+
# Persist run settings alongside the slab cache for reproducibility
1051+
# and to make restart/resume behavior easy to audit.
1052+
settings_path = os.path.join(slab_output_root, "run_settings.json")
1053+
settings_payload = {
1054+
"saved_at_unix": time.time(),
1055+
"run_signature": run_signature,
1056+
"run_signature_json": run_signature_json,
1057+
"slab_output_cache_key": slab_output_cache_key,
1058+
"checkpoint_path": checkpoint_path,
1059+
"slab_output_root": slab_output_root,
1060+
}
1061+
settings_tmp_path = (
1062+
f"{settings_path}.tmp-{os.getpid()}-{time.time_ns()}"
1063+
)
1064+
try:
1065+
with open(settings_tmp_path, "w", encoding="utf-8") as f:
1066+
json.dump(settings_payload, f, indent=2, sort_keys=True)
1067+
os.replace(settings_tmp_path, settings_path)
1068+
print(f"Saved interleaved run settings to: {settings_path}")
1069+
except Exception as exc:
1070+
with suppress(OSError, FileNotFoundError):
1071+
os.unlink(settings_tmp_path)
1072+
print(
1073+
"Warning: could not persist interleaved run settings "
1074+
f"({exc})"
1075+
)
1076+
10501077
if os.path.exists(checkpoint_path):
10511078
try:
10521079
existing = zarr.open_array(checkpoint_path, mode="r")

0 commit comments

Comments
 (0)