Skip to content
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

Avoiding required nesting of configs #61

Open
KennethEnevoldsen opened this issue Jan 7, 2024 · 2 comments
Open

Avoiding required nesting of configs #61

KennethEnevoldsen opened this issue Jan 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@KennethEnevoldsen
Copy link
Contributor

Hi, I have had the problem that I often want variables defined in the top-most layers of my config (e.g. a logger as seen below), which I then want to refer to in multiple places. This causes a recursion error:

InterpolationDepthError: Recursion limit exceeded in value substitution: option 'logger' in section 'training' contains an interpolation key which cannot be substituted in 10 steps. Raw value: '${logger}'

I don't see any principled reason why that would not be possible (though I might be wrong). My question is simply if I were to find the time to make a PR for this would it be considered useful?

Minimal example:

import catalogue

from confection import Config, registry


class Registry(registry):
    registry = catalogue.create("my_package", "loggers")


@Registry.registry.register("my_logger")
def test_fn(name: str):
    return name

# desired config
config_str_unnested = """
[logger]
@registry = "my_logger"
name = "test_logger"


[training]
batch_size = 32
logger = ${logger}
"""

# current config
config_str_nested = """
[logger]
[logger.logger]
@registry = "my_logger"
name = "test_logger"


[training]
batch_size = 32
logger = ${logger.logger}
"""

if __name__ == "__main__":
    cfg = Config().from_str(text=config_str_nested)
    # works, but is less readable
    cfg = Config().from_str(text=config_str_unnested) 
    # does not work, but is more readable
@svlandeg svlandeg added the enhancement New feature or request label Jan 8, 2024
@svlandeg
Copy link
Member

Hey @KennethEnevoldsen - sorry for the slow response to these very reasonable questions / suggestions, we're working through a bit of a backlog for support after the holiday season.

We'd definitely think this would be useful if you'd find the time for a PR.

Just for my understanding - do you want the function called multiple times, or the same object referenced?

@KennethEnevoldsen
Copy link
Contributor Author

Ideally the same object references, but can see that there might be a challenge there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants