Source code for gyoza.models.op_attempt

"""OpAttempt entity — a single execution attempt within an OpRun."""

from __future__ import annotations

from dataclasses import dataclass, field
from datetime import datetime
from typing import Any

from gyoza.models.resources import Constraints, EventEntry, ExecutionSummary, OpRunState


[docs] @dataclass class OpAttempt: """A single execution attempt belonging to an OpRun. OpRuns can have multiple attempts when retries are configured. Each attempt has its own event timeline, outputs, and execution summary. Parameters ---------- id : str Unique identifier for the attempt (``<run_id>_att_<n>``). op_run_id : str Parent OpRun identifier. attempt : int Attempt number (1-indexed). state : OpRunState Current state of this attempt. progress : int Completion percentage (0–100). events : list[EventEntry] Timeline of events during this attempt. inputs : dict[str, Any] Snapshot of inputs at execution time. outputs : dict[str, Any] Outputs produced by this attempt. execution_summary : ExecutionSummary Execution metadata (worker, duration, GPU, error). constraints : Constraints Hardware constraints snapshot for this attempt. started_at : datetime | None When the container started. finished_at : datetime | None When the container exited. """ id: str op_run_id: str attempt: int state: OpRunState progress: int = 0 events: list[EventEntry] = field(default_factory=list) inputs: dict[str, Any] = field(default_factory=dict) outputs: dict[str, Any] = field(default_factory=dict) execution_summary: ExecutionSummary = field(default_factory=ExecutionSummary) constraints: Constraints = field(default_factory=Constraints) started_at: datetime | None = None finished_at: datetime | None = None
[docs] def to_dict(self) -> dict[str, Any]: """Serialise to a JSON-compatible dictionary. Returns ------- dict[str, Any] Dictionary with all attempt data. """ return { "id": self.id, "op_run_id": self.op_run_id, "attempt": self.attempt, "state": self.state.value, "progress": self.progress, "events": [e.to_dict() for e in self.events], "inputs": self.inputs, "outputs": self.outputs, "execution_summary": self.execution_summary.to_dict(), "constraints": self.constraints.to_dict(), "started_at": self.started_at.isoformat() if self.started_at else None, "finished_at": self.finished_at.isoformat() if self.finished_at else None, }