Hydra: [Bug] trying to use the mandatory attribute according to tutorial

Created on 20 Aug 2020  路  4Comments  路  Source: facebookresearch/hydra

馃悰 Bug

Hi, thanks for Hydra, seem like a perfect solution for me from reading the docs. especially the instance features

I'm trying to run some basic stuff to get familiar with Hydra, and when I'm trying to use the MISSING required attribute it crashes.

Checklist

  • [x] I checked on the latest version of Hydra (the recommended one from the README)

  • [x] I created a minimal repro

It is demonstrated in the following notebook:

https://colab.research.google.com/drive/1fsWCyEiZCntZarBjcc8VUgYG14C6K0DT?usp=sharing

* Stack trace/error message *

RecursionError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/omegaconf/dictconfig.py in __getattr__(self, key)
    294 
--> 295             return self._get_impl(key=key, default_value=DEFAULT_VALUE_MARKER)
    296         except Exception as e:

1438 frames
RecursionError: maximum recursion depth exceeded

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
KeyError: '_content'

Expected Behavior

creating an instance

System information

  • Hydra Version : 1.0
  • Python version : COLAB
  • Virtual environment type and version : COLAB
  • Operating system : COLAB
bug

All 4 comments

Please open your collab privacy.

  1. You should be using Use OmegaConf.MISSING, not dataclass.MISSING.
  2. With Hydra you don't normally instantiate the config objects, Hydra is doing it for you.
  3. You create an OmegaConf config object with OmegaConf.create() and OmegaConf.structured(ClassOrObject) for Structured Configs (dataclasses).
  4. DictConfig is not designed to be extended by users.

thanks!

  1. my bad.. I think it would be helpful if imports are added as a context for the docs
  2. in my use case I will be mainly instantiating them myself.. is there a fundamental reason it would be wrong? or just less optimized by design for this use case
  3. I am not sure with respect to what you mentioned this
  4. isn't it used in the docs examples?

thanks again!

thanks!

1. my bad.. I think it would be helpful if imports are added as a context for the docs

Yes. Mind sending a quick PR to fix the tutorial?

2. in my use case I will be mainly instantiating them myself.. is there a fundamental reason it would be wrong? or just less optimized by design for this use case

What are you getting out of Hydra?
Did you go over the basic tutorial and do you understand config composition?

If you want to benefit from the features of Hydra you have to do things the right way.
I also have the feeling that you are misunderstanding OmegaConf. Please go over the slides of it linked from the project readme.
With both Hydra and OmegaConf, you don't use the actual dataclass instances at runtime. You use OmegaConf instances (DictConfig and ListConfig), and embrace ducktyping for static type safety.

3. I am not sure with respect to what you mentioned this

If you instantiate your data class directly, OmegaConf.MISSING means absolutely nothing.
It's the string "???".
You need to instantiate an OmegaConf object from your dataclass.
you do it with:

cfg = OmegaConf.structured(YourClass)

Read the OmegaConf docs or go over the slides.

4. isn't it used in the docs examples?

It was for the wrong reasons (to allow type safe access to the real object). This should be removed now. Do you see see those?
Note that you did not see any examples of instantiating the dataclass in the tutorial (or in the OmegaConf docs).

Was this page helpful?
0 / 5 - 0 ratings