Skip to content

Generate reproduction script from GUI input #143

@jokasimr

Description

@jokasimr

A problem when working with the GUI is that you cannot easily reproduce the results.
If you worked in a jupyter notebook it describes the code you ran to produce the output.
Same if you work with a basic script.

To fix this we could let the user to export the GUI state to be able to import it at a later time.
This is probably a useful feature we should have, but it's not really a good way to enable reproducibility, because the user still has to know how to do some more steps in order to actually produce the results (for example, press the "reduce button").
Another problem is that it's very easy to create the results using the GUI, then change some field, forget that you did, and then export the gui state which now does not match the results produced.

Another option is to let the user export a script (probably bash or python) that does everything you need to do to reproduce a set of output files.
The script would contain the gui state and when executed it would

  • create an environment
  • install the same dependencies as in the environment the gui runs in
  • run the workflow to produce the results

The script could then be stored in scicat and would enable anyone to reproduce the results without running the gui.

To illustrate a bit more how I imagine this could work here is a code snippet:

import sys
import json
import subprocess
import pandas


def create_reproduction_script(
    parameters,
    template,
):
    requirements = subprocess.check_output([sys.executable, "-m", "pip", "freeze"]).decode()
    # or maybe?
    requirements_conda = subprocess.check_output(['conda', 'list', '--export']).decode()

    parameters = json.dumps({
        name: value.to_csv() if isinstance(value, pandas.DataFrame) else value
        for name, value in parameters.items()
    })
    return template.substitute(
        requirements=requirements,
        requirements_conda=requirements_conda,
        parameters=parameters
    ) 
# reproduce_gui.py.template
import sys
import json
import subprocess
import tempfile


requirements = '''$requirements'''
requirements_conda = '''$requirements_conda'''

# Install dependencies
with tempfile.NamedTemporaryFile() as f:
    f.write(requirements.encode())
    subprocess.check_output([sys.executable, '-m', 'pip', 'install', '-r', f.name])


with tempfile.NamedTemporaryFile() as f:
    f.write(requirements_conda.encode())
    subprocess.check_output(['conda', 'install', '-y', '--file', f.name])


import pandas
# Data definitions
parameters = json.loads('''$parameters''')
parameters = {name: pandas.read_csv(value) for name, value in parameters.items()}

# Import workflow
from ess.reflectometry.gui import AmorBatchReductionGUI
run = AmorBatchReductionGUI.workflow


if __name__ == '__main__':
   run(parameters)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions