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

Verbosity #305

Merged
merged 6 commits into from
Oct 18, 2024
Merged

Verbosity #305

merged 6 commits into from
Oct 18, 2024

Conversation

benoitlaurent96
Copy link
Collaborator

Added different verbosity levels in the source code using the standard logging module. The user can change the verbosity level with the function WallGoManager.setVerbosity(). The levels follow the standard logging convention, with logging.DEBUG=10, logging.INFO=20, logging.WARNING=30 and logging.ERROR=40.

I wasn't sure if the verbosity level should be treated as another config parameter and included in the config file. In the end I didn't choose to code it like that, but I'm open to another opinion.

Most of the information that was previously shown with print() is now at the INFO level. The detail of the pressure calculation (showing the pressure and error at each iteration) is at the DEBUG level. Every message printed when something not expected happens is at the WARNING level. Let me know if you think some of the levels are not appropriate.

@jorindevandevis
Copy link
Collaborator

What about having a command line argument option for setting the verbosity?

Copy link
Collaborator

@og113 og113 left a comment

Choose a reason for hiding this comment

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

This works really nicely.

Here are some suggestions for improvements to printing:

  • There are print statements in src/WallGo/__init__.py which are always called, and hence not controlled by the verbosity level. Can these be replaced by logging statements, or does this require the WallGoManager already to be initialised?
  • There is also a print statement in src/WallGo/PotentialTools/__init__.py for which I would ask the same question.
  • There is a print(self.modelParameters) statement in the __init__ in yukawa.py which just prints an empty dict. I think this can be just deleted.
  • There is a space at the beginning of the line printing === Begin EOM with off-eq effects ignored === which should be removed.
  • WallGoManager.setVerbosity should have a docs string.

src/WallGo/wallGoManager.py Show resolved Hide resolved
@benoitlaurent96
Copy link
Collaborator Author

What about having a command line argument option for setting the verbosity?

It's already in the wallGoExampleBase file. So when you run an example, you can add something like '--verbose 20' (which would set it to the INFO level). However, this is not in the source code, so it won't be available if a user codes their own example without using ours.

@benoitlaurent96
Copy link
Collaborator Author

  • There are print statements in src/WallGo/__init__.py which are always called, and hence not controlled by the verbosity level. Can these be replaced by logging statements, or does this require the WallGoManager already to be initialised?

Yes, to work properly, the logging module must be initialised. Since the init file is the first thing to be called, I don't see how the user could have any control over the verbosity in there. Do you have a solution?

@niemilau
Copy link
Collaborator

  • There are print statements in src/WallGo/__init__.py which are always called, and hence not controlled by the verbosity level. Can these be replaced by logging statements, or does this require the WallGoManager already to be initialised?

Yes, to work properly, the logging module must be initialised. Since the init file is the first thing to be called, I don't see how the user could have any control over the verbosity in there. Do you have a solution?

After a quick look:

  • _initializeInternal() is now useless so can be removed.
  • There are prints related to WallGoCollision loading that could be changed to RuntimeWarning.

The whole logic behind loading WallGoCollision internally could use polish and I'm not sure what the best approach here would be. The main complication is that if we want to allow WallGo to be used without WallGoCollision installed, we can't import eg. collisionHelpers.py into the WallGo package without first checking that WallGoCollision can be successfully imported.

@og113
Copy link
Collaborator

og113 commented Oct 17, 2024

Okay, thanks for the explanation. I don't think we don't want plain print statements in the __init__ files. If we are raising a warning or an error we can just do that. If there is other useful information to convey, then it should be stored rather than printed in __init__ (though the location of the collisions is already stored, so nothing to add there).

@og113
Copy link
Collaborator

og113 commented Oct 17, 2024

Lauri raises a good point about the interrelation between WallGo and WallGoCollisions. At the moment there are lots of different import WallGoCollisions statements all over the place, and it is somewhat confusing. However, I don't think this PR is the place to fix this particular question. I will make an Issue for it.

Copy link
Collaborator

@og113 og113 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. I suggest let's remove print statements from __init__, replacing those that relate to warnings or errors with warnings or errors. And, as Lauri says, the _initializeInternal in WallGo/__init__.py doesn't do anything useful anymore so can be removed.

"--verbose",
type=int,
default=logging.DEBUG,
help="""Set the verbosity level. Must an int: DEBUG=10, INFO=20, WARNING=30,
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Must an int" -> "Must be an int"

@benoitlaurent96
Copy link
Collaborator Author

I removed the prints in the init file. Let me know if I can merge it.

Copy link
Collaborator

@og113 og113 left a comment

Choose a reason for hiding this comment

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

Tiny change requested (add raise).

_bCollisionModuleAvailable = True # pylint: disable=invalid-name

from .collisionHelpers import *

except ImportError as e:
print(f"Error loading WallGoCollision module: {e}")
print(
RuntimeWarning(f"Error loading WallGoCollision module: {e}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this not be raise RuntimWarning(...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it has to be warnings.warn(...), otherwise raise would stop the program.

@benoitlaurent96 benoitlaurent96 merged commit ef491dc into main Oct 18, 2024
4 checks passed
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.

4 participants