For AI agents: see the complete TomoJAX documentation index at llms.txt. This page is also available as Markdown at https://tomojax.dev/api/progress.md or by sending Accept: text/markdown.

tomojax.progress

Synchronous progress events and cooperative cancellation.

NameSummary
AdvancedCompleted units and a snapshot of the associated diagnostics.
CanceledThe operation stopped at a work boundary.
ControlCoordinate pause, resume and cancellation between an owner and a controller.
Event
FinishedThe outcome of an operation.
NoteA message from the watched code.
PausedA task reached a work boundary while paused.
PlacedThe coordinator resolved the devices participating in a task.
PreviewCoherent small arrays copied at one completed work boundary.
ResumedA paused task resumed computation.
StartedAn operation entered by its calling thread.
to_jsonReturn a versioned JSON-compatible record for an event.
watchDeliver events synchronously to a fast handler in the calling context.

Advanced

class Advanced(
    task: int,
    done: int,
    total: int | None,
    metrics: Mapping[str, _Metric],
    time: float,
    eta: float | None = None,
)
Defined in src/tomojax/progress.py:110

Completed units and a snapshot of the associated diagnostics.

Parameters

  • task (int): Task identifier.
  • done (int): Number of completed units.
  • total (int or None): Current estimate of the total units, if known.
  • metrics (mapping): Snapshot of scalar diagnostics for the completed work.
  • time (float): Monotonic seconds since the watch began.
  • eta (float or None, optional): Remaining active seconds at the measured completion rate.

Canceled

class Canceled(message: str = 'canceled', *, checkpoint: str | None = None)
Defined in src/tomojax/errors.py:35

The operation stopped at a work boundary.

Parameters

  • message (str, optional): Why and where it stopped; "canceled" by default.
  • checkpoint (str or None, optional): The directory holding the stopped run's saved state: the same call with this checkpoint resumes. None when the run had no checkpoint.

Control

class Control()
Defined in src/tomojax/progress.py:286

Coordinate pause, resume and cancellation between an owner and a controller.

Control.pause

pause() -> None

Request a pause at the next work boundary.

Control.resume

resume() -> None

Wake the paused operation or withdraw a pending pause.

Control.cancel

cancel() -> None

Request cancellation and wake a paused operation.

Inside a checkpointed loop, the loop saves at its next work boundary before raising Canceled.

Control.state

@property
state: _State

Return the cooperative state of the active operation.

Returns

  • str: Running, pause-requested or paused.

Control.canceled

@property
canceled: bool

Whether cancellation has been requested.

Returns

  • bool: True once cancellation has been requested.

Control.deferring

deferring() -> Iterator[None]

Within, a cancel waits for the code that saves state at its own boundary.

A checkpointed loop enters this block: on cancel it saves at its next boundary and raises Canceled itself, so the work boundaries inside it let the cancel pass. Outside the block a cancel stops the work at the next boundary.

Yields

  • None: The extent of the deferral.

Control.boundary

boundary() -> None

Mark a work boundary: block while paused, or raise when canceled.

Raises

  • Canceled: If the operation was canceled, unless a checkpointed loop defers it.

Event

Defined in src/tomojax/progress.py:282

Finished

class Finished(task: int, status: _Status, time: float)
Defined in src/tomojax/progress.py:141

The outcome of an operation.

Parameters

  • task (int): Task identifier.
  • status (str): One of done, failed or canceled.
  • time (float): Monotonic seconds since the watch began.

Note

class Note(task: int | None, level: NoteLevel, message: str, time: float)
Defined in src/tomojax/progress.py:211

A message from the watched code.

Parameters

  • task (int or None): Innermost task ID or None between operations.
  • level (str): Severity of the message.
  • message (str): Formatted log or warning text.
  • time (float): Monotonic seconds since the watch began.

Paused

class Paused(task: int, time: float)
Defined in src/tomojax/progress.py:179

A task reached a work boundary while paused.

Parameters

  • task (int): Innermost active task.
  • time (float): Monotonic seconds since the watch began.

Placed

class Placed(task: int, devices: tuple[str, ...], time: float)
Defined in src/tomojax/progress.py:160

The coordinator resolved the devices participating in a task.

Parameters

  • task (int): Active task identifier.
  • devices (tuple of str): Participating device IDs in coordinator order.
  • time (float): Monotonic seconds since the watch began.

Preview

class Preview(task: int, arrays: Mapping[str, Sample], time: float)
Defined in src/tomojax/progress.py:263

Coherent small arrays copied at one completed work boundary.

Parameters

  • task (int): Owning task identifier.
  • arrays (mapping): Named host images with axes, fixed coordinates and value units.
  • time (float): Monotonic seconds since the watch began.

Resumed

class Resumed(task: int, time: float)
Defined in src/tomojax/progress.py:195

A paused task resumed computation.

Parameters

  • task (int): Innermost active task.
  • time (float): Monotonic seconds since the watch began.

Started

class Started(
    task: int,
    parent: int | None,
    name: _Name,
    label: str,
    total: int | None,
    unit: str,
    time: float,
)
Defined in src/tomojax/progress.py:79

An operation entered by its calling thread.

Parameters

  • task (int): Identifier unique to this watch.
  • parent (int or None): Enclosing task, if any.
  • name (str): The operation or numerical stage identifier.
  • label (str): Display text for the task, preserving file names.
  • total (int or None): Expected number of units, if known.
  • unit (str): Unit of completed work.
  • time (float): Monotonic seconds since the watch began.

to_json

to_json(event: Event, *, directory: str | Path | None = None) -> dict[str, object]
Defined in src/tomojax/progress.py:393

Return a versioned JSON-compatible record for an event.

Parameters

  • event (Event): Progress event to encode.
  • directory (str or pathlib.Path or None, optional): Consumer-owned directory for the NumPy arrays in a preview.

Returns

  • dict: Versioned record suitable for strict JSON encoding.

watch

watch(
    handler: Callable[[Event], None],
    *,
    control: Control | None = None,
    previews: bool = False,
) -> Iterator[None]
Defined in src/tomojax/progress.py:747

Deliver events synchronously to a fast handler in the calling context.

Parameters

  • handler (callable): Receives each event synchronously and must return quickly. An exception stops delivery and propagates to the caller.
  • control (Control or None, optional): Token which another thread or the handler may set to stop the operation.
  • previews (bool, optional): Deliver registered preview arrays from completed numerical work boundaries.

Yields

  • None: The dynamic extent of this watch in the current context.

On this page

TomoJAX