-
-
Notifications
You must be signed in to change notification settings - Fork 663
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
[Bug] Parsing list of configurations with a structured config #1389
Comments
This is not how it works. List composition is not supported. You can create a dict with both DBConfigs in 1.1 per the link you received your stack overflow question. |
Do you think list composition could be supported for Hydra 1.1., or in the future? I ask because some models accept list of objects as attributes. This feature would allow automatic list creation (instead of a dictionary), and recursive instantiation of the model + lists, so it may be a common use case. I was thinking of parsing the list even as a dictionary, and indexing the first element as |
One thing that you can do now is to use interpolation to simulate it: dict:
item1:
a: 10
item2:
b: 20
as_list:
- ${dict.item1}
- ${dict.item2} OmegaConf 2.1 will support more powerful custom resolvers. It's possible that they will enable generating as_list automatically from dict. (cc @odelalleau).
I don't understand what your question. |
Ok, thanks for your suggestions.
It was not a clear question, maybe I framed in between suggestion/question. Somewhere in an issue I read that to override a default value in a list, you could access as To conclude, an example of a similar use case I have, is the hydra-optuna-sweeper. The Thanks for your support. I will close the issue now. |
Not in my current implementation because resolvers systematically wrap their output in a Edit: read my other comment below though |
I see what you mean. 1:
a: 10 2:
a: 20 3:
a: 30 Depending on which one you chose, you may end up with a hole in your list. |
I think this should be possible now, with |
@odelalleau thanks! Actually, @omry found quite elegant solution for me yesterday on zulipchat: https://hydra-framework.zulipchat.com/#narrow/stream/213879-Hydra/topic/.E2.9C.94.20Typechecking.20.26.20Structured.20Configs |
Could someone explain why the code from @jzazo doesn't or even shouldn't work? Isn't it essentially the same than what is documented in the multiple-config-groups example from the docs, with StructuredConfigs instead of config files? Actually, I have tried to re-implement the multiple-config-groups example from the docs with structured configs (see below), and I get the same error than @jzazo. But why? And is there a way to specify multiple (i.e., a list of) configs with Structured Configs? from dataclasses import dataclass, field
from typing import Any, Dict, List
import hydra
from hydra.core.config_store import ConfigStore
from omegaconf import OmegaConf
@dataclass
class ApacheConfig:
site: List[Any] = field(default_factory=list)
host: str = "localhost"
port: int = 443
@dataclass
class FbConfig:
fb: Dict[str, str] = field(default_factory=lambda: {"domain": "fb.com"})
@dataclass
class GoogleConfig:
google: Dict[str, str] = field(default_factory=lambda: {"domain": "google.com"})
cs = ConfigStore.instance()
cs.store(name="apache", group="server", node=ApacheConfig)
cs.store(name="fb", group="server/site", node=FbConfig)
cs.store(name="google", group="server/site", node=GoogleConfig)
@hydra.main(version_base=None, config_path="conf", config_name="config")
def my_app(cfg):
print(OmegaConf.to_yaml(cfg))
if __name__ == "__main__":
my_app() with the following config.yaml file: defaults:
- server: apache
- server/site:
- fb
- google |
I don't know why it does not work, but the feature request is being tracked, and hopefully it will be released in Hydra 1.3.0. |
Yes, the syntax is the same as in multiple-config-groups example.
See here and here for my recommended workaround based on Omry's comments above. You can use a
Yes, this is certainly on our radar. Most likely we will not get to this for Hydra 1.3, however. |
🐛 Bug
Description
I cannot parse a list of configs as attribute in a schema that requires a list type. Using latest dev version of Hydra 1.1. I think this feature is supported, although I have not found examples in the documentation.
Checklist
To reproduce
** Minimal Code/Config snippet to reproduce **
This snipped is almost exactly as the documented example. Changes are in line 36 of
my_app.py
where I specify a List type, andconfig.yaml
, where I input a list instead of an entry:and
config.yaml
specifies a list input, instead of a single entry:** Stack trace/error message **
Expected Behavior
I expected that
db
group would be aListConfig
of twoDBConfig
elements and the whole schema would work, but it fails.System information
Additional context
I first asked this question in stackoverflow.
The text was updated successfully, but these errors were encountered: