Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyscf driver does no checking on input arguments at instantiation #28

Closed
nonhermitian opened this issue Dec 3, 2020 · 5 comments · Fixed by #180
Closed

pyscf driver does no checking on input arguments at instantiation #28

nonhermitian opened this issue Dec 3, 2020 · 5 comments · Fixed by #180
Assignees
Labels
type: documentation Issues related to documentation

Comments

@nonhermitian
Copy link
Contributor

Information

  • Qiskit Aqua version: lastest
  • Python version:
  • Operating system:

What is the current behavior?

for example:

driver = PySCFDriver(molecule = 'happy holidays', unit=UnitsType.ANGSTROM, basis='happy holidays')

does not generate an error when the object is built. The unit kwarg does look for an enum, but that is it. This leads to hard to read errors down the line:

e.g. the above gives:

AttributeError: 'str' object has no attribute 'geometry'

or

driver = PySCFDriver(molecule = molecule, unit=UnitsType.ANGSTROM, basis='happy holidays')

gives:

QiskitChemistryError: 'Failed electronic structure computation'

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

@woodsp-ibm
Copy link
Member

There is a finite amount of checking that is done and also things are passed to the driver for interpretation too, like the molecule since different formats are possible XYZ, Z_matrix etc. Things like basis set are dependent on driver. Even if the format is correct it may still be semantically incorrect in which case these types of errors, incorrect basis set name etc are caught by the driver and the error reported is what it gives. It maybe possible to improve for specific cases but in general the input is passed to the drivers and it relies on whatever the driver reports to report back - trying to do syntactic and semantic checking is a huge undertaking given the driver complexity of capabilities and not something that is in any way practical. Having said there there maybe room for some minor incremental improvement but its not going to avoid seeing the sort of error you show.

@nonhermitian
Copy link
Contributor Author

But then the end user has no idea what is actually a valid input for most of the inputs. In the case of basis, there must be a finite number of options. In the case of pyscf, a quick glace at their docs gives:

'sto3g'
'sto-3g'
'sto6g'
'sto-6g'
'631g'
'6-31g'
'321g'
'3-21g'
'ccpvdz'
'cc-pvdz'
'gth-szv'
'gthszv'

as as valid inputs. Again, QiskitChemistryError: 'Failed electronic structure computation' is not a very good error message as that could point to one of many possible issues.

@woodsp-ibm
Copy link
Member

Maybe something can be said around the basis sets to make it clearer we expect users to look to the driver documentation for whatever these are. The set in PySCF is much much larger than you indicate - more like this here https://sunqm.github.io/pyscf/_modules/pyscf/gto/basis.html

The 'electronic structure computation` should also have the source exception from PySCF that this was re-raised from. That is as much information that is available as to why PySCF failed in the computation.

As to this message

AttributeError: 'str' object has no attribute 'geometry'

the molecule is shown in the docs as something of type Molecule - and you passed in a string. I imagine the code then looks for the geometry attribute on the molecule instance - whatever type you passed, in this case a 'str', it did not have it.

@nonhermitian
Copy link
Contributor Author

Ok then it seems you already know where to find the basis options. Can just refer the user there in the docs. As for molecule, you would expect that the driver would error if something that was not a molecule instance was passed.

@woodsp-ibm
Copy link
Member

woodsp-ibm commented Dec 8, 2020

Can just refer the user there in the docs.

Other attributes have refs. to more specifics in PySCF that detail the value so it seems reasonable to give one here.

As for molecule, you would expect that the driver would error if something that was not a molecule instance was passed.

It did error - the error it threw when it attempted to access a field it expected on the instance that was passed. I agree its not so easy to figure from the error perhaps but then this can often be the case with Python as its not a strongly typed language and type checking is really against the philiosphy of duck typing so its not normally done. If you look at the docs/typehints its says it should be Molecule. If you edit in an IDE, such as PyCharm, they recognise the typehints from the code and would alert you to the type mismatch when you were editing.

@woodsp-ibm woodsp-ibm transferred this issue from qiskit-community/qiskit-aqua Jan 29, 2021
@mrossinek mrossinek mentioned this issue May 10, 2021
6 tasks
@mrossinek mrossinek self-assigned this May 10, 2021
@mrossinek mrossinek added the type: documentation Issues related to documentation label May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Issues related to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants