Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use dataclasses for configs #2

Open
elray1 opened this issue Oct 31, 2024 · 1 comment
Open

use dataclasses for configs #2

elray1 opened this issue Oct 31, 2024 · 1 comment

Comments

@elray1
Copy link

elray1 commented Oct 31, 2024

define base_config as a dataclass and then instantiate it with model_name, p, power_transform, etc. as needed

@elray1
Copy link
Author

elray1 commented Oct 31, 2024

One pattern is to replace your base config with a dataclass:
In [8]: @DataClass
...: class ModelConfig:
...: sources: list[str]
...: model_name: str = "sarix"
...: fit_locations_separately: bool = False
...: # model parameters
...: p: int = 1
...: P: 0 = 0
...: #etc
...: power_transform: str = None
And create a helper function that returns a ModelConfig instance based on passed parameters:
In [9]: def get_model_config(sources: list[str], fit_locations_separately: bool, p:int) -> ModelConf
...: ig:
...: model_config = ModelConfig(sources=sources, fit_locations_separately=fit_locations_separ
...: ately, p=p)
...: return model_config
And then in the code that parses args:
mc = get_model_config(["hhs"], fit_locations_separately=True, p=5)
The dataclass attributes work in the same tidy way as the SimpleNamespace
In [11]: mc
Out[11]: ModelConfig(sources=['hhs'], model_name='sarix', fit_locations_separately=True, p=5, P=0, power_transform=None)

In [12]: mc.model_name
Out[12]: 'sarix'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant