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: Recurrsively track the imported source files #812

Open
Jarvis73 opened this issue Mar 20, 2021 · 3 comments
Open

Feature Request: Recurrsively track the imported source files #812

Jarvis73 opened this issue Mar 20, 2021 · 3 comments
Labels

Comments

@Jarvis73
Copy link

Jarvis73 commented Mar 20, 2021

I have three source files:

  • main.py
from sacred import Experiment
import dataset

ex = Experiment("ExpName")

@ex.automain
def main(_run):
    print(_run.experiment_info['sources'])
  • dataset.py
import utils
  • utils.py
# Some util functions

When I run the main.py, the output is

[('main.py', '8f7e3a8cdd0d92b7255dae98fe255dc2'), ('dataset.py', 'd8f74eeb22a5f209e4c8b12258282689')]

But the utils.py is not included.

I think recursively tracking the imported source files is a general way to organize my experiments. But now I have to manually add the utils.py by ex.add_source_file("utils.py"), which is not quite convenient.

@Jarvis73 Jarvis73 changed the title Recurrsively track the imported source files Feature Request: Recurrsively track the imported source files Mar 20, 2021
@thequilo
Copy link
Collaborator

I agree this would be a good feature. I'm not that familiar with dependency gathering, but I think that it shouldn't be too complicated.

In general, I would recommend putting all your sources in a git repository. Then, sacred can track the state of that git repository. But even then, it could be that you import another custom package in your code that depends on other things that are currently not tracked.

Let's add this feature as an option for dependency gathering!

@Qwlouse
Copy link
Collaborator

Qwlouse commented May 3, 2021

Try:

from sacred import SETTINGS

SETTINGS["DISCOVER_DEPENDENCIES"] = "sys"

Sacred supports four dependency gathering strategies:

  • "none": do not gather dependencies at all
  • "imported": collect all modules that are imported from the main script (default)
  • "sys": collect all modules that are cached by sys.modules (<- this should capture recursive imports too)
  • "dir": collect all python files in the directory or any subdirectories of the main script

@Jarvis73
Copy link
Author

@Qwlouse
Thank you for your reply. I tested the sys mode, and it did solve my question.

@thequilo
By the way, I think maybe the sys mode is more natural to be the default option than imported. Because only if all the "recursively imported source files" are reserved, one can reproduce the experiments.

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

No branches or pull requests

3 participants