-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for omegaconf interpolations in configs #577
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
base: main
Are you sure you want to change the base?
Conversation
|
Peut-être que ceci mérite une discussion plus large, mais je voterais pour une réécriture complète de |
Ok, oui il y a beaucoup de redondances en effet. Si on est à l'aise d'assumer cet dépendance, pourquoi pas |
Un autre moyen de s'en sortir serait d'utiliser les variables d'env ou une CLI pour lire les quelques variables "privées" qui restent ? Ça éliminerait le besoin d'un fichier |
Je n'ai pas d'opinion forte, je vous fait confiance là-dessus. |
|
Si on veut aller all-in, hydra permet des choses comme: # main.py
@hydra.main(config_path="../configs/", config_name="config", version_base=None)
def train(cfg):
# blablapython main.py +paths.indicators=/path/to/your/indicators.yaml# config.yaml, updatée avec l'appel python main.py
## ceci est ajouté avec l'appel de main.py
paths:
indicators: path/to/your/indicators.yaml
## ceci est déja codé
indicator:
load_xclim_module:
filename: ${paths.indicators}Mais c'est pas mieux vraiment. config.yaml serait quand même écrit avec des références inexistentes. Je préfère l'approche d'avoir un paths.yaml |
|
hydra permet aussi des instantiations. Tu dis quelles fonction ou classe vont avec tes arguments. biasadjust:
variables:
snw:
training:
_target_: xscen.train
var: snw
period: *ref_period
method: EmpiricalQuantileMapping
jitter_under:
thresh: 1e-8 kg m-2
...et tu instanties ça dans le script from hydra.utils import instantiate
import xscen
task = "biasadjust"
for var in CONFIG[task]["variables"]:
# instantiate(CONFIGtask]["variables"]["train"]) te retourne un callable qui manque dref & dhist
ds_tr = instantiate(CONFIG[task]["variables"][var]["training"])(dref = dsref, dhist = ds)mais c'est peut-être pas super utile comme abstraction C'est pas tant différent de caller xs.train avec les arguments d'intérêt appelés avec le dict. Mais pour la config de pins qui avait des quantiles un peu funky, c'est quand même nice, l'information peut facilement être mise dans ma config aussi. nquantiles:
_target_: numpy.arange
start: 0.05
stop: 1
step: 0.02Je vous laisse juger si c'est épatant ou dégoûtant héhé |
|
Je commence à changer mon fusil d'épaule sur la malpropreté de mon approche actuelle, du moins relative. Je maintiens que le plus clean serait d'avoir un defaults qui fait référence à paths.yaml. Mais c'est pas vraiment pire que ce qu'on a en ce moment? Présentement, on définit |
Pull Request Checklist:
number) and pull request (:pull:number) has been added.What kind of change does this PR introduce?
Does this PR introduce a breaking change?
This is optional, but I changed the templates by assuming
omegaconfwould be instaledOther information:
This doesn't replace all the functions in
xscen.config. Rather, it's a small add-on that lets me use the interpolations of OmegaConf.Currently, this is a bit dirty, because in config.yaml I make reference to keys from paths.yaml which is not explicitly referenced. Implicitly, we know we will merge config.yaml and paths.yaml, so it's fine. A proper way to do this would be to add it as a dependence: