-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -76,5 +76,8 @@ INTER_CLOSE: '}' -> popMode; | |||
|
||||
DOT: '.'; | ||||
INTER_ID: ID -> type(ID); | ||||
// A special type of `ID` that contains the "@" character. It has to be a different | ||||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Author
Collaborator
|
supported_chars = "%_-abc123." |
ID
type as keys).
So which characters exactly do we want to support in key names? All those from that regex, or a subset of them?
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 8, 2020
Owner
This seems almost equivalent to what I have right now, except that:
- Names are different
I prefer to call it by what it is, not what it look like.
- You are not allowing @ as the first character
accidental omission.
The second point is easy to change. Regarding the names, remember that we also have an ID lexer token in VALUE_MODE, which is used to parse dictionary keys. And we can't re-use the same name (even if it's in a different mode), so we have to make a choice regarding which one gets to be named ID (the one with @ or the one without).
Yes, that's true.
There is a limitation in OmegaConf right now where dict keys can't be numbers, but the grammar can probably support more flexible keys (and allow the DictConfig to potentially fail there):
Will this work? playing with it for a moment now it seems to be working.
dictKeyValuePair: primitive COLON element;
I got the grammar to recognize:
a={
[email protected]: string
10.0: float
1: int
}
We can change Hydra to line up with this it works.
Back to the topic if interpolation keys:
Basically, they should allow us to refer to specific nodes (foo.bar).
There is a special case in Hydra default list interpolation which requires nodes to have the keys like db/engine@backup
.
At minimum, we should allow for those two characters, but I wonder if we should relax it to support anything except special tokens (like .
, :
, {
, }
, [
, ]
etc)
To clarify, there is no requirement to change which names are legal for custom resolvers. I think the current ID definition makes sense there.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 8, 2020
•
edited
Loading
Author
Collaborator
edited
I prefer to call it by what it is, not what it look like.
Ok, so what do you think about my other proposition? (DICTKEY / RESOLVER_OR_NODE / NODE, which tried to do that exactly = give a name that says what it is). Otherwise what names do you want? (right now, based on your previous message, it would be ??? / INTER_ID / ID)
Edit: actually I don't like DICTKEY
since this token in VALUE_MODE
is also used in unquoted strings. So I'd rather stick with ID
in VALUE_MODE
.
There is a limitation in OmegaConf right now where dict keys can't be numbers, but the grammar can probably support more flexible keys (and allow the DictConfig to potentially fail there):
Will this work? playing with it for a moment now it seems to be working.dictKeyValuePair: primitive COLON element;
Yes it can work, actually initially I had dictionary keys that could be anything but you preferred to stick to basic strings only. This has little to do with DictConfig though, since these dictionaries are arguments to resolvers (maybe they can end up being converted to DictConfig if a resolver returns them, but I've never tried that).
The main downside is that to get this to work I would need to bring back this weird code I wrote to be able to sort dictionary keys (required to make sure that the resolver cache works properly with dictionaries). For instance if you try to call sorted(a)
on the example dictionary you wrote, you'd get a TypeError: '<' not supported between instances of 'float' and 'str'
. It's doable though, just giving you a heads up that there's this extra added complexity. Also if we do it, any reason not to allow interpolations too as dictionary keys? (edit: scratch that, actually primitive
contains interpolations)
At minimum, we should allow for those two characters, but I wonder if we should relax it to support anything except special tokens (like
.
,:
,{
,}
,[
,]
etc)
Ok, I'll come up shortly with a proposition to be more flexible here.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 8, 2020
Author
Collaborator
Proposition in 200fef2 (it includes my current preference in terms of naming for lexer tokens). Some tests are failing / missing, once we agree on the grammar I'll replace this commit with another one with proper tests as well as code (like I said earlier, I need to put back some code to deal with different types as dictionary keys).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 8, 2020
Owner
Yes it can work, actually initially I had dictionary keys that could be anything but you preferred to stick to basic strings only. This has little to do with DictConfig though, since these dictionaries are arguments to resolvers (maybe they can end up being converted to DictConfig if a resolver returns them, but I've never tried that).
The first motivation to add dictionaries to the grammar came from the override grammar in Hydra (See doc about dicts)
"Dictionaries are merged, not assigned."
Looking at 200fef2 now.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 8, 2020
Author
Collaborator
The first motivation to add dictionaries to the grammar came from the override grammar in Hydra (See doc about dicts)
"Dictionaries are merged, not assigned."
Ok but that's one area where Hydra and OmegaConf differ: in OmegaConf dictionaries parsed through the grammar are those provided to resolvers as arguments (not that it's a big deal, just making sure I understand what you're saying)
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 8, 2020
Owner
You are correct, but it's certainly possible that OmegaConf will catch up on that functionality now that it has a way to parse complex strings in the command line :).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 9, 2020
Author
Collaborator
initially I had dictionary keys that could be anything
I looked back on it as I was curious to see how I avoided the problem mentioned in 200fef2#r44939891
It turns out my memory was wrong, in my earlier version dictionary keys could be ID
or interpolation
. Now that I see it, I remember that my motivation for allowing interpolations was that even if keys were expected to only be IDs, we may want these IDs to be computed by an interpolation. And, as a side effect, it allowed using keys of different types if we really wanted to (since interpolations can return anything).
I'm just mentioning this to correct my previous statement. It also means there might be other unforeseen issues with allowing any primitive
as key (since I didn't make it work before after all).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 10, 2020
Owner
There is an issue I just closed as a dup which wanted to add numbers as supported keys in DictConfig. this seems related to extending the dict in the grammar to support more types.
Let's try to make it work, if we hit a landmine we can limit the change to support the exact functionality needed by Hydra (@
, /
).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 10, 2020
Author
Collaborator
Let's try to make it work, if we hit a landmine we can limit the change to support the exact functionality needed by Hydra (
@
,/
).
Alright, just did a quick check and I think it will work by having two version of primitive
, one with COLON
and one without. It's a bit annoying because I have to copy/paste the definition: there is no equivalent of the lexer's fragments in the parser to avoid repetitions, and if I try something like primitive_with_colon: (primitive_without_colon | COLON)+
then I run again into "Attempting Full Context" warnings (which I'd rather avoid if possible).
Anyway, I'll put up a working version tomorrow so you can check it out and see whether or not you like it. A backup solution could be to only allow IDs and quoted strings (since anyway in DictConfig you probably want these keys to be strings, even if they are numbers).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 10, 2020
Owner
A backup solution could be to only allow IDs and quoted strings (since anyway in DictConfig you probably want these keys to be strings, even if they are numbers).
Actually not: once we have support for number keys I would like to be able to use numbers:
{1: one, 3.14: pi}
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 10, 2020
Author
Collaborator
Ok, done in 4bbc308
I actually found a way to make it work without copying the definition of primitive
, but in the end it made things more complex and less flexible. So although this is a bit verbose, at least it's easy to understand, and if we ever want to change what we allow in dictionary keys this should be easy as well.
A few notes:
- I wish I didn't need to make the changes I made in _utils.py but I couldn't find a better way. Let me know if you do.
- I renamed
listValue
anddictValue
tolistContainer
anddictContainer
in the grammar because I introduceddictKey
, and having bothdictKey
anddictValue
would have created wrong expectations. The other option would have been to find another name thandictKey
, but it sounded like the best name to me. Happy to change names though if you prefer otherwise.
Just tried it in Hydra, at least all existing tests pass so nothing should be badly broken. I'll put up a PR on Hydra once this change is approved.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 10, 2020
Owner
Oh, and to be more clear:
What I meant by "trying this in Hydra" was to enable dict keys that can be any primitive there as well and see that nothing blows up.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 10, 2020
•
edited
Loading
Author
Collaborator
edited
What I meant by "trying this in Hydra" was to enable dict keys that can be any primitive there as well and see that nothing blows up.
Yes that's exactly what I did (except that I didn't allow ":", applying to Hydra's override grammar the same kind of grammar changes that I implemented in 4bbc308 to make it work in OmegaConf)
All current tests passed in Hydra, but I still need to turn it into a proper PR with additional tests.
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
omry
Dec 13, 2020
Owner
Ok, sounds good.
Can you prioritize the Hydra diff?
It will be easier to see the changes to the grammar in that context (and will also allow me to play with it sooner).
This comment has been minimized.
This comment has been minimized.
Sorry, something went wrong.
odelalleau
Dec 14, 2020
Author
Collaborator
Can you prioritize the Hydra diff?
Ok, here it is: facebookresearch/hydra#1208
the comment seems in conflict with the test below, that uses @ in resolver name.
can this be simplified?
I don't think @ in keys should be different than other legal character in the interpolation key.