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

Set disable=None by default for progress bar in ctapipe tools #2444

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

morcuended
Copy link
Member

@morcuended morcuended commented Nov 2, 2023

Sets tqdm(..., disable=None) in process and merge ctapipe tools.

By default the progress bar is displayed when running the tools in interactive mode. If they are executed in non-tty mode the progress bar is disabled. There is also a command line option --disable-progress to disable it.

I added some tests to check the expected behavior in both tty and non-tty modes.

Closes #2366

@morcuended morcuended changed the title Set disable=None by default in ctapipe tools Set disable=None by default for progress bar in ctapipe tools Nov 2, 2023
Copy link
Contributor

@kosack kosack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove the --progress option in a few other tests in test_process.py, I think.

Another potential suggestion (optional): since many people may still have this option in their scripts, maybe deprecating it more gracefully would be nice? e.g. add a --progress option that does nothing except emit a warning that the --progress option is deprecated and no longer needed (and to use --disable-progress to remove the automatic progress bar if necessary). We might want to always do that on changes to top-level command-line options.

@morcuended
Copy link
Member Author

You need to remove the --progress option in a few other tests in test_process.py, I think.

Yes, done. Thanks.

Another potential suggestion (optional): since many people may still have this option in their scripts, maybe deprecating it more gracefully would be nice? e.g. add a --progress option that does nothing except emit a warning that the --progress option is deprecated and no longer needed (and to use --disable-progress to remove the automatic progress bar if necessary). We might want to always do that on changes to top-level command-line options.

Thanks, Good idea. I will do so.

@morcuended
Copy link
Member Author

I tried to implement some tests for disabling the progress bar when using non-tty mode and also that it is displayed automatically in tty mode. But I found no straightforward way to capture the progress bar using, for example, subprocess. If you think tests on this are anyways necessary, we could try to find a way.

@@ -118,6 +113,10 @@ class ApplyModels(Tool):
},
"Overwrite output file if it exists",
),
"disable-progress": (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the flag definition should be left as before, but the action needs to changed accordingly.

I think the desired behavior is:

  • Flag not given sets disable=None, so tqdm checks if it runs in an interactive environment or not
  • --progress forces the progress bar -> disable=False
  • --no-progress forces the progress bar to be disabled -> disable=True.

This would be the case for:

"progress": ({"ApplyModels": {"disable_progress_bar": False}}, "Always enable progress bar."),
"no-progress": ({"ApplyModels": {"disable_progress_bar": True}}, "Always disable progress bar."),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, indeed that would not change the current implementation. It is actually what we briefly discussed in the meeting, I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at all this duplicated code now, we could move these options to the base Tool class with a method progress_bar so we have this only in one place and the implementations can just do:

for foo in self.progress_bar(iterable, **options):
    ...

@morcuended morcuended marked this pull request as draft November 6, 2023 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default values of progress bar option to None
3 participants