IDSIA / sacred

Sacred is a tool to help you configure, organize, log and reproduce experiments developed at IDSIA.
MIT License
4.23k stars 381 forks source link

Dot Notation for config access #312

Open Robin-des-Bois opened 6 years ago

Robin-des-Bois commented 6 years ago

Great project!

Since dictionaries get passed around everywhere: Have you ever considered integrating something like DotMap?

All those dictionary accesses and string literals create (uncessary?) visual noise and also make the code analysis of the IDE less useful

Are there obvious reasons why this would be a bad idea? and if not how could this be implemented such that every user can enable/disable this feature easily?

Qwlouse commented 6 years ago

Thanks! :-) I have thought about using something with dotted access for the configuration, too. Turning just the final config into a DotMap (or similar) should be pretty easy to do. But to enable IDE analysis for experiments, more work would be necessary, since the way configurations are currently created cannot be understood by an IDE. But at least accessing nested config-entries would be much nicer in many cases. I am not sure how easy it would be to make it an optional feature, but I think it might be okay to make it a mandatory feature. I'd be open to adding it to the next major release.

There are a ton of packages that do this and I had started to collect them to see if they suit my needs. I've put my list so far below (and added DotMap).

attrdict

easydict

treedict

bunch

Abandoned. See munch

munch

addict

benedict

edict

prodict

DotMap

black-puppydog commented 6 years ago

Which functionality specifically are you missing from addict?

I reallyreally like the idea of not using config['stuff'] all over the place, especially since config keys already have to be python names. One problem I can think of is with this kind of config though:

@ex.config
def conf():
    a = {1: 'one', 2: 'two'}
kklemon commented 5 years ago

Any news regarding this feature?

I tried to use EasyDict in a config but it seems like that all config objects inheriting from dict are casted to actual dicts when calling automain. As there any easy way to change this behavior?