18 from typing
import Optional, List, Dict, Any
19 from typing_extensions
import Self
20 from pathlib
import Path
24 from ...entities
import BaseParameter, parameter_factory
25 from ...codable
import Codable, KeyDescriptor
28 TASK_CONFIG_PATH = Path(
".",
"task.yaml")
31 class ParamGroup(Codable):
34 params: Optional[List[BaseParameter]]
37 def _decodeValue(cls, key: str, value: Any) -> Any:
39 return [parameter_factory.create(obj)
for obj
in value]
41 return super()._decodeValue(key, value)
44 class TaskConfig(Codable):
46 paramGroups: Optional[List[ParamGroup]]
49 def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
50 descriptors = super()._keyDescriptors()
51 descriptors[
"paramGroups"] = KeyDescriptor(
"param_groups", ParamGroup, list)
56 def decode(cls, params: dict) -> Self:
57 if params.get(
"param_groups")
is None:
58 params[
"param_groups"] = []
60 return super().decode(params)
63 def readTaskConfig() -> List[BaseParameter]:
64 parameters: List[BaseParameter] = []
66 if not TASK_CONFIG_PATH.exists():
69 with TASK_CONFIG_PATH.open(
"r")
as configFile:
70 config = TaskConfig.decode(yaml.safe_load(configFile))
72 if config.paramGroups
is not None:
73 for group
in config.paramGroups:
74 if group.params
is not None:
75 parameters.extend(group.params)