-
Notifications
You must be signed in to change notification settings - Fork 383
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
Access sub-ingredient's config #923
Comments
Actually, this works as intended; not sure why I thought it didn't. I think I'm actually after "sibling" config. I.e.,
How can I make something like this work? |
The first version also doesn't work, if I switch
Then if I invoked
|
In the second example (sibling config), it should also be
I get
So this is really a question about |
The problem is that Here, an example, that may give you an idea, how the sacred magic works:
|
I guess I don't understand the precedence. Named configs are executed before regular configs, but their values take precedence over regular configs? I.e., regular configs don't over-write the already set values? Is that right? What is the right way to deal with this, where I want to access some global config value in a named config, which I promise won't modify it? Is there some kind of read-only access? Or that's impossible because the value is just not there? Do I have to copy the "default" values that everybody needs access too to every config? That seems like substantial code duplication. |
It seems having a global
|
Yes, that is right. Sacred has priorities, which config values are used, if they are multiple times set.
I have never required something like that. I overwrite values in a named config (For me it is an "shortcut" for the CLI). Then the default config resolves dependencies (e.g. if statements). |
The global variable seems to do the trick. Thanks for your help. |
Sorry, there is one more thing I don't understand. What's the logic why this doesn't work for sub-ingredients? If I explicitly mark |
I don't use |
Named configs are always evaluated before "normal" configs, no matter where they are defined. This is the place where it happens: Lines 420 to 442 in cd90ee1
While I agree that this is confusing and it would make total sense to fully evaluate the sub-ingredient's config (named + normal) before the parent ingredient, this would be a substantial change in the core code. |
And currently you can overwrite a sub-ingredient's config from its parent. Run from sacred import Experiment, Ingredient
i = Ingredient('i')
@i.config
def defaults():
a = 42
ex = Experiment(ingredients=[i])
@ex.named_config
def named():
i = {'a': 123}
@ex.automain
def main(_config):
print(_config) gives
This is incompatible with the other processing order. But I'm unsure which one is more intuitive. |
I have two ingredients. One of them knows about the other one. When configuring the second one, I'd like to be able to access a config value from the first one, but I can't find a way to do this. Here's an example that sketches what I'm after.
Is there any way to do this?
The text was updated successfully, but these errors were encountered: