Skip to content

Commit

Permalink
Bugfix: handling of configurations and gradients
Browse files Browse the repository at this point in the history
* The code handled configurations incorrectly.This has been fixed.
* The gradients were not output correctly, causing problems in e.g the Structure
  and Thermochemistry steps.
* Changed logging at the INFO level to DEBUG to clean up the output of geomeTRIC.
  • Loading branch information
paulsaxe committed Feb 7, 2025
1 parent 08e9f7b commit 748a273
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
=======
History
=======
2024.2.7 -- Bugfix: handling of configurations and gradients
* The code handled configurations incorrectly.This has been fixed.
* The gradients were not output correctly, causing problems in e.g the Structure
and Thermochemistry steps.
* Changed logging at the INFO level to DEBUG to clean up the output of geomeTRIC.

2024.10.15 -- Bugfix: error if used in a loop and previous directories deleted.
* The code crashed if called with a loop in the flowchart, and the last directory of
a previous loop iteration was deleted before running the next iteration.
Expand Down
4 changes: 2 additions & 2 deletions torchani_step/SEAMM_TorchANI.py_template
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ class TorchANI:
if need_gradients:
dE = dE_stack.mean(dim=0).tolist()
dE_stdev = dE_stack.std(dim=0).tolist()
results["gradients"] = dE
results["gradients, stdev"] = dE_stdev
results["gradients"] = dE[0]
results["gradients, stdev"] = dE_stdev[0]

configuration["results"]["data"].append(results)

Expand Down
5 changes: 1 addition & 4 deletions torchani_step/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def analyze(self, indent="", **kwargs):
)

# Get the appropriate system/configuration for the new coordinates
system, configuration = self.get_system_configuration(P)
system, configuration = self.get_system_configuration(None)

schema = kwargs["schema"]
step_no = kwargs["step_no"]
Expand All @@ -263,9 +263,6 @@ def analyze(self, indent="", **kwargs):
# The model chemistry
self.model = f"ANI/{P['model']}"

# Get the appropriate system/configuration
system, configuration = self.get_system_configuration(P)

have_stdev = False
for system in schema["systems"]:
system_name = system["name"]
Expand Down
16 changes: 9 additions & 7 deletions torchani_step/torchani.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ def description_text(self, P=None):
text += __(node.description_text(), indent=3 * " ").__str__()
except Exception as e:
print(f"Error describing torchani flowchart: {e} in {node}")
logger.critical(f"Error describing torchani flowchart: {e} in {node}")
self.logger.critical(
f"Error describing torchani flowchart: {e} in {node}"
)
raise
except: # noqa: E722
print(
"Unexpected error describing torchani flowchart: {} in {}".format(
sys.exc_info()[0], str(node)
)
)
logger.critical(
self.logger.critical(
"Unexpected error describing torchani flowchart: {} in {}".format(
sys.exc_info()[0], str(node)
)
Expand Down Expand Up @@ -240,7 +242,7 @@ def run(self):
schema, indent=4, cls=CompactJSONEncoder, sort_keys=True
)
files = {"input.json": input_data}
logger.info("input.json:\n" + files["input.json"])
self.logger.debug("input.json:\n" + files["input.json"])
executor = self.flowchart.executor

# Read configuration file for TorchANI if it exists
Expand Down Expand Up @@ -292,7 +294,7 @@ def run(self):
"stderr.txt",
]

self.logger.info(f"{cmd=}")
self.logger.debug(f"{cmd=}")

result = executor.run(
cmd=cmd,
Expand All @@ -308,9 +310,9 @@ def run(self):
self.logger.error("There was an error running TorchANI")
return None

logger.debug("\n" + pprint.pformat(result))
self.logger.debug("\n" + pprint.pformat(result))

logger.info("stdout:\n" + result["stdout"])
self.logger.debug("stdout:\n" + result["stdout"])
if "stderr.txt" in result and "data" in result["stderr.txt"]:
if result["stderr.txt"]["data"] != "":
lines = result["stderr.txt"]["data"].splitlines()
Expand All @@ -324,7 +326,7 @@ def run(self):
continue
tmp.append(line)
if len(tmp) > 0:
logger.warning("stderr:\n" + "\n".join(tmp))
self.logger.warning("stderr:\n" + "\n".join(tmp))

lines = result["output.json"]["data"].splitlines()
line = lines[0]
Expand Down

0 comments on commit 748a273

Please sign in to comment.