SubjectResult

Note

This page is a reference documentation. It only explains the class signature, and not how to use it. Please refer to the Habitat Guide and Python API guide (v2.0) for usage.

class SubjectResult(subject_id: str, value: TOut | None, error: BaseException | None, from_cache: bool = False)[source]

Bases: Generic[TOut]

Result slot for one subject, distinguishing success from isolated failure.

Batch habitat analysis must be able to continue when a single subject fails, while still reporting that failure honestly. Returning an explicit result rather than raising keeps that policy in the backend instead of scattering try/except through the algorithms.

subject_id

Subject this result belongs to.

Type:

str

value

Computed result when successful, otherwise None.

Type:

habit.contracts.ops.TOut | None

error

Captured exception when failed, otherwise None.

Type:

BaseException | None

from_cache

Whether the value was restored from a checkpoint instead of being recomputed.

Type:

bool

result() → TOut[source]

Return the value or re-raise the captured failure.

Named after concurrent.futures.Future.result(), the standard-library anchor for “give me the value or re-raise the error”.

Returns:

The successful value.

Raises:

BaseException – The originally captured error, when this result represents a failure.

__init__(subject_id: str, value: TOut | None, error: BaseException | None, from_cache: bool = False) → None

Examples using habit.contracts.SubjectResult

/auto_examples/06_parallel_runs/plot_02_skip_failed

Skipping a subject that fails

/auto_examples/06_parallel_runs/plot_04_resume

Resuming finished subjects

/auto_examples/06_parallel_runs/plot_08_wall_clock

Per-subject wall-clock limit