patchworks 0.11.5__tar.gz → 0.11.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {patchworks-0.11.5 → patchworks-0.11.7}/PKG-INFO +1 -1
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/snakemake.md +3 -1
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/Snakefile +5 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/pixi.toml +1 -1
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/profile/slurm/config.yaml +8 -6
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/rules/common.smk +10 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/rules/convert.smk +2 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/rules/merge.smk +2 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/rules/segment.smk +20 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/scripts/_pw.py +51 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/scripts/convert.py +3 -0
- patchworks-0.11.7/workflow/scripts/fetch_model.py +21 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/scripts/merge.py +2 -1
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/scripts/prepare_tiles.py +2 -1
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/scripts/segment_tile.py +2 -1
- {patchworks-0.11.5 → patchworks-0.11.7}/.github/workflows/docs.yml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/.github/workflows/lint.yml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/.github/workflows/release.yml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/.gitignore +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/.markdownlint-cli2.yaml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/README.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/cliff.toml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/chunks.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/cluster.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/io.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/merge_tile_labels.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/plugins/cellpose.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/plugins/napari.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/plugins/ome_zarr.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/relabel.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/api/tile_process.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/cellpose_2d.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/cellpose_2d.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/cellpose_3d.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/cellpose_3d.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/custom.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/custom_method.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/standalone_merge.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/stardist.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/examples/stardist_2d.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/getting_started.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/gpu_distributed.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/merging.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/ome_zarr_napari.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/performance.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/pitfalls.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/skip_empty.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/guide/tiling.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/docs/index.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/mkdocs.yml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/pyproject.toml +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/__init__.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_chunks.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_cluster.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_core.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_distributed.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_io.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_merge.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/_relabel.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/plugins/__init__.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/plugins/cellpose.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/plugins/napari.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/src/patchworks/plugins/ome_zarr.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/tests/test_core.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/tests/test_distributed.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/tests/test_napari.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/tests/test_ome_zarr.py +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/.snakemake/iocache/latest.pkl +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/README.md +0 -0
- {patchworks-0.11.5 → patchworks-0.11.7}/workflow/config/config.yaml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patchworks
|
|
3
|
-
Version: 0.11.
|
|
3
|
+
Version: 0.11.7
|
|
4
4
|
Summary: Tiled processing of arbitrarily large images with globally consistent labels
|
|
5
5
|
Project-URL: Homepage, https://github.com/imcf/patchworks
|
|
6
6
|
Project-URL: Issues, https://github.com/imcf/patchworks/issues
|
|
@@ -223,10 +223,12 @@ prologue. The simplest path is a single shared env that the compute nodes see.
|
|
|
223
223
|
| Symptom | Fix |
|
|
224
224
|
|---------|-----|
|
|
225
225
|
| `snakemake: command not found` | use `python -m snakemake` |
|
|
226
|
-
| Segment jobs pend forever | wrong `slurm_partition
|
|
226
|
+
| Segment jobs pend forever | wrong `slurm_partition`/GPU request; on scicore use `gres: "gpu:1"` |
|
|
227
|
+
| Segment dies, `Network is unreachable` | offline GPU nodes — the `fetch_model` localrule caches the model on the submit host first; if it still fails, your submit host has no network either (pre-download manually) |
|
|
227
228
|
| `cellpose is not installed` in a job | the job's env lacks `patchworks[cellpose]` |
|
|
228
229
|
| Reading the input fails | install the matching reader (`patchworks[imaris]`/`[bioio]` + a `bioio-*`) |
|
|
229
230
|
| Out of GPU memory | smaller `tile_shape`, or `do_3D: false` |
|
|
231
|
+
| A job fails with an empty SLURM log | read `logs/segment/<index>.log` (per tile) or `logs/steps.log` — the real traceback is there |
|
|
230
232
|
| Very slow | confirm GPU is used (`nvidia-smi`); try 2-D or a lower `level` |
|
|
231
233
|
|
|
232
234
|
## How it works (for the curious)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
# On a cluster, put this project on a shared filesystem the compute nodes can
|
|
8
8
|
# read: the SLURM jobs re-launch snakemake from this env's interpreter.
|
|
9
9
|
|
|
10
|
-
[
|
|
10
|
+
[workspace]
|
|
11
11
|
name = "patchworks-workflow"
|
|
12
12
|
channels = ["conda-forge"]
|
|
13
13
|
platforms = ["linux-64"]
|
|
@@ -17,7 +17,7 @@ keep-going: true
|
|
|
17
17
|
|
|
18
18
|
# Defaults for every rule (CPU jobs).
|
|
19
19
|
default-resources:
|
|
20
|
-
slurm_partition: "
|
|
20
|
+
slurm_partition: "scicore"
|
|
21
21
|
# slurm_account: "my_account"
|
|
22
22
|
mem_mb: 16000
|
|
23
23
|
cpus_per_task: 4
|
|
@@ -32,12 +32,14 @@ set-resources:
|
|
|
32
32
|
prepare:
|
|
33
33
|
mem_mb: 32000
|
|
34
34
|
runtime: 120
|
|
35
|
-
segment:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
segment:
|
|
36
|
+
# one GPU per tile — this is what spreads Cellpose across GPUs
|
|
37
|
+
slurm_partition: "rtx4090"
|
|
38
|
+
gpu: 1
|
|
39
|
+
qos: "rtx4090-6hours" # scicore: <partition>-<duration> QOS
|
|
40
|
+
mem_mb: 32000 # plenty — a tile used ~1G; the failure was a Python error
|
|
39
41
|
cpus_per_task: 4
|
|
40
|
-
runtime: 120
|
|
42
|
+
runtime: 360 # 6 hours — must match the QOS, NOT 120 (=2h → killed early)
|
|
41
43
|
merge:
|
|
42
44
|
mem_mb: 128000
|
|
43
45
|
cpus_per_task: 8
|
|
@@ -15,6 +15,16 @@ STAGE = f"{WORK}/stage.zarr"
|
|
|
15
15
|
STAGE_OK = f"{STAGE}.done"
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
# Logs: one shared file for the sequential CPU steps (convert/prepare/merge),
|
|
19
|
+
# one file per tile for the GPU segment jobs.
|
|
20
|
+
LOGS = f"{WORK}/logs"
|
|
21
|
+
STEPLOG = f"{LOGS}/steps.log"
|
|
22
|
+
|
|
23
|
+
# Marker that the segmentation model is cached locally. Produced by a local
|
|
24
|
+
# rule (runs on the networked submit host) so offline GPU nodes never download.
|
|
25
|
+
MODEL_OK = f"{WORK}/model.ready"
|
|
26
|
+
|
|
27
|
+
|
|
18
28
|
def occupied_done(wildcards):
|
|
19
29
|
"""Per-tile markers for the occupied tiles (resolved after the checkpoint)."""
|
|
20
30
|
tiles = checkpoints.prepare.get().output.tiles
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
# Plan tiles (checkpoint) and segment each tile on a GPU.
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
rule fetch_model:
|
|
5
|
+
"""Cache the segmentation model on the (networked) submit host.
|
|
6
|
+
|
|
7
|
+
Declared local (see ``localrules`` in the Snakefile) so it never runs on an
|
|
8
|
+
offline GPU node — Cellpose downloads its weights here, into shared $HOME.
|
|
9
|
+
"""
|
|
10
|
+
output:
|
|
11
|
+
touch(MODEL_OK),
|
|
12
|
+
log:
|
|
13
|
+
f"{LOGS}/fetch_model.log",
|
|
14
|
+
script:
|
|
15
|
+
"../scripts/fetch_model.py"
|
|
16
|
+
|
|
17
|
+
|
|
3
18
|
checkpoint prepare:
|
|
4
19
|
input:
|
|
5
20
|
IMAGE_OK,
|
|
6
21
|
output:
|
|
7
22
|
tiles=TILES,
|
|
8
23
|
stage=touch(STAGE_OK),
|
|
24
|
+
log:
|
|
25
|
+
STEPLOG,
|
|
9
26
|
script:
|
|
10
27
|
"../scripts/prepare_tiles.py"
|
|
11
28
|
|
|
@@ -16,7 +33,10 @@ rule segment:
|
|
|
16
33
|
tiles=TILES,
|
|
17
34
|
stage=STAGE_OK,
|
|
18
35
|
image=IMAGE_OK,
|
|
36
|
+
model=MODEL_OK,
|
|
19
37
|
output:
|
|
20
38
|
f"{WORK}/seg/{{index}}.done",
|
|
39
|
+
log:
|
|
40
|
+
f"{LOGS}/segment/{{index}}.log",
|
|
21
41
|
script:
|
|
22
42
|
"../scripts/segment_tile.py"
|
|
@@ -8,11 +8,62 @@ these helpers only turn the Snakemake config into the right arguments.
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import json
|
|
11
|
+
import logging
|
|
12
|
+
import sys
|
|
11
13
|
from pathlib import Path
|
|
12
14
|
|
|
13
15
|
from patchworks import load_ome_zarr
|
|
14
16
|
|
|
15
17
|
|
|
18
|
+
class _Tee:
|
|
19
|
+
"""Write to several streams at once (e.g. the SLURM log and a file)."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, *streams):
|
|
22
|
+
self._streams = streams
|
|
23
|
+
|
|
24
|
+
def write(self, data):
|
|
25
|
+
for stream in self._streams:
|
|
26
|
+
stream.write(data)
|
|
27
|
+
|
|
28
|
+
def flush(self):
|
|
29
|
+
for stream in self._streams:
|
|
30
|
+
stream.flush()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def start_log(path, *, append=True):
|
|
34
|
+
"""Tee stdout/stderr (and logging) into ``path``.
|
|
35
|
+
|
|
36
|
+
Captures prints, tracebacks and library logging into a file in the work
|
|
37
|
+
directory, independent of the (often empty) SLURM job log. Line-buffered,
|
|
38
|
+
so output up to a crash or OOM kill is preserved.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
path : str or Path
|
|
43
|
+
Log file to write. Parent directories are created.
|
|
44
|
+
append : bool, optional
|
|
45
|
+
Append to an existing log (keep retry history) instead of truncating.
|
|
46
|
+
Default True.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
TextIO
|
|
51
|
+
The open log file (kept open for the lifetime of the process).
|
|
52
|
+
"""
|
|
53
|
+
path = Path(path)
|
|
54
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
55
|
+
handle = open(path, "a" if append else "w", buffering=1)
|
|
56
|
+
sys.stdout = _Tee(sys.__stdout__, handle)
|
|
57
|
+
sys.stderr = _Tee(sys.__stderr__, handle)
|
|
58
|
+
logging.basicConfig(
|
|
59
|
+
level=logging.INFO,
|
|
60
|
+
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
|
61
|
+
handlers=[logging.StreamHandler(sys.stdout)],
|
|
62
|
+
force=True,
|
|
63
|
+
)
|
|
64
|
+
return handle
|
|
65
|
+
|
|
66
|
+
|
|
16
67
|
def open_image(work_dir, channel, level):
|
|
17
68
|
"""Open the converted image for segmentation.
|
|
18
69
|
|
|
@@ -8,6 +8,9 @@ conversion is not redone. To force a fresh conversion, delete ``image.zarr``
|
|
|
8
8
|
|
|
9
9
|
from patchworks.plugins.ome_zarr import to_ome_zarr
|
|
10
10
|
|
|
11
|
+
from _pw import start_log
|
|
12
|
+
|
|
13
|
+
start_log(snakemake.log[0]) # noqa: F821
|
|
11
14
|
cfg = snakemake.config # noqa: F821 (injected by Snakemake)
|
|
12
15
|
chunks = cfg.get("convert_chunks")
|
|
13
16
|
to_ome_zarr(
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Snakemake (local) script: cache the segmentation model before segmenting.
|
|
2
|
+
|
|
3
|
+
Runs on the submit host, which has network access, so the offline GPU nodes
|
|
4
|
+
never try to download Cellpose weights at run time (they read the shared
|
|
5
|
+
``$HOME/.cellpose`` cache instead).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from _pw import start_log
|
|
9
|
+
|
|
10
|
+
start_log(snakemake.log[0]) # noqa: F821
|
|
11
|
+
cfg = snakemake.config # noqa: F821
|
|
12
|
+
|
|
13
|
+
if cfg.get("method", "cellpose") == "cellpose":
|
|
14
|
+
# _get_model downloads + caches the weights keyed by (model, gpu).
|
|
15
|
+
from patchworks.plugins.cellpose import _get_model
|
|
16
|
+
|
|
17
|
+
model = cfg["cellpose"]["model"]
|
|
18
|
+
_get_model({"model": model, "gpu": False})
|
|
19
|
+
print(f"[patchworks] cached segmentation model: {model}")
|
|
20
|
+
else:
|
|
21
|
+
print(f"[patchworks] method={cfg.get('method')!r}; no model to prefetch")
|
|
@@ -11,8 +11,9 @@ from pathlib import Path
|
|
|
11
11
|
from patchworks import merge_tile_labels
|
|
12
12
|
from patchworks.plugins.ome_zarr import write_labels
|
|
13
13
|
|
|
14
|
-
from _pw import stage_path
|
|
14
|
+
from _pw import stage_path, start_log
|
|
15
15
|
|
|
16
|
+
start_log(snakemake.log[0]) # noqa: F821
|
|
16
17
|
cfg = snakemake.config # noqa: F821
|
|
17
18
|
work_dir = cfg["work_dir"]
|
|
18
19
|
image_store = str(Path(work_dir) / "image.zarr")
|
|
@@ -11,8 +11,9 @@ from patchworks import (
|
|
|
11
11
|
spatial_tiles,
|
|
12
12
|
)
|
|
13
13
|
|
|
14
|
-
from _pw import open_image, stage_path
|
|
14
|
+
from _pw import open_image, stage_path, start_log
|
|
15
15
|
|
|
16
|
+
start_log(snakemake.log[0]) # noqa: F821
|
|
16
17
|
cfg = snakemake.config # noqa: F821
|
|
17
18
|
work_dir = cfg["work_dir"]
|
|
18
19
|
image = open_image(work_dir, cfg["channel"], cfg["level"])
|
|
@@ -6,8 +6,9 @@ run in parallel. Each job writes a disjoint chunk of the stage store.
|
|
|
6
6
|
|
|
7
7
|
from patchworks import stage_tile
|
|
8
8
|
|
|
9
|
-
from _pw import build_fn, load_tiles_json, open_image, stage_path
|
|
9
|
+
from _pw import build_fn, load_tiles_json, open_image, stage_path, start_log
|
|
10
10
|
|
|
11
|
+
start_log(snakemake.log[0]) # noqa: F821
|
|
11
12
|
cfg = snakemake.config # noqa: F821
|
|
12
13
|
index = int(snakemake.wildcards.index) # noqa: F821
|
|
13
14
|
work_dir = cfg["work_dir"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|