-
Notifications
You must be signed in to change notification settings - Fork 910
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
Make registering custom resolvers easy #2407
Comments
Awesome, here is a really scrappy version of what I think import os
import polars as pl
CONFIG_LOADER_ARGS = {
"custom_resolvers" : {
"oc.env" : lambda x : os.environ[x],
"polars" : lambda x : getattr(pl, x)
}
}
load_args:
dtypes:
product_age: ${polars:Float64}
group_identifier: ${polars:Utf8} |
A few thoughts:
I totally agree with:
This API would obviously allow to register e.g. |
Agreed on both points
|
Could you elaborate on how you imagine this would work?
Do you mean like scoping by |
On the point of enabling When we conducted the config research in the summer (see #1847), the main use case for environment variables was credentials, and so we decided to enable it for just that to start with. An advanced user could overwrite this behaviour and just enable environment variables for everything, but I still believe it's a sensible choice not to enable it by default just to make sure users don't just abuse env vars because it's easy. |
I've meant what @merelcht is talking about above - right now, the
+1 to that! |
Why not enable the built-in resolvers for all configuration types? I mean, if a user wants to go ahead and use environment variables in their config, why not? I do see added value for e.g. configuring different paths in catalog entries based on the env (dev vs qa vs prod). |
In hydra they use a specific data_fab:
type: data_fab.extras.DataSet
save_args:
if_exists: append
dtype:
simulation_payload:
_target_: sqlalchemy.types.JSON
_partial_: False |
By the way, registering custom resolvers does not even need subclassing # settings.py
if not OmegaConf.has_resolver("dummy"):
OmegaConf.register_new_resolver("dummy", lambda x: x)
CONFIG_LOADER_CLASS = OmegaConfigLoader apparently |
(The |
I guess this is exactly what Kedro's environment doing already. |
I know, but if you can do it with an environment variable, you can simply add your catalog entry in |
I see your point, however, we don't want to encourage users to abuse environment variables for everything. It's still a bit unclear how we should enable this feature. I think for that purpose we should keep the discussion there. For this specific PR it's about how to enable registering custom resolver, and whether
|
Summary of tech design session on 24/05: Discussed two possible solutions -
|
Closing this issue in favour of the following tickets - |
Description
Omegaconf
provides functionality to register custom config resolvers: https://omegaconf.readthedocs.io/en/2.3_branch/usage.html#resolversAt the moment it's possible to do this by subclassing the
OmegaConfigLoader
. Ideally it should be possible to do this without having to make a custom class.Context
This feature would allows users to do more advanced variable interpolation in their config.
Possible Implementation
Allow users to provide custom resolvers through
settings.py
, adding a new constructor arg likecustom_resolvers : Optional[Dict[str, Callable]]
Possible Alternatives
Perhaps users can achieve this as well by using hooks.
The text was updated successfully, but these errors were encountered: