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

[ENH] Handle Additional Kwargs in AiiDA Progress Reporter #6757

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

Conversation

jgyasu
Copy link

@jgyasu jgyasu commented Feb 15, 2025

Fixes #6564

  • Added _kwargs storage to ProgressReporterAbstract
  • New methods to access and update kwargs
  • Modified create_callback to handle additional parameters
  • Updated tqdm integration to properly merge kwargs

@jgyasu
Copy link
Author

jgyasu commented Feb 15, 2025

@khsrali @unkcpz I will aprreciate any review to my draft PR. I haven't added the tests yet but if the design looks fine then I can add tests. Thank you :)

@unkcpz
Copy link
Member

unkcpz commented Feb 15, 2025

@khsrali could you give it a look? The callback seems a bit anti-pattern, I may prefer to go with dependency injection for the original reporter implementation in disk-objectstore. But since it is already there, I may don't have time to take a look at further change. Much appreciate if you can take care of this.

@jgyasu
Copy link
Author

jgyasu commented Feb 16, 2025

So is this implementation fine for now? @khsrali

Copy link
Contributor

@khsrali khsrali left a comment

Choose a reason for hiding this comment

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

Thanks @jgyasu

You can start writing tests, maybe also try with manual tests.
As this is more of a visual and graphical thing.

The idea, was to allow some keywords pass to the progress reporter. The progress reported may or not be tqdm. In case it's tqdim it has to check if those keywords are legit and if they are not in conflict with this:

TQDM_BAR_FORMAT = '{desc:40.40}{percentage:6.1f}%|{bar}| {n_fmt}/{total_fmt}'

If they are in conflict, either raise, or think how to solve it.

merged_kwargs.update(init_kwargs)
return tqdm(*args, **merged_kwargs)

set_progress_reporter(tqdm_with_kwargs, bar_format=bar_format, leave=leave)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, if this works.. As you already initialize it

Copy link
Contributor

Choose a reason for hiding this comment

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

You may pass the class when it's not initialized, yet.

"""Return the additional keyword arguments."""
return self._kwargs

def update_kwargs(self, **kwargs: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

The given keywords should not conflict with TQDM_BAR_FORMAT

progress_reporter.reset(value['total'])
progress_reporter.set_description_str(value['description'])
total = value.pop('total', None)
description = value.pop('description', None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to change this? there will always be a value in the way the _callback supposed to be utilized

progress_reporter.set_description_str(description)

if value:
progress_reporter.update_kwargs(**value)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't really need to update this.
Also this keywords are not exactly one-to-one to tqdm keys

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.

aiida/common/progress_reporter.py could accept **kwargs
3 participants