QCHackers / tqec

Design automation software tools for Topological Quantum Error Correction
https://qchackers.github.io/tqec/
Apache License 2.0
69 stars 18 forks source link

Re-export correctly in `__init__.py` #164

Closed nelimee closed 8 months ago

nelimee commented 8 months ago

Describe the bug

The current __init__.py files in the repository only import symbols, but do not re-export them per Python standards.

All the imports, in all the __init__.py files are currently raising a F401 error when linted.

Steps to reproduce the behavior:

Run a linter on the code base. Using ruff with

python -m ruff check .

outputs

src/tqec/__init__.py:2:5: F401 `.circuit` imported but unused; consider adding to `__all__` or using a redundant alias
src/tqec/__init__.py:3:5: F401 `.noise_models` imported but unused; consider adding to `__all__` or using a redundant alias
# [a lot more lines]
src/tqec/templates/constructions/__init__.py:3:5: F401 `.qubit.QubitRectangleTemplate` imported but unused; consider adding to `__all__` or using a redundant alias
src/tqec/templates/constructions/__init__.py:4:5: F401 `.qubit.QubitSquareTemplate` imported but unused; consider adding to `__all__` or using a redundant alias
Found 99 errors.

Expected behavior

No linter error.

How to fix

The ruff linter has two options:

  1. include the symbols that are meant to be re-exported in the __all__ special variable.
  2. use the import X as X format to explicitly mark the symbol X as re-exported.

I spent some time to search for the rationale behind F401 and found this comment.

I will add a third option:

  1. disable the F401 warning for this specific case.

As we already ruled out the __all__ approach in a previous PR, I guess we are left with 2 or 3.

Python dependency versions (please complete for backend bugs)

Run pip freeze and put the output in the <details> element below.

alabaster==0.7.16 anyio==4.0.0 argon2-cffi==23.1.0 argon2-cffi-bindings==21.2.0 arrow==1.3.0 asttokens==2.4.1 async-lru==2.0.4 attrs==23.2.0 Babel==2.13.1 beautifulsoup4==4.12.2 bleach==6.1.0 blinker==1.7.0 cachetools==5.3.2 certifi==2023.7.22 cffi==1.16.0 charset-normalizer==3.3.2 cirq==1.3.0 cirq-aqt==1.3.0 cirq-core==1.3.0 cirq-ft==1.3.0 cirq-google==1.3.0 cirq-ionq==1.3.0 cirq-pasqal==1.3.0 cirq-rigetti==1.3.0 cirq-web==1.3.0 click==8.1.7 comm==0.2.0 contourpy==1.2.0 coverage==7.4.1 cycler==0.12.1 debugpy==1.8.0 decorator==5.1.1 defusedxml==0.7.1 Deprecated==1.2.14 docutils==0.20.1 duet==0.2.9 executing==2.0.1 fastjsonschema==2.19.0 Flask==3.0.0 Flask-Cors==3.0.10 fonttools==4.46.0 fqdn==1.5.1 google-api-core==2.15.0 google-auth==2.25.1 googleapis-common-protos==1.62.0 grandalf==0.8 graphviz==0.20.1 grpcio==1.60.0 grpcio-status==1.60.0 h11==0.14.0 httpcore==0.16.3 httpx==0.23.3 idna==3.4 imagesize==1.4.1 iniconfig==2.0.0 ipykernel==6.26.0 ipython==8.17.2 ipywidgets==8.1.1 iso8601==1.1.0 isoduration==20.11.0 itsdangerous==2.1.2 jedi==0.19.1 Jinja2==3.1.2 json5==0.9.14 jsonpointer==2.4 jsonschema==4.21.0 jsonschema-specifications==2023.11.1 jupyter==1.0.0 jupyter-console==6.6.3 jupyter-events==0.9.0 jupyter-lsp==2.2.0 jupyter_client==8.6.0 jupyter_core==5.5.0 jupyter_server==2.10.1 jupyter_server_terminals==0.4.4 jupyterlab==4.0.8 jupyterlab-pygments==0.2.2 jupyterlab-widgets==3.0.9 jupyterlab_server==2.25.1 kiwisolver==1.4.5 lark==0.11.3 markdown-it-py==3.0.0 MarkupSafe==2.1.3 matplotlib==3.8.2 matplotlib-inline==0.1.6 mdit-py-plugins==0.4.0 mdurl==0.1.2 mistune==3.0.2 mpmath==1.3.0 msgpack==1.0.7 mypy==1.8.0 mypy-extensions==1.0.0 myst-parser==2.0.0 nbclient==0.9.0 nbconvert==7.11.0 nbformat==5.9.2 nest-asyncio==1.5.8 netgraph==4.13.2 networkx==3.2.1 notebook==7.0.6 notebook_shim==0.2.3 numpy==1.26.1 ordered-set==4.1.0 overrides==7.4.0 packaging==23.2 pandas==2.1.3 pandocfilters==1.5.0 parso==0.8.3 pexpect==4.8.0 Pillow==10.1.0 platformdirs==4.0.0 pluggy==1.3.0 prometheus-client==0.18.0 prompt-toolkit==3.0.41 proto-plus==1.23.0 protobuf==4.25.1 psutil==5.9.6 ptyprocess==0.7.0 pure-eval==0.2.2 pyasn1==0.5.1 pyasn1-modules==0.3.0 pycparser==2.21 pydantic==1.10.13 Pygments==2.16.1 PyJWT==2.8.0 PyLaTeX==1.4.2 PyMatching==2.1.0 pyparsing==3.1.1 pyquil==3.5.4 pyrsistent==0.20.0 pytest==7.4.4 pytest-cov==4.1.0 python-dateutil==2.8.2 python-json-logger==2.0.7 python-rapidjson==1.13 pytz==2023.3.post1 PyYAML==6.0.1 pyzmq==25.1.1 qcs-api-client==0.21.6 qtconsole==5.5.1 QtPy==2.4.1 rectangle-packer==2.0.2 referencing==0.31.0 requests==2.31.0 retrying==1.3.4 retworkx==0.13.2 rfc3339==6.2 rfc3339-validator==0.1.4 rfc3986==1.5.0 rfc3986-validator==0.1.1 rpcq==3.11.0 rpds-py==0.13.0 rsa==4.9 ruamel.yaml==0.18.5 ruamel.yaml.clib==0.2.8 ruff==0.2.2 rustworkx==0.13.2 scipy==1.11.4 Send2Trash==1.8.2 setuptools==68.0.0 sinter==1.12.1 six==1.16.0 sniffio==1.3.0 snowballstemmer==2.2.0 sortedcontainers==2.4.0 soupsieve==2.5 Sphinx==7.2.6 sphinxcontrib-applehelp==1.0.8 sphinxcontrib-devhelp==1.0.6 sphinxcontrib-htmlhelp==2.0.5 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.7 sphinxcontrib-serializinghtml==1.1.10 stack-data==0.6.3 stim==1.12.1 stimcirq==1.12.1 sympy==1.12 tenacity==8.2.3 terminado==0.18.0 tinycss2==1.2.1 toml==0.10.2 tornado==6.3.3 tqdm==4.66.1 -e git+https://github.com/nelimee/tqec.git@b7994930f37aa28a8afe651a3bee06787337346d#egg=tqec traitlets==5.13.0 types-Deprecated==1.2.9.3 types-python-dateutil==2.8.19.14 types-retry==0.9.9.4 typing_extensions==4.8.0 tzdata==2023.3 uri-template==1.3.0 urllib3==2.1.0 wcwidth==0.2.10 webcolors==1.13 webencodings==0.5.1 websocket-client==1.6.4 Werkzeug==3.0.1 wheel==0.37.1 widgetsnbextension==4.0.9 wrapt==1.16.0
inmzhang commented 8 months ago
  1. disable the F401 warning for this specific case.

If we only use __init__.py for re-exporting, then I prefer disabling F401.