Coverage for src/mlopus/mlflow/api/common/schema.py: 100%
35 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-07-13 14:49 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-07-13 14:49 +0000
1from datetime import datetime
2from enum import Enum
3from typing import Dict, Any
5from mlopus.utils import pydantic, urls
6from . import patterns
9class RunStatus(Enum):
10 """Run status values."""
12 FAILED = "FAILED"
13 RUNNING = "RUNNING"
14 FINISHED = "FINISHED"
15 SCHEDULED = "SCHEDULED"
18class BaseEntity(pydantic.BaseModel, pydantic.MappingMixin):
19 """Base class for entity schemas."""
21 tags: Dict[str, Any] = pydantic.Field(
22 repr=False,
23 description=(
24 "Nested tags dict with JSON-serializable leaf-values and keys "
25 f"in the pattern: `{patterns.TAG_PARAM_OR_METRIC_KEY.pattern}`"
26 ),
27 )
30class Experiment(BaseEntity):
31 """Type of Experiment used by MLOpus in generic MLflow-compliant APIs."""
33 id: str = pydantic.Field(description=f"Experiment ID in the pattern `{patterns.EXP_ID.pattern}`")
34 name: str = pydantic.Field(description="Experiment Name.")
37class Run(BaseEntity):
38 """Type of Run used by MLOpus in generic MLflow-compliant APIs."""
40 id: str = pydantic.Field(description=f"Run ID in the pattern `{patterns.RUN_ID.pattern}`")
41 name: str = pydantic.Field(description="Run name.")
42 exp: Experiment = pydantic.Field(repr=False, description="Parent experiment.")
43 repo: str = pydantic.Field(repr=False, description="Artifacts repo URL.")
44 params: Dict[str, Any] = pydantic.Field(
45 repr=False,
46 description="Nested params dict with JSON-serializable leaf-values.",
47 )
48 metrics: Dict[str, Any] = pydantic.Field(
49 repr=False,
50 description="Nested metrics dict with float leaf-values.",
51 )
52 status: RunStatus | None = pydantic.Field(repr=False, description="Run status.")
53 end_time: datetime | None = pydantic.Field(
54 repr=False,
55 description="Start time in local timezone.",
56 )
57 start_time: datetime | None = pydantic.Field(
58 repr=False,
59 description="End time in local timezone.",
60 )
62 @property
63 def repo_url(self) -> urls.Url:
64 """Artifacts repo URL."""
65 return urls.parse_url(self.repo)
68class Model(BaseEntity):
69 """Type of registered Model used by MLOpus in generic MLflow-compliant APIs."""
71 name: str = pydantic.Field(description=f"Model vame in the pattern `{patterns.MODEL_NAME.pattern}`")
74class ModelVersion(BaseEntity):
75 """Type of ModelVersion used by MLOpus in generic MLflow-compliant APIs."""
77 version: str = pydantic.Field(description=f"Model version in the pattern `{patterns.MODEL_VERSION.pattern}`")
78 model: Model = pydantic.Field(description="Parent model.")
79 run: Run = pydantic.Field(repr=False, description="Parent run.")
80 path_in_run: str = pydantic.Field(repr=False, description="Path inside run artifacts.")