Use Cookiecutter to generate new experiments as well as workspaces #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
I realised that the most useful thing this tool could do would be to just semi-automate the task of copying relevant files and information from a workspace to an experiment directory. But if experiment directories could be templated according to user preferences this would be even nicer.
So, let's lean on the widely-used Cookiecutter to generate experiment directories from templates!
Implementation
Basically what happens is
cookiecutter.main.cookiecutter
via theextra_context
argument. This allows the user to refer to configuration parameters in the template. This generates the experiment directory (and templated files)Customisation and Cookiecutter 2.0
One thing that can be nice with Cookiecutter is being able to dynamically input parameters at the point of generation. However, the latest stable version of Cookiecutter on PyPI (1.7.3) only allows us to choose between prompting the user for all of the parameters defined in
cookiecutter.json
, or not prompting the user at all and relying completely on defaults and injected context.This rules out prompting here, since we do not want the user to have to confirm, nor even be able to modify, the parameters injected by PyREx. Hence, while one is welcome to extend the base experiment template by adding more parameters to
cookiecutter.json
, these will not be prompted for and will hence take their default values.It looks like this restriction will be lifted when Cookiecutter 2.0 is released, which introduces private variables in the
cookiecutter.json
which are never prompted for, but whose values can be overridden using theextra_context
parameter.Unfortunately, it's not clear when 2.0 will be released, and Cookiecutter seems to be suffering from a lack of maintenance. See these issues: #1555, #1636, #1642.