unitaryfund / mitiq

Mitiq is an open source toolkit for implementing error mitigation techniques on most current intermediate-scale quantum computers.
https://mitiq.readthedocs.io
GNU General Public License v3.0
358 stars 157 forks source link

Error when running type checks #2033

Closed purva-thakre closed 11 months ago

purva-thakre commented 11 months ago

Issue Description

If type checks are done locally, the following errors are raised.

mitiq/observable/observable.py:185: error: "defaultdict" is not subscriptable, use "typing.DefaultDict" instead  [misc]
mitiq/interface/conversions.py:350: error: Item "Circuit" of "Union[Circuit, Program, Any, Any, Any]" has no attribute "qregs"  [union-attr]
mitiq/interface/conversions.py:350: error: Item "Program" of "Union[Circuit, Program, Any, Any, Any]" has no attribute "qregs"  [union-attr]
mitiq/interface/conversions.py:352: error: Item "Circuit" of "Union[Circuit, Program, Any, Any, Any]" has no attribute "cregs"  [union-attr]
mitiq/interface/conversions.py:352: error: Item "Program" of "Union[Circuit, Program, Any, Any, Any]" has no attribute "cregs"  [union-attr]
mitiq/interface/conversions.py:353: error: Item "Circuit" of "Union[Circuit, Program, Any, Any, Any]" has no attribute "cregs"  [union-attr]
mitiq/interface/conversions.py:353: error: Item "Program" of "Union[Circuit, Program, Any, Any, Any]" has no attribute "cregs"  [union-attr]

How to Reproduce

cd mitiq

make check-types
natestemen commented 11 months ago

Can you post the output of these commands:

mypy --version
pip list
python --version
purva-thakre commented 11 months ago

@natestemen Looks like my version of mypy is not what's in devrequirements.txt.

Will upgrade to a newer version and check if I get the same errors.

purva-thakre commented 11 months ago

I did not know check-types, check-style and check-format are run for Python 3.11 only.

https://github.com/unitaryfund/mitiq/blob/master/.github/workflows/build.yml#L26

My local environment was using Python 3.8.10 which still led to one error after installing the requirements as specified in devrequirements.txt.

mypy mitiq --show-error-codes
mitiq/observable/observable.py:185: error: "defaultdict" is not subscriptable, use "typing.DefaultDict" instead  [misc]

I propose we close this issue but add details about the checks being restricted to Python 3.11 in #2029 or we could instead change the Contributing guidelines to have a Python 3.11 environment.

natestemen commented 11 months ago

We will be dropping support for python 3.8 soon, and I believe these errors do not occur with python 3.9.

purva-thakre commented 11 months ago

Closing this issue as the errors are due to an older Python environment.