scipp / scipp/ess

Generate reproduction script from GUI input

Open
#289 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

essreflectometry
Dominant language
Python
Stars
1
Forks
3
Avg merge
2d 11h
Merged PRs (30d)
17

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository files or tests; start by reading the workflow entry point ess.reflectometry.gui.AmorBatchReductionGUI.workflow and the surrounding GUI parameter handling. Define the generated script's supported inputs and outputs, then verify that it captures the environment and parameters and can reproduce the GUI-produced output files.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.