This document provides a comprehensive, exhaustive reference for all public classes, functions, and interfaces in the haloexec package.
- haloexec.engine
- haloexec.disk.workspace
- haloexec.disk.backend
- haloexec.disk.convergence
- haloexec.disk.sync_model
- haloexec.disk.cellular_automaton
- haloexec.disk.io.geotiff
- haloexec.disk.io.zarr
- haloexec.ram.cellular_automaton
- haloexec.ram.sync_model
- haloexec.visualization
Primitivas de decomposição de domínio sem dependências externas.
@dataclass(frozen=True)
class Block:
r0: int
r1: int
c0: int
c1: intRepresents an immutable 2D rectangular sub-domain slice
shape -> tuple[int, int]: Returns(r1 - r0, c1 - c0).core -> tuple[slice, slice]: Returns(slice(r0, r1), slice(c0, c1)), ready for direct NumPy indexing into global arrays or memory-mapped files.
def make_blocks(height: int, width: int, block_h: int, block_w: int) -> list[Block]Partitions a 2D global grid of dimensions (height, width) into regular sub-domains of maximum size (block_h, block_w).
height(int): Global domain row count.width(int): Global domain column count.block_h(int): Target block height.block_w(int): Target block width.
list[Block]: Sequential list of blocks covering the entire domain. Edge blocks along the south and east boundaries contain residual dimensions when dimensions are not evenly divisible.
def resolve_boundary_value(boundary_value: dict[str, float] | float, name: str) -> floatResolves the external ghost cell fill value for a given array.
boundary_value(dict | float): Scalar constant or dictionary mapping array names to fill values.name(str): Name of the array to resolve.
float: Resolved boundary sentinel. Ifnameends with"_past"and does not have an explicit key in aboundary_valuedict, automatically falls back to the base name without"_past". If not found, defaults to0.
Gerenciador de arrays bidimensionais em disco baseados em np.memmap com suporte a double-buffering e checkpoints.
@dataclass(frozen=True)
class HaloWindow:
global_slices: tuple[slice, slice]
core_offset: tuple[int, int]Describes a disk read window clipped at domain boundaries.
global_slices: Slice coordinates to read from the disk array.core_offset:(row_offset, col_offset)of the core block within the read window.
def halo_window(block: Block, shape: tuple[int, int], halo: int) -> HaloWindowComputes the clipped read window coordinates for a block with halo
class MemmapRasterWorkspace:
METADATA = "metadata.json"
CHECKPOINT = "checkpoint.json"@classmethod
def create(
cls,
root: Path,
shape: tuple[int, int],
arrays: dict[str, np.dtype],
block_h: int,
block_w: int,
halo: int = 1,
) -> MemmapRasterWorkspaceInitializes a new on-disk workspace directory structure containing double-buffered .dat files for slots "a" and "b".
- Files are allocated as POSIX sparse files (unwritten blocks consume 0 disk space).
- Raises
FileExistsErrorifrootexists and is non-empty.
def __init__(self, root: Path) -> NoneOpens an existing initialized workspace from disk. Loads metadata.json and checkpoint.json.
def blocks(self) -> list[Block]Returns all domain blocks partitioned according to the workspace's metadata.
def fill(self, name: str, array: np.ndarray, slot: str | None = None) -> NonePopulates an entire array layer in the specified slot (defaults to active read_slot). Intended for initial state setup.
def read_block_with_halo(self, block: Block, boundary_value: dict | float = 0) -> dict[str, np.ndarray]Extracts the halo window for all arrays from the active read_slot. Populates boundary ghost cells with boundary_value.
def write_block_core(self, block: Block, values: dict[str, np.ndarray]) -> NoneWrites the updated core regions (excluding halo) into the write slot (the inactive ping-pong slot).
def read_block_core(self, block: Block, name: str) -> np.ndarrayReads strictly the core region of an array from the active read_slot.
def write_block_to_read_slot(self, block: Block, name: str, values: np.ndarray) -> NoneWrites core block data directly into the active read slot. Reserved for synchronizing <name>_past arrays.
def write_block_core_in_place(self, block: Block, values: dict[str, np.ndarray]) -> NoneWrites core block data directly into the active read slot, making changes immediately visible to subsequent blocks in the same pass (used for Gauss-Seidel convergence).
def swap_buffers(self) -> NoneLogically inverts the active read_slot ("a" "b").
def checkpoint(self, step: int) -> NonePersists the current simulation step and active slot atomically to checkpoint.json.
def snapshot(self, name: str) -> np.ndarrayMaterializes a full copy of an array from the active read slot in RAM (use only for validation or small grids).
def flush(self) -> NoneForces an explicit sync of memory-mapped buffers to physical storage.
def as_backend(self, stride: int = 1, nodata_value: float | int | None = None) -> WorkspaceRasterBackendCreates a lightweight RasterBackend adapter for visualization and inspection.
class WorkspaceRasterBackend:
def __init__(
self,
workspace: MemmapRasterWorkspace,
stride: int = 1,
nodata_value: float | int | None = None,
) -> NoneExposes a MemmapRasterWorkspace through the RasterBackend duck-type interface without duplicating memory.
-
workspace(MemmapRasterWorkspace): The underlying disk workspace. -
stride(int): Spatial subsampling decimation factor ($1 = \text{full resolution}$ ,$2 = 50%$ , etc.). -
nodata_value(float | int | None): Optional sentinel for extent mask resolution.
arrays -> dict[str, np.ndarray]: Dictionary of memory-mapped views onto the active read slot, sliced with::stride.shape -> tuple[int, int]: Scaled grid shape(H // stride, W // stride).
def sweep_until_convergence(
workspace: MemmapRasterWorkspace,
rule: Callable[[dict[str, np.ndarray]], dict[str, np.ndarray]],
boundary_value: dict | float = 0,
max_sweeps: int | None = None,
) -> dict[str, Any]Executes iterative block sweeps until an entire global pass produces zero modified blocks.
-
workspace(MemmapRasterWorkspace): Target workspace. -
rule(Callable): Transition function receiving a halo window dictionary and returning updated core arrays. -
boundary_value: Fill sentinel for external boundary ghost cells. -
max_sweeps(int, optional): Safety limit. Defaults to$\text{number of blocks} + 1$ .
dict: Summary containing{"sweeps": int, "blocks_changed_total": int, "converged": True}.
RuntimeError: If convergence is not achieved withinmax_sweeps.
def workspace_arrays_for_sync_model(
base: dict[str, np.dtype],
land_use_types: list[str],
) -> dict[str, np.dtype]Constructs the array declaration dictionary for a workspace, automatically adding <name>_past entries for all variables in land_use_types.
class DiskChunkedSyncRasterModel:
def setup(
self,
workspace: MemmapRasterWorkspace,
halo: int | None = None,
boundary_value: float | dict = 0,
**kwargs,
) -> NoneCooperative mixin for executing SyncRasterModel subclasses (e.g., FloodModel) out-of-core on a MemmapRasterWorkspace.
- Must precede the scientific model in class inheritance order:
class FloodModelDisk(DiskChunkedSyncRasterModel, FloodModel): pass - Handles block-by-block
_pastsynchronization inpre_execute()andpost_execute().
class DiskChunkedRasterCellularAutomaton:
def setup(
self,
workspace: MemmapRasterWorkspace,
halo: int | None = None,
boundary_value: dict | float = 0,
state_attr: str = "state",
**kwargs,
) -> NoneCooperative mixin for executing RasterCellularAutomaton subclasses (defined with rule(arrays) -> dict) out-of-core on a MemmapRasterWorkspace.
def load_geotiff_into_workspace(
workspace: MemmapRasterWorkspace,
path: str | Path,
band_spec: list[tuple[str, str, float]],
) -> NoneLoads a single GeoTIFF file into a workspace block-by-block using windowed streaming.
def load_geotiffs_into_workspace(
workspace: MemmapRasterWorkspace,
sources: list[tuple[str | Path, list[tuple[str, str, float]]]],
) -> NoneLoads multiple GeoTIFF files into a workspace simultaneously across blocks, validating shape and CRS alignment.
def save_workspace_to_geotiff(
workspace: MemmapRasterWorkspace,
path: str | Path,
bands: list[str] | list[tuple[str, str, float]],
transform: Any = None,
crs: Any = "EPSG:31984",
compress: str = "lzw",
) -> NoneExports workspace arrays from the active read slot directly into a tiled Cloud-Optimized GeoTIFF.
def load_zarr_into_workspace(
workspace: MemmapRasterWorkspace,
store: str | Path,
variable_map: dict[str, str] | None = None,
time_index: int | None = None,
) -> NoneStreams a Zarr store into a workspace block-by-block, normalizing dimension axis orders.
def load_zarr_tiles_into_workspace(
workspace: MemmapRasterWorkspace,
tiles: list[dict[str, Any]],
array: str | None = None,
fill: float | None = None,
skip_empty_blocks: bool = False,
) -> NoneAssembles multiple distinct Zarr tiles into a unified continuous workspace array.
class HaloChunkedRasterCellularAutomaton(RasterCellularAutomaton):
def setup(
self,
backend: RasterBackend,
block_h: int,
block_w: int,
halo: int = 1,
boundary_value: float | dict = 0,
state_attr: str = "state",
) -> NoneIn-memory domain decomposition execution engine for RasterCellularAutomaton. Preserves the rule(arrays: dict) -> dict interface.
class HaloChunkedSyncRasterModel:
def setup(
self,
backend: RasterBackend,
block_h: int,
block_w: int,
halo: int = 1,
boundary_value: float | dict = 0,
**kwargs,
) -> NoneIn-memory cooperative mixin for executing SyncRasterModel subclasses in blocks with halo.
class CheckpointRasterMap(RasterMap):
def setup(
self,
*args: Any,
save_steps: Iterable[int] | None = None,
**kwargs: Any,
) -> NoneSubclass of RasterMap that restricts map rendering and PNG export to an arbitrary set of simulation steps (save_steps).