Move `OmegaConf.resolve(cfg)` after `pre_call`
petosa opened this issue · 6 comments
Hello,
I am using the @zen
decorator in my project, and using its pre_call
arg to modify my config. I am trying to modify the unresolved config, but pre_call
gets the config after OmegaConf.resolve(cfg)
has been run.
Can OmegaConf.resolve(cfg)
please be moved to be after self.pre_call(cfg)
to allow for more flexibility?
@petosa I'll think about it (and I'm sure @rsokl will have more insight) but I don't think this is possible in hydra-zen as the resolver is handled by Hydra. You might want to look into Hydra callbacks: https://hydra.cc/docs/experimental/callbacks/
Thanks for your reply. Couldn't the requested change be achieved by moving line 336 in the linked code to line 340?
Yeah, I can try and look at it. @rsokl might have a better understanding of the dynamics at play between hydra-zen and Hydra here though, but we may not want to mess with that behavior. It still might be better to use callbacks (which can be configured with hydra-zen). I'm not sure when the resolver is called for callbacks though. Do you have a simple example of what you are trying to do? Maybe there's another solution?
I like the idea of being able to use pre_call
to do stuff to the cfg before it gets resolved. Moving resolve
is no good because it could easily break people's existing code.
Off the top of my head, I think Zen
/zen
should have a resolve_cfg: bool = True
param. For your desired case, you would pass resolve_cfg=False
then have your pre_call
function be responsible for calling OmegaConf.resolve
at the end. This would permit maximum flexibility.
I would happily accept a PR for this. Our CI seems to need some tending to due to breaking changes in pydantic and some other flakiness, so be warned that it might be a little noisy. I hope to fix it this weekend.
(CI is back in good health)