quantumlib / Cirq

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.
Apache License 2.0
4.24k stars 1.01k forks source link

Trouble with importing custom packages from `pylint.interfaces` for local CI test #6353

Closed shef4 closed 8 months ago

shef4 commented 10 months ago

Description of the issue I'm having issues trying to run some of the slow checks. I think it is because I am missing IRawChecker. Is there a way i can install this custom package or a work around?

Cirq version 1.3.0.dev

Result from running: ./check/pytest

============================= test session starts ==============================
platform linux -- Python 3.11.5, pytest-7.4.2, pluggy-1.3.0
rootdir: [/config/workspace/opensource-projects/Cirq](https://vscode-remote+code-002eatompak-002edev.vscode-resource.vscode-cdn.net/config/workspace/opensource-projects/Cirq)
configfile: pyproject.toml
plugins: anyio-4.0.0, cov-4.1.0, xdist-3.3.1
4 workers [21438 items]r                                                   
collecting 0 items [/](https://vscode-remote+code-002eatompak-002edev.vscode-resource.vscode-cdn.net/) 2 errors                                                  
==================================== ERRORS ====================================
_________ ERROR collecting dev_tools/pylint_copyright_checker_test.py __________
ImportError while importing test module '/config/workspace/opensource-projects/Cirq/dev_tools/pylint_copyright_checker_test.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
[/config/anaconda3/envs/cirq-py3/lib/python3.11/importlib/__init__.py](https://vscode-remote+code-002eatompak-002edev.vscode-resource.vscode-cdn.net/config/anaconda3/envs/cirq-py3/lib/python3.11/importlib/__init__.py):126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
dev_tools/pylint_copyright_checker_test.py:19: in <module>
    from dev_tools.pylint_copyright_checker import CopyrightChecker
dev_tools/pylint_copyright_checker.py:18: in <module>
    from pylint.interfaces import IRawChecker
E   ImportError: cannot import name 'IRawChecker' from 'pylint.interfaces' (/config/anaconda3/envs/cirq-py3/lib/python3.11/site-packages/pylint/interfaces.py)
_____________________________ ERROR collecting gw1 _____________________________
pavoljuhas commented 8 months ago

@shef4 - please make sure you setup your development environment according to https://github.com/quantumlib/Cirq/blob/main/docs/dev/development.md#setting-up-an-environment

if there is still a problem, please post a step-by-step instructions including your Python environment setup.

pavoljuhas commented 8 months ago

Also, per @NoureldinYosri comment this may be a problem with pylint installation or having a different version installed. Can you check if the following works?

$ python3 -c "from pylint.interfaces import IRawChecker"
pavoljuhas commented 8 months ago

likely related to https://github.com/quantumlib/Cirq/issues/6351

shef4 commented 8 months ago

@pavoljuhas I'm not sure if this should be in a different area but wanted to share it for newer contributors. If you have any recommendation please lmk else thanks for the help!

After installing all necessary dependencies, the rest of the development cycle steps can be completed in a Jupiter notebook. This helps streamline your work as such:

  1. Open files that need to be changed and Python notebook to test changed file behavior.
  2. Install the editable version of Cirq
  3. Import circ
  4. Reproduce the issue and see if you get the same failure before and after the file change
  5. run continuous testing and verify the change
  6. *after testing you can also make a draft PR straight from VScode
Screenshot 2024-01-03 at 2 04 47 PM
NoureldinYosri commented 8 months ago

@shef4 this looks like a nice addition to your personal blog if you have one. If you don't have one maybe you should :D

shef4 commented 8 months ago

@NoureldinYosri Thanks, means a lot! I don't have one but that sounds like the perfect place for info like this.

pavoljuhas commented 8 months ago

@shef4 - one thing to keep in mind when working with Jupyter notebooks is that code changes are not reflected in the live sessions for any code that was already imported. In such case, you'd need to restart the kernel and re-run notebook cells as needed. It is also preferable to separate one-time setup (ie, installation in editable mode, installation of all package dependencies) from a test code that would be executed over and over again.

Circling back to the original subject - do you still get the ImportError for IRawChecker after following development.md to setup your environment?

If so, please reopen this issue with more detail on how to reproduce the error. Thank you!