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

[Feature Request] Array Element Overrides from dotlist via getitem syntax #179

Closed
apsdehal opened this issue Mar 25, 2020 · 7 comments · Fixed by #647
Closed

[Feature Request] Array Element Overrides from dotlist via getitem syntax #179

apsdehal opened this issue Mar 25, 2020 · 7 comments · Fixed by #647
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@apsdehal
Copy link

Currently, OmegaConf supports overriding as training_parameters.lr_steps.1=500 for overriding a specific element of an array. This is not intuitive and we should support proper getitem syntax for array element overrides.

training_parameters.lr_steps[1]=500 should be supported.

@omry omry added the enhancement New feature or request label Mar 25, 2020
@omry omry added this to the OmegaConf 2.1 milestone Mar 25, 2020
@omry
Copy link
Owner

omry commented Feb 3, 2021

Blocked on #445

@Jasha10
Copy link
Collaborator

Jasha10 commented Feb 22, 2021

If I am not mistaken, this issue is resolved:

>>> training_parameters = OmegaConf.create({"lr_steps": [1000,800,100,75]})
>>> training_parameters
{'lr_steps': [1000, 800, 100, 75]}
>>> training_parameters.lr_steps[1]
800
>>> training_parameters.lr_steps[1] = 500
>>> training_parameters
{'lr_steps': [1000, 500, 100, 75]}

@odelalleau
Copy link
Collaborator

If I am not mistaken, this issue is resolved:

No, that's because the way it's phrased can be misleading. training_parameters.lr_steps[1]=500 is not meant to be read as a Python statement, but as a command line override as would be used in Hydra for instance. In OmegaConf, it's actually more about the select / update functions that assume the key is dot-separated (search for split(".") in the code)

@omry
Copy link
Owner

omry commented Feb 22, 2021

In [3]: cfg = OmegaConf.create({"a" : {"b": [1,2,3]}})

In [4]: cfg
Out[4]: {'a': {'b': [1, 2, 3]}}

In [5]: OmegaConf.select(cfg, "")
Out[5]: {'a': {'b': [1, 2, 3]}}

In [6]: OmegaConf.select(cfg, "a")
Out[6]: {'b': [1, 2, 3]}

In [7]: OmegaConf.select(cfg, "a.b")
Out[7]: [1, 2, 3]

In [8]: OmegaConf.select(cfg, "a.b.0")
Out[8]: 1

What would be good is to support:

OmegaConf.select(cfg, "a.b[0]")

In fact, we can support it for regular dict access as well:

OmegaConf.select(cfg, "[a][b][0]")

@omry
Copy link
Owner

omry commented Mar 18, 2021

This should probably cover the interpolation syntax as well, so it can be too much for 2.1:

list:
 - a
 - b 
item0: ${list.0}  # a, current syntax
item1: ${list[1]} # b, new syntax

@dasturge
Copy link

dasturge commented Nov 8, 2022

Hi, I found this issue when trying to figure out how to do just that. Can you point me to documentation I missed or, can I request documentation of this feature?

@Jasha10
Copy link
Collaborator

Jasha10 commented Nov 8, 2022

Hi @dasturge,

Take a look at the docs on Config node interpolation.

Also, there are usage examples in the OmegaConf.select docs and the OmegaConf.update docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
5 participants