Skip to content

Commit

Permalink
Psi4 random fail restarts (#409)
Browse files Browse the repository at this point in the history
* add mocked error test

* update psi4 error message

* formatting

* skip test if psi4 not installed

* update pydantic maximum version

* lint

---------

Co-authored-by: Lori A. Burns <[email protected]>
  • Loading branch information
jthorton and loriab authored Aug 2, 2023
1 parent 25d3b99 commit 3f69fad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion devtools/conda-envs/openmm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies:
- py-cpuinfo
- psutil
- qcelemental >=0.11.1
- pydantic >=0.30.1
- pydantic >=1.8.2

# Testing
- pytest
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/qcore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- py-cpuinfo
- psutil
- qcelemental >=0.24
- pydantic >=0.30.1
- pydantic >=1.8.2
- tbb<2021

# Testing
Expand Down
2 changes: 1 addition & 1 deletion devtools/conda-envs/xtb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- py-cpuinfo
- psutil
- qcelemental >=0.11.1
- pydantic >=0.30.1
- pydantic >=1.8.2

# Extras
- gcp-correction
Expand Down
2 changes: 1 addition & 1 deletion qcengine/programs/psi4.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _handle_errors(self, output_data):
error_message = output_data["error"]["error_message"]
error_type = output_data["error"].get("error_type", "unknown_error")
else:
error_message = "Unknown error, error message is not found, possibly segfaulted"
error_message = "Unknown error, error message is not found, possible segmentation fault!"
error_type = "internal_error"

return error_message, error_type
Expand Down
25 changes: 25 additions & 0 deletions qcengine/tests/test_harness_canonical.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests the DQM compute dispatch module
"""
import msgpack
import numpy as np
import pytest
from qcelemental.models import AtomicInput, BasisSet
Expand Down Expand Up @@ -148,3 +149,27 @@ def test_compute_bad_models(program, model):

with pytest.raises(qcng.exceptions.InputError) as exc:
ret = qcng.compute(inp, program, raise_error=True)


def test_psi4_restarts(monkeypatch):
"""
Make sure that a random error is raised which can be restarted if psi4 fails with no error message
"""
if not has_program("psi4"):
pytest.skip("Program psi4 not found.")

# create the psi4 task
inp = AtomicInput(molecule=qcng.get_molecule("hydrogen"), driver="energy", model={"method": "hf", "basis": "6-31G"})

def mock_execute(*args, **kwargs):
"""
Mock the output of a failed psi4 task with missing error message.
"""

mock_output = {"sucess": False, "outfiles": {"data.msgpack": msgpack.dumps({"missing": "data"})}}
return True, mock_output

monkeypatch.setattr("qcengine.programs.psi4.execute", mock_execute)

with pytest.raises(qcng.exceptions.RandomError):
_ = qcng.compute(input_data=inp, program="psi4", raise_error=True, task_config={"retries": 0})

0 comments on commit 3f69fad

Please sign in to comment.