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

[Feature Request] Promote Compose API to hydra.compose() #953

Closed
liuzhenqi77 opened this issue Sep 8, 2020 · 2 comments
Closed

[Feature Request] Promote Compose API to hydra.compose() #953

liuzhenqi77 opened this issue Sep 8, 2020 · 2 comments
Labels
enhancement Enhanvement request

Comments

@liuzhenqi77
Copy link

🚀 Feature Request

Promote Compose API to hydra.compose() decorator

Motivation

As a Hydra beginner, I quickly stumbled upon this issue of hydra.main() not returning values (#769). Then I switch to the Compose API, which I find really useful when starting & testing a project from scratch, when I do not need complex functions like multirun at this stage. Sometimes only config and some logging are needed.

Pitch

It would be great if hydra.compose() decorator is supported to use Compose API functions like in the original idea (#219).

It would also be great if the basics like config, output, logging, (optional) disable output, etc, are supported. They are really helpful for those functions not in app() and do need to return parameters. And it would be helpful for transition from prototype code to final parameter-sweeping.

@liuzhenqi77 liuzhenqi77 added the enhancement Enhanvement request label Sep 8, 2020
@omry
Copy link
Collaborator

omry commented Sep 9, 2020

Hi @liuzhenqi77, thanks for your suggestion.

I strongly suggest using @hydra.main by default and reverting to compose() in cases where you do not have access to the command line. (tests, notebooks etc).
By starting your project using compose you are basically guaranteeing that you will have difficulties down the line.

If you want to return a value from your @hydra.main you are probably thinking about it in the wrong way. It is designed to be the entry point to your application. not a function you call.

At this point I have no plans of closing the functional gap between compose and @hydra.main().
I do have plans to make allow disabling the output directory management of @hydra.main() though, (#910).
furthermore, The current API for compose is more flexible than a the decorator style API and I do not plan to switch it to a decorator API.

@omry omry closed this as completed Sep 9, 2020
@addisonklinke
Copy link

FWIW I was unit testing some code where several downstream tasks assumed the Hydra log file would be present. Rather than modify my source code to deal with this (just for the sake of testing), I used hydra.core.utils.configure_log() to ensure the logging was setup even with the Compose API

I'm not sure if this is discouraged, but the function is public and it's just a thin wrapper around logging.config.dictConfig

from hydra import compose, initialize
from hydra.core.utils import configure_log

with initialize(config_path=None):
    cfg = compose('config', return_hydra_config=True)
configure_log(cfg.hydra.job_logging)

You can also alter the logging node before passing it through, in case you want different configurations based on the test

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

No branches or pull requests

3 participants