MolSSI / QCFractal

A distributed compute and database platform for quantum chemistry.
https://molssi.github.io/QCFractal/
BSD 3-Clause "New" or "Revised" License
144 stars 47 forks source link

Validate or clean `add_compute` input before submission #689

Closed lilyminium closed 12 months ago

lilyminium commented 2 years ago

Is your feature request related to a problem? Please describe.

I spent some time debugging a silly error where I passed in a list of keyword ObjectIds instead of a single ObjectId. The error I got was:

Traceback (most recent call last):
  File "./02_mwe.py", line 35, in <module>
    response = client.add_compute(**computation)
  File "/data/homezvol0/lilyw7/miniconda3/envs/psiresp-3.8/lib/python3.8/site-packages/qcfractal/interface/client.py", line 890, in add_compute
    return self._automodel_request("task_queue", "post", payload, full_return=full_return)
  File "/data/homezvol0/lilyw7/miniconda3/envs/psiresp-3.8/lib/python3.8/site-packages/qcfractal/interface/client.py", line 275, in _automodel_request
    r = self._request(rest, name, data=payload.serialize(self.encoding), timeout=timeout)
  File "/data/homezvol0/lilyw7/miniconda3/envs/psiresp-3.8/lib/python3.8/site-packages/qcfractal/interface/client.py", line 237, in _request
    raise IOError("Server communication failure. Reason: {}".format(r.reason))
OSError: Server communication failure. Reason: Internal Server Error

Describe the solution you'd like

A more relevant error message would have been helpful, probably generated via type-checking before sending it off to the server. Alternatively the input could be cleaned as is done for molecule.

Describe alternatives you've considered

Additional context

MWE:

from qcfractal import FractalSnowflakeHandler
import qcelemental as qcel

server = FractalSnowflakeHandler()
client = server.client()
mol = qcel.models.Molecule(**{"symbols": ["He"], "geometry": [0, 0, 0]})

keywords = {"maxiter": 300}
keyword_id = client.add_keywords([ptl.models.KeywordSet(values=keywords)])

computation = dict(
    program="psi4",
    basis="6-31g*",
    method="hf",
    driver="energy",
    molecule=[mol],
    keywords=keyword_id, # add [0] for it to work
)
response = client.add_compute(**computation)
print(response)
ret = client.query_results(response.ids)[0]
print(ret)

Environment

qcelemental               0.23.0             pyhd8ed1ab_0    conda-forge
qcengine                  0.20.0             pyhd8ed1ab_0    conda-forge
qcfractal                 0.15.6           py38h578d9bd_0    conda-forge
qcfractal-core            0.15.6           py38h578d9bd_0    conda-forge
qcportal                  0.15.6             pyhd8ed1ab_0    conda-forge
bennybp commented 12 months ago

v0.50 should be a bit more explicit with errors like this (although still not perfect). At least it will be a pydantic error and not just a generic error. If it's still not enough it might be possible to use typecheck with the client functions.