modrec-workflow/helpers/app_settings.py
Michael Luciuk 9979d84e29 Documentation and formatting updates (#1)
Documentation and formatting updates:
- Updates to project README.
- Adding project health files (`LICENSE` and `SECURITY.md`)
- A few minor formatting changes throughout
- A few typo fixes, removal of unused code, cleanup of shadowed variables, and fixed import ordering with isort.

**Note:** These changes have not been tested.

Co-authored-by: Michael Luciuk <michael.luciuk@gmail.com>
Co-authored-by: Liyu Xiao <liyu@qoherent.ai>
Reviewed-on: https://git.riahub.ai/qoherent/modrec-workflow/pulls/1
Reviewed-by: Liyux <liyux@noreply.localhost>
Co-authored-by: Michael Luciuk <michael@qoherent.ai>
Co-committed-by: Michael Luciuk <michael@qoherent.ai>
2025-07-08 10:50:41 -04:00

67 lines
1.5 KiB
Python

import os
from dataclasses import dataclass
from functools import lru_cache
from typing import Dict
import yaml
@dataclass
class DataSetConfig:
num_slices: int
train_split: float
seed: int
modulation_types: list
val_split: float
beta: float
sps: int
snr_start: int
snr_stop: int
snr_step: int
num_iterations: int
recording_length: int
modulation_settings: Dict[str, Dict[str, str]]
@dataclass
class TrainingConfig:
batch_size: int
epochs: int
learning_rate: float
use_gpu: bool
drop_rate: float
drop_path_rate: float
wd: int
@dataclass
class AppConfig:
optimization_style: str
target_platform: str
class AppSettings:
"""Application settings, to be initialized from app.yaml configuration file."""
def __init__(self, config_file: str):
# Load the YAML configuration file
with open(config_file, "r") as f:
config_data = yaml.safe_load(f)
# Parse the loaded YAML into dataclass objects
self.dataset = DataSetConfig(**config_data["dataset"])
self.training = TrainingConfig(**config_data["training"])
self.app = AppConfig(**config_data["app"])
@lru_cache
def get_app_settings() -> AppSettings:
"""Return application configuration settings."""
module_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
config_file = os.path.join(module_path, "conf", "app.yaml")
return AppSettings(config_file=config_file)
if __name__ == "__main__":
s = get_app_settings()