Project-MONAI / Project-MONAI/tutorials

`runner.sh` Parses Some Files Incorrectly

Open
#1,805 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
2.5k
Forks
803
Avg merge
6d 22h
Merged PRs (30d)
3

Description

Describe the bug
The runner.sh script parses out the output from jupytext into something for feeding into pep8. sed is used in places to pick parts out, however for some weirdly formatting Python this will introduce syntax errors. For example, the following will not be interpreted correctly:

if epoch % 10 == 0:
        print(
            "Train: reconstruction: %.4f; generator: %.4f; discriminator: %.4f; perceptual: %.4f; kld: %.4f"
            % (
                epoch_recon_losses[-1],
                epoch_gen_losses[-1],
                epoch_disc_losses[-1],
                epoch_perc_losses[-1],
                epoch_kld_losses[-1],
            )
        )

The solution is to reformulate the code to avoid these sorts of issues. This example here isn't very attractive code anyway so a refactor to break the contents into multiple lines which are read properly wouldn't hurt anyhow. There will be other cases potentially that are well-formed code but still introduce parsing issues.

This is a minor issue I haven't had time to work on a solution for other than to refactor code, a solution to using jupytext and sed better should be investigated later.

To Reproduce
This can be seen as a problem in PR #1794 currently though a fix is being worked on.

Expected behavior
Script shouldn't introduce issues

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

Start by inspecting runner.sh and its jupytext and sed extraction path, then compare the behavior described in PR #1794. Done means the script preserves well-formed Python while extracting content for pep8 without introducing syntax errors, including the multiline example shown here.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python, shell
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.