neofoam.framework.initialization.init_step

Lazy Initialization

Provides the InitStep dataclass for deferred initialization with dependency tracking.

class neofoam.framework.initialization.init_step.InitStep(name: str, depends_on: list[str] = <factory>, initializer: ~typing.Callable[[dict[str, ~typing.Any]], ~typing.Any] = None, category: str = 'resource')[source]

Bases: object

A deferred initialization step that declares its dependencies.

InitStep objects are returned from BUILD stage methods and collected by the initializer. They are then topologically sorted by dependencies and executed in the correct order.

Attributes:

name: Unique identifier (e.g., “fields.U”, “operators.momentum”) depends_on: List of dependency names that must be initialized first initializer: Lazy function that produces the runtime object using context category: Optional category for grouping (e.g., “fields”, “operators”)

Example:
InitStep(

name=”fields.U”, depends_on=[“mesh”], initializer=lambda ctx: create_vector_field(ctx[“mesh”], U0)

)

exception neofoam.framework.initialization.init_step.InitStepExecutionError(step_name: str, depends_on: list[str], cause: Exception)[source]

Bases: RuntimeError

Raised when an InitStep’s initializer fails during execution.

Attributes:

step_name: Name of the InitStep that failed. depends_on: Dependencies declared by the failed step.