Skip to content

Commit

Permalink
fix: ⚡️ Fix logging, block alignment, tmpdirs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhoadesScholar committed Mar 11, 2024
1 parent ab0a549 commit db7d8aa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
6 changes: 0 additions & 6 deletions dacapo/blockwise/predict_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ def start_worker(
output_size,
voxel_size=output_voxel_size,
)
# # use daisy requests to run pipeline
# pipeline += gp.DaisyRequestBlocks(
# reference=request,
# roi_map={raw: "read_roi", prediction: "write_roi"},
# num_workers=1,
# )

daisy_client = daisy.Client()

Expand Down
10 changes: 9 additions & 1 deletion dacapo/blockwise/relabel_worker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from glob import glob
import os
import sys
from time import sleep

Check warning on line 4 in dacapo/blockwise/relabel_worker.py

View check run for this annotation

Codecov / codecov/patch

dacapo/blockwise/relabel_worker.py#L4

Added line #L4 was not covered by tests
import daisy
from dacapo.compute_context import create_compute_context
from dacapo.store.array_store import LocalArrayIdentifier
Expand Down Expand Up @@ -54,7 +55,14 @@ def start_worker(
if block is None:
break

relabel_in_block(array_out, nodes, components, block)
try:
relabel_in_block(array_out, nodes, components, block)
except OSError as e:
logging.error(

Check warning on line 61 in dacapo/blockwise/relabel_worker.py

View check run for this annotation

Codecov / codecov/patch

dacapo/blockwise/relabel_worker.py#L58-L61

Added lines #L58 - L61 were not covered by tests
f"Failed to relabel block {block.write_roi}: {e}. Trying again."
)
sleep(1)
relabel_in_block(array_out, nodes, components, block)

Check warning on line 65 in dacapo/blockwise/relabel_worker.py

View check run for this annotation

Codecov / codecov/patch

dacapo/blockwise/relabel_worker.py#L64-L65

Added lines #L64 - L65 were not covered by tests


def relabel_in_block(array_out, old_values, new_values, block):
Expand Down
7 changes: 3 additions & 4 deletions dacapo/blockwise/segment_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ def start_worker(
edges = unique_pairs[non_zero_filter]
nodes = np.unique(edges)

print(f"Writing ids to {os.path.join(tmpdir, 'block_%d.npz')}")
assert os.path.exists(tmpdir)
with open(
os.path.join(tmpdir, f"block_{block.block_id[1]}.npz"), "wb"
) as f:
path = os.path.join(tmpdir, f"block_{block.block_id[1]}.npz")
print(f"Writing ids to {path}")
with open(path, "wb") as f:
np.savez_compressed(

Check warning on line 174 in dacapo/blockwise/segment_worker.py

View check run for this annotation

Codecov / codecov/patch

dacapo/blockwise/segment_worker.py#L170-L174

Added lines #L170 - L174 were not covered by tests
f,
nodes=nodes,
Expand Down
2 changes: 2 additions & 0 deletions dacapo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def run_blockwise(
input_array.voxel_size,
output_dtype,
overwrite=overwrite,
write_size=write_roi.shape,
)

_run_blockwise( # type: ignore
Expand Down Expand Up @@ -383,6 +384,7 @@ def segment_blockwise(
input_array.voxel_size,
np.uint64,
overwrite=overwrite,
write_size=write_roi.shape,
)
print(

Check warning on line 389 in dacapo/cli.py

View check run for this annotation

Codecov / codecov/patch

dacapo/cli.py#L389

Added line #L389 was not covered by tests
f"Created output array {output_array_identifier.container}:{output_array_identifier.dataset} with ROI {_total_roi}."
Expand Down
15 changes: 11 additions & 4 deletions dacapo/compute_context/bsub.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import os
from pathlib import Path
from .compute_context import ComputeContext
import daisy

import attr

Expand Down Expand Up @@ -36,6 +39,10 @@ def device(self):
return "cpu"

def _wrap_command(self, command):
client = daisy.Client()
basename = str(

Check warning on line 43 in dacapo/compute_context/bsub.py

View check run for this annotation

Codecov / codecov/patch

dacapo/compute_context/bsub.py#L42-L43

Added lines #L42 - L43 were not covered by tests
Path("./daisy_logs", client.task_id, f"worker_{client.worker_id}")
)
return (
[
"bsub",
Expand All @@ -47,10 +54,10 @@ def _wrap_command(self, command):
f"num={self.num_gpus}",
"-J",
"dacapo",
# "-o",
# f"{run_name}_train.out",
# "-e",
# f"{run_name}_train.err",
"-o",
f"{basename}.out",
"-e",
f"{basename}.err",
]
+ (
[
Expand Down

0 comments on commit db7d8aa

Please sign in to comment.