Skip to content

Commit

Permalink
Merge pull request #30 from dgasmith/stdout
Browse files Browse the repository at this point in the history
Psi4: Ensures output always goes to stdout field
  • Loading branch information
dgasmith authored Feb 19, 2019
2 parents 835b291 + fb02386 commit 437f3ca
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion devtools/conda-envs/psi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- pyyaml
- py-cpuinfo
- psutil
- qcelemental >=0.2.2
- qcelemental >=0.2.6
- pydantic >=0.18.1

# Testing
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/rdkit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- pyyaml
- py-cpuinfo
- psutil
- qcelemental >=0.2.2
- qcelemental >=0.2.6
- pydantic >=0.18.1

# Testing
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/torchani.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
- pyyaml
- py-cpuinfo
- psutil
- qcelemental >=0.2.2
- qcelemental >=0.2.6
- pydantic >=0.18.1

# Testing
Expand Down
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Enhancements

- (:pr:`24`) Improves load times dramatically by delaying imports and cpuutils.
- (:pr:`25`) Code base linting.
- (:pr:`30`) Ensures Psi4 output is already returned and Pydantic v0.20+ changes.

v0.5.1 / 2019-01-29
-------------------
Expand Down
19 changes: 12 additions & 7 deletions qcengine/programs/psi4.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def _parse_psi_version(version):
input_data["nthreads"] = config.ncores
input_data["memory"] = int(config.memory * 1024 * 1024 * 1024 * 0.95) # Memory in bytes
input_data["success"] = False
reset_schema = False
input_data["return_output"] = True

if input_data["schema_name"] == "qcschema_input":
input_data["schema_name"] = "qc_schema_input"
reset_schema = True

scratch = config.scratch_directory
if scratch is not None:
Expand All @@ -51,8 +51,9 @@ def _parse_psi_version(version):
else:
raise TypeError("Psi4 version '{}' not understood.".format(psi_version))

if reset_schema:
output_data["schema_name"] = "qcschema_input"
# Reset the schema if required
output_data["schema_name"] = "qcschema_output"

# Dispatch errors, PSIO Errors are not recoverable for future runs
if output_data["success"] is False:

Expand All @@ -61,9 +62,13 @@ def _parse_psi_version(version):

# Move several pieces up a level
if output_data["success"]:
output_data["provenance"]["memory"] = round(input_data["memory"] / (1024**3), 3)
output_data["provenance"]["nthreads"] = input_data["nthreads"]
del output_data["memory"], input_data["nthreads"]
output_data["provenance"]["memory"] = round(output_data.pop("memory") / (1024**3), 3) # Move back to GB
output_data["provenance"]["nthreads"] = output_data.pop("nthreads")
output_data["stdout"] = output_data.pop("raw_output", None)

# Delete keys
output_data.pop("return_ouput", None)

return Result(**output_data)
return FailedOperation(
success=output_data.pop("success", False), error=output_data.pop("error"), input_data=output_data)
34 changes: 17 additions & 17 deletions qcengine/tests/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def test_psi4_task():
json_data["keywords"] = {"scf_type": "df"}
json_data["return_output"] = False

ret = dc.compute(json_data, "psi4", raise_error=True)
ret = dc.compute(json_data, "psi4", raise_error=True, capture_output=False)

assert ret["driver"] == "energy"
assert "provenance" in ret
assert "Final Energy" in ret["stdout"]

for key in ["cpu", "hostname", "username", "wall_time"]:
assert key in ret["provenance"]
Expand All @@ -42,22 +43,21 @@ def test_psi4_task():

@addons.using_psi4
def test_psi4_ref_switch():
inp = ResultInput(
**{
"molecule": {
"symbols": ["Li"],
"geometry": [0, 0, 0],
"molecular_multiplicity": 2
},
"driver": "energy",
"model": {
"method": "SCF",
"basis": "sto-3g"
},
"keywords": {
"scf_type": "df"
}
})
inp = ResultInput(**{
"molecule": {
"symbols": ["Li"],
"geometry": [0, 0, 0],
"molecular_multiplicity": 2
},
"driver": "energy",
"model": {
"method": "SCF",
"basis": "sto-3g"
},
"keywords": {
"scf_type": "df"
}
})

ret = dc.compute(inp, "psi4", raise_error=True, return_dict=False)

Expand Down
9 changes: 5 additions & 4 deletions qcengine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def handle_output_metadata(output_data, metadata, raise_error=False, return_dict
else:
output_fusion = output_data.dict()

output_fusion["stdout"] = metadata["stdout"]
output_fusion["stderr"] = metadata["stderr"]
# Do not override if computer generates
output_fusion["stdout"] = output_fusion.pop("stdout", metadata["stdout"])
output_fusion["stderr"] = output_fusion.pop("stderr", metadata["stderr"])

if metadata["success"] is not True:
output_fusion["success"] = False
output_fusion["error"] = {"error_type": "meta_error", "error_message": metadata["error_message"]}
Expand All @@ -142,9 +144,8 @@ def handle_output_metadata(output_data, metadata, raise_error=False, return_dict
raise ValueError(output_fusion["error"]["error_message"])

# Fill out provenance datadata
wall_time = metadata["wall_time"]
provenance_augments = config.get_provenance_augments()
provenance_augments["wall_time"] = wall_time
provenance_augments["wall_time"] = metadata["wall_time"]
if "provenance" in output_fusion:
output_fusion["provenance"].update(provenance_augments)
else:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'pyyaml',
'py-cpuinfo',
'psutil',
'qcelemental>=0.2.2',
'qcelemental>=0.2.6',
'pydantic>=0.18.0'
],
entry_points={"console_scripts": [
Expand Down

0 comments on commit 437f3ca

Please sign in to comment.