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

Use logging/warnings instead of print when loading force constants from Phonopy #325

Closed
RastislavTuranyi opened this issue Nov 8, 2024 · 3 comments
Labels
wontfix This will not be worked on

Comments

@RastislavTuranyi
Copy link

Hi!

Loading force constants from Phonopy can generate multiple "warnings" e.g. Force constants not found in 4-benzylaniline_683106-phonopy.yaml, attempting to read from 4-benzylaniline_683106-force_constants.hdf5 which takes a lot of terminal space when I run many calculations in a script. Therefore, I tried looking into disabling these stdout prints, but it turned out that they are hardcoded print statements.

Would it be possible to use something like logging or warnings.warn to log these messages? That way, it would be possible to intercept them upstream

@ajjackson
Copy link
Collaborator

This would technically be a breaking change, but it would indeed be nice to have the verbosity control that logging provides. (And allow us to print more debug information!)

Have you considered using https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout in the script?

To discard standard output from a function:

with redirect_stdout(None):
    run_something()

Or to store it to a list:

buffer = io.StringIO()
with redirect_stdout(buffer):
    run_something()
    
buffer.seek(0)
lines = buffer.readlines()

@ajjackson
Copy link
Collaborator

Perhaps we should create a wider Issue to consider using logging consistently across Euphonic for versions 2.x

@ajjackson ajjackson added the wontfix This will not be worked on label Feb 7, 2025
@ajjackson
Copy link
Collaborator

Closing as wontfix because we won't treat Phonopy reader specially. Opening separate issue for wider discussion of logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants