Giter Club home page Giter Club logo

Comments (7)

odelalleau avatar odelalleau commented on June 2, 2024 1

Thanks for the explanation. I just thought that the behavior should be the same, regardless if the value of the flag gets set to True or False.

It should indeed be the same.

Because I just need a "reset" of the flag for the whole config and some child nodes can be readonly, I just used oc.create(oc.to_container(config)) and create a fresh config without any flags.

I agree it'd be good to also have a way to clear flags recursively.

from omegaconf.

MatteoVoges avatar MatteoVoges commented on June 2, 2024 1

It should indeed be the same.

Ahh you're right. I forgot for a moment, that directly set flags have higher priority than the parent flags 🤦‍♂️ .

from omegaconf.

odelalleau avatar odelalleau commented on June 2, 2024

Although I agree this can be confusing, I'm not sure this is actually a bug.

The way flags work in OmegaConf is that a node inherits its parent's flags except for those that are explicitly set for this node. See code at:

def _get_flag_no_cache(self, flag: str) -> Optional[bool]:

The order in which flags are set doesn't matter. Whether you do

OmegaConf.set_readonly(config, False)
OmegaConf.set_readonly(config.a, True)

or

OmegaConf.set_readonly(config.a, True)
OmegaConf.set_readonly(config, False)

you will always have is_readonly(config.a) because the flag is explicitly set for the subconfig node.

I think it'd make sense to add an option to override the child nodes' flags, but in the meantime, my suggestion would be that you write your own function that iterates over children to achieve this.

from omegaconf.

MatteoVoges avatar MatteoVoges commented on June 2, 2024

Thanks for the explanation. I just thought that the behavior should be the same, regardless if the value of the flag gets set to True or False.
Because I just need a "reset" of the flag for the whole config and some child nodes can be readonly, I just used oc.create(oc.to_container(config)) and create a fresh config without any flags.

from omegaconf.

omry avatar omry commented on June 2, 2024

Because I just need a "reset" of the flag for the whole config and some child nodes can be readonly, I just used oc.create(oc.to_container(config)) and create a fresh config without any flags.

IIRC You can reset the value of a node by setting the flag value on that node to None.
If you want to do it recursively, maybe it's better to introduce a new reset_flag function instead of overloading set_flag.

from omegaconf.

MatteoVoges avatar MatteoVoges commented on June 2, 2024

I would be happy with both options. I just need a config with no flags, therefor its not important, if the value is None or False. A reset_flag function would be cool, too, but would do the same job as set_flag("reaonly", None).

from omegaconf.

odelalleau avatar odelalleau commented on June 2, 2024

Yeah I think a recursive set_flag() is more generic and powerful than a recursive reset_flag().

from omegaconf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.