-
Notifications
You must be signed in to change notification settings - Fork 56
enable non-verbose logging of relaxation (e.g. Relax(verbose=0)
)
#11
Comments
The tensorflow warnings can be captured with a catch warnings. But the FIRE: is output from ASE. I am trying to figure out how to control the verbosity, but I can't see an obvious way to do it (beyond supplying a log file, which I don't want to do). |
For the FIRE:, if nothing on the ASE side, maybe filter out lines that begin with FIRE: and then reset the import re
class Filter(object):
"""https://stackoverflow.com/a/63662744/13697228
For reassigning default, https://stackoverflow.com/a/51340381/13697228"""
def __init__(self, stream, re_pattern):
self.stream = stream
self.pattern = (
re.compile(re_pattern) if isinstance(re_pattern, str) else re_pattern
)
self.triggered = False
def __getattr__(self, attr_name):
return getattr(self.stream, attr_name)
def write(self, data):
if data == "\n" and self.triggered:
self.triggered = False
else:
if self.pattern.search(data) is None:
self.stream.write(data)
self.stream.flush()
else:
# caught bad pattern
self.triggered = True
def flush(self):
self.stream.flush() if self.relax_on_decode:
sys.stdout = Filter(sys.stdout, r"^FIRE:| Step Time Energy fmax|\*Force-consistent energies used in optimization.") # type: ignore # noqa: E501
relaxer = Relaxer() # This loads the default pre-trained model
# relaxation
if self.relax_on_decode:
# restore default https://stackoverflow.com/a/51340381/13697228
sys.stdout = sys.__stdout__
|
For the tensorflow warnings, I went with: import tensorflow as tf
...
if not self.verbose:
tf.get_logger().setLevel(logging.ERROR) which just leaves:
I'm pretty sure this is just during the one call to |
I actually found a more elegant solution. Using contextlib.redirect_stdout.... |
Yeah for the TF, I will leave them for now since it is relatively easy to silence by the end user if you wish. Tensorflow has a lot of deprecations and warnings and sometimes those are useful, especially for the developer end.... |
@shyuep great! That works for me. The |
can refactor out again after next m3gnet release materialsvirtuallab/m3gnet#11
Can remove after next m3gnet release materialsvirtuallab/m3gnet#11
Ok, I just released v0.06 that should have the verbosity control. |
This isn't time-sensitive (I'm grateful it's running!), but I'm planning to loop through many structures, and the default output I get for a single relaxation is:
The text was updated successfully, but these errors were encountered: