|
18 | 18 | import logging |
19 | 19 | from abc import ABC, abstractmethod |
20 | 20 | from pathlib import Path |
21 | | -from typing import TYPE_CHECKING, Any, Dict, Optional |
| 21 | +from typing import TYPE_CHECKING, Any |
| 22 | + |
| 23 | +from pydantic import BaseModel, ConfigDict, Field |
22 | 24 |
|
23 | 25 | from .installables import Installable |
24 | 26 |
|
25 | 27 | if TYPE_CHECKING: |
26 | 28 | from .base_job import BaseJob |
27 | 29 |
|
28 | 30 |
|
29 | | -class System(ABC): |
30 | | - """ |
31 | | - Base class representing a generic system. |
32 | | -
|
33 | | - Attributes |
34 | | - name (str): Unique name of the system. |
35 | | - scheduler (str): Type of scheduler used by the system, determining the specific subclass of System to be used. |
36 | | - install_path (Path): Installation path of CloudAI software. |
37 | | - output_path (Path): Path to the output directory. |
38 | | - global_env_vars (Optional[Dict[str, Any]]): Dictionary containing additional configuration settings for the |
39 | | - system. |
40 | | - monitor_interval (int): Interval in seconds for monitoring jobs. |
41 | | - """ |
42 | | - |
43 | | - def __init__( |
44 | | - self, |
45 | | - name: str, |
46 | | - scheduler: str, |
47 | | - install_path: Path, |
48 | | - output_path: Path, |
49 | | - global_env_vars: Optional[Dict[str, Any]] = None, |
50 | | - monitor_interval: int = 1, |
51 | | - ) -> None: |
52 | | - """ |
53 | | - Initialize a System instance. |
| 31 | +class System(ABC, BaseModel): |
| 32 | + """Base class representing a generic system.""" |
54 | 33 |
|
55 | | - Args: |
56 | | - name (str): Name of the system. |
57 | | - scheduler (str): Type of scheduler used by the system. |
58 | | - install_path (Path): The installation path of CloudAI. |
59 | | - output_path (Path): Path to the output directory. |
60 | | - global_env_vars (Optional[Dict[str, Any]]): Dictionary containing additional configuration settings for |
61 | | - the system. |
62 | | - monitor_interval (int): Interval in seconds for monitoring jobs. |
63 | | - """ |
64 | | - self.name = name |
65 | | - self.scheduler = scheduler |
66 | | - self.install_path = install_path |
67 | | - self.output_path = output_path |
68 | | - self.global_env_vars = global_env_vars if global_env_vars is not None else {} |
69 | | - self.monitor_interval = monitor_interval |
70 | | - |
71 | | - def __repr__(self) -> str: |
72 | | - """ |
73 | | - Provide a detailed string representation of the System instance, including all its attributes. |
| 34 | + model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True) |
74 | 35 |
|
75 | | - Returns |
76 | | - str: String representation of the system including name, scheduler, output_path, and monitor_interval. |
77 | | - """ |
78 | | - return ( |
79 | | - f"System(name='{self.name}', scheduler='{self.scheduler}', output_path='{self.output_path}', " |
80 | | - f"monitor_interval={self.monitor_interval})" |
81 | | - ) |
| 36 | + name: str |
| 37 | + scheduler: str |
| 38 | + install_path: Path |
| 39 | + output_path: Path |
| 40 | + global_env_vars: dict[str, Any] = Field(default_factory=dict) |
| 41 | + monitor_interval: int = 1 |
82 | 42 |
|
83 | 43 | @abstractmethod |
84 | 44 | def update(self) -> None: |
|
0 commit comments