-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add progress bar to phonon calculations #319
Open
RastislavTuranyi
wants to merge
3
commits into
stfc:main
Choose a base branch
from
RastislavTuranyi:268_phonon_progress_bar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+9
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,7 @@ | |||||
import phonopy | ||||||
from phonopy.file_IO import write_force_constants_to_hdf5 | ||||||
from phonopy.structure.atoms import PhonopyAtoms | ||||||
from tqdm import tqdm | ||||||
|
||||||
from janus_core.calculations.base import BaseCalculation | ||||||
from janus_core.calculations.geom_opt import GeomOpt | ||||||
|
@@ -149,6 +150,7 @@ def __init__( | |||||
write_results: bool = True, | ||||||
write_full: bool = True, | ||||||
file_prefix: Optional[PathLike] = None, | ||||||
enable_progress_bar: bool = False | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
To make ruff happy (best merged with other suggestion) |
||||||
) -> None: | ||||||
""" | ||||||
Initialise Phonons class. | ||||||
|
@@ -214,6 +216,8 @@ def __init__( | |||||
file_prefix : Optional[PathLike] | ||||||
Prefix for output filenames. Default is inferred from structure name, or | ||||||
chemical formula of the structure. | ||||||
enable_progress_bar : bool | ||||||
Whether to show a progress bar during phonon calculations. Default is False. | ||||||
""" | ||||||
(read_kwargs, minimize_kwargs) = none_to_dict((read_kwargs, minimize_kwargs)) | ||||||
|
||||||
|
@@ -229,6 +233,7 @@ def __init__( | |||||
self.plot_to_file = plot_to_file | ||||||
self.write_results = write_results | ||||||
self.write_full = write_full | ||||||
self.enable_progress_bar = enable_progress_bar | ||||||
|
||||||
# Ensure supercell is a valid list | ||||||
self.supercell = [supercell] * 3 if isinstance(supercell, int) else supercell | ||||||
|
@@ -357,6 +362,9 @@ def calc_force_constants( | |||||
phonon.generate_displacements(distance=self.displacement) | ||||||
disp_supercells = phonon.supercells_with_displacements | ||||||
|
||||||
if self.enable_progress_bar: | ||||||
disp_supercells = tqdm(disp_supercells) | ||||||
|
||||||
phonon.forces = [ | ||||||
self._calc_forces(supercell) | ||||||
for supercell in disp_supercells | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -258,6 +258,7 @@ def phonons( | |||||
"write_results": True, | ||||||
"write_full": write_full, | ||||||
"file_prefix": file_prefix, | ||||||
"enable_progress_bar": True | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
To make ruff happy (best merged with other suggestion) |
||||||
} | ||||||
|
||||||
# Initialise phonons | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tqdm
may be a dependency of a dependency and that's not a good thing to rely on. You need to add this explicitly to dependencies if you want to use it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also,
rich
is also a dependency of a dependency, that may be a better choice here since Jupyter notebooks and IPython are encouraged ways of using JanusThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how rich compares in terms of performance/overheads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea, but I should think minimal in relation to a phonon calculation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supposedly, they should be pretty comparable nowadays. Regardless, as mentioned, the milliseconds are going to be negligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's all fine if everyone's happy. The main thing was that it was an option which is why (although not necessarily obvious in the GitHub font) "may" was italicised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry the integration is that it prints to the output perfectly happily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, to confirm, we are sticking with
tqdm
, is that right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I obviously haven't seen how this specific one would look in comparison, but in general
rich
maybe looks slightly nicer to me, and maybe fits stylistically with the typer interface better.So, all things being equal (e.g. no immediately noticeable performance issues, which it sounds like there shouldn't be), I'd maybe tend towards
rich
.I am completely fine with
tqdm
if it's more straightforward to finish this PR up though, as long as it addresses the issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, don't forget @oerc0122's original point to add the dependency to pyproject.toml!