blockrun.engine¶
Block-map engine.
A job is a map over output chunks: tile the output grid into blocks (Block),
and run a per-block function that reads the input it needs, transforms it, and writes its
chunk. Tasks should be idempotent, so a relaunch resumes, and should return small status
values rather than arrays: outputs go to the store, not through the scheduler.
Attributes¶
Classes¶
One output chunk: its grid index and its region in the output volume. |
Functions¶
|
Apply |
|
Wrap |
|
Tile |
Module Contents¶
- class blockrun.engine.Block¶
One output chunk: its grid index and its region in the output volume.
- index: tuple[int, ...]¶
- property shape: tuple[int, ...]¶
- blockrun.engine.block_map(blocks: Sequence[Block], fn: Callable[[Block], Any], *, client: Any | None = None, npartitions: int | None = None, on_result: Callable[[list[Any]], None] | None = None) list[Any]¶
Apply
fnto each block, returning the per-block results.fnmust be top-level / picklable and should return a small status value (write big outputs to the store, not back through the scheduler).on_result, if given, is called with each batch’s results as they arrive, e.g. to record them in aManifestso a run that dies midway leaves an accurate record.With
client=Noneit runs serially in-process. Otherwise blocks are split round-robin intonpartitionsbatches (defaultmin(len(blocks), 512)), one task each, and results stream back throughas_completed.
- blockrun.engine.idempotent(fn: Callable[[Block], Any], is_done: Callable[[Block], bool], *, skipped: Any = 'skipped') Callable[[Block], Any]¶
Wrap
fnso blocks that are already done are skipped.is_doneruns on the worker, so keep it cheap (a store existence or metadata check).
- blockrun.engine.iter_blocks(shape: Sequence[int], chunks: Sequence[int]) Iterator[Block]¶
Tile
shapeinto blocks ofchunks(edge blocks are clipped).Axis order is whatever
shape/chunksuse (canonical(c,) z, y, x).
- blockrun.engine.Region¶