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

Add support for ruff and pylint #78

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8309251
fix: Update conftest.py to satisfy ruff
andrijapau Dec 23, 2024
f1dea01
fix: Update test_api_client.py to satisfy ruff
andrijapau Dec 23, 2024
78e08ad
fix: Update test_device.py with simple ruff fixes
andrijapau Dec 23, 2024
263a63a
fix: Update test_device.py with unsafe fixes
andrijapau Dec 23, 2024
2280137
fix: Update test_device.py with manual fixes
andrijapau Dec 23, 2024
1f42e28
fix: Update source code with ruff --fix
andrijapau Dec 23, 2024
7c2f06b
feat: Improve Makefile to add clean-up of ruff_cache
andrijapau Dec 23, 2024
694b4ef
fix: Clean up source code with ruff check --fix
andrijapau Dec 23, 2024
972f37a
fix: Clean-up source code with unsafe fixes
andrijapau Dec 23, 2024
86d4333
fix: Manually make ruff happy
andrijapau Dec 23, 2024
9c97bed
fix: Update source code for documentation ruff complaints
andrijapau Dec 23, 2024
6df182b
fix: Source code now passes all of ruff
andrijapau Dec 23, 2024
107dba3
clean-up tests for pylint
andrijapau Dec 24, 2024
eb8a92e
fix init file with isort
andrijapau Dec 24, 2024
d440693
fix up code with isort
andrijapau Dec 24, 2024
ee143c1
update workflow actions
andrijapau Dec 24, 2024
1eb6667
update pylintrc
andrijapau Dec 24, 2024
dec4e28
add ruff toml files
andrijapau Dec 24, 2024
b680cf6
update requirements
andrijapau Dec 24, 2024
057668f
update makefile to remove top level __pycache__
andrijapau Dec 24, 2024
919d702
fix typo in makefile
andrijapau Dec 24, 2024
a5d3954
add no coverage to line
andrijapau Dec 24, 2024
bec8f3f
add import-error disable
andrijapau Dec 24, 2024
c6122f7
add pylint disable to ops.py
andrijapau Dec 24, 2024
d22ee06
doc: add changelog entry
andrijapau Dec 24, 2024
cf9184a
add pre-commit / test it :)
andrijapau Dec 24, 2024
3aa661c
add tach.toml
andrijapau Dec 24, 2024
8e933b4
add new line character to requirements*.txt
andrijapau Dec 24, 2024
3fda6f9
adjust spacing on format.yml
andrijapau Dec 24, 2024
50573f1
remove hyphen from uses in format.yml
andrijapau Dec 24, 2024
353056b
run black on tests
andrijapau Dec 24, 2024
d126cb7
add PR template
andrijapau Dec 24, 2024
e1dee6f
update readme
andrijapau Dec 24, 2024
fdd6bc0
fix readme typo
andrijapau Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to the
test directory!

- [ ] All new functions and code must be clearly commented and documented.
If you do make documentation changes, make sure that the docs build and
render correctly by running `make docs`.

- [ ] Ensure that the test suite passes, by running `make test`.

- [ ] Add a new entry to the `CHANGELOG.md` file, summarizing the
change, and including a link back to the PR.

- [ ] The PennyLane source code conforms to
[PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
To lint modified files, simply `pip install pylint`, and then
run `pylint pennylane/path/to/file.py`.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.

------------------------------------------------------------------------------------------------------------

**Context:**

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
25 changes: 20 additions & 5 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,26 @@ on:
- pull_request

jobs:
black:
formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Black Code Formatter
uses: lgeiger/black-action@v1.0.1
- name: Check-out code
uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@v5
with:
args: "-l 100 pennylane_aqt/ --check"
python-version: "3.10"

- name: Install dependencies
run: pip install black pylint isort

- name: Run Black
run: |
black -t py310 -t py311 -t py312 -l 100 pennylane_aqt/ --check
black -t py310 -t py311 -t py312 -l 100 tests/ --check

- name: Run isort
run: |
isort --py 312 --profile black -l 100 -o autoray -p ./pennylane --skip __init__.py --filter-files ./pennylane_aqt --check
isort --py 312 --profile black -l 100 -o autoray -p ./pennylane --skip __init__.py --filter-files ./tests --check
33 changes: 33 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Linting check
on:
- pull_request

jobs:
linting:
runs-on: ubuntu-latest
steps:
- name: Check-out code
uses: actions/checkout@v1

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff pylint

- name: Ruff Linter (source-code)
run: ruff check pennylane_aqt/ --preview

- name: Ruff Linter (test-suite)
run: ruff check tests/ --preview

- name: Pylint Linter (source-code)
run: pylint --rcfile .pylintrc pennylane_aqt/

- name: Pylint Linter (test-suite)
run: pylint --rcfile tests/.pylintrc tests/

64 changes: 64 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
repos:
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
args: [
"--line-length=100",
"-t", "py39",
"-t", "py310",
"-t", "py311",
]
exclude: ^doc/
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args:
[
"--py",
"311",
"--profile",
"black",
"-l",
"100",
"-o",
"autoray",
"-p",
"./pennylane_aqt",
"--skip",
"__init__.py",
"--filter-files",
]
files: ^(pennylane_aqt/|tests/)
- repo: https://github.com/gauge-sh/tach-pre-commit
rev: v0.19.1
hooks:
- id: tach
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=.pylintrc", # Link to your config file
]
exclude: ^(doc/|tests/)
- id: pylint-test
name: pylint-test
entry: pylint
language: system
types: [python]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=tests/.pylintrc", # Link to your config file
]
files: ^(tests/)

2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ ignored-classes=numpy,scipy,autograd
# can either give multiple identifiers separated by comma (,) or put this option
# multiple times (only on the command line, not in the configuration file where
# it should appear only once).
disable=line-too-long,invalid-name,too-many-lines,redefined-builtin,too-many-locals,duplicate-code,bad-continuation
disable=invalid-name,too-many-locals,duplicate-code,import-error
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Improvements 🛠

* Add support for `ruff` and `pylint`.
[(#78)](https://github.com/PennyLaneAI/pennylane-aqt/pull/78)

### Breaking changes 💔

* The ``qml.QubitStateVector`` template has been removed. Instead, use :class:`~pennylane.StatePrep`.
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ dist:

.PHONY : clean
clean:
rm -rf pennylane-aqt/__pycache__
rm -rf __pycache__
rm -rf pennylane_aqt/__pycache__
rm -rf tests/__pycache__
rm -rf dist
rm -rf build
rm -rf .pytest_cache
rm -rf .coverage coverage_html_report/
rm -rf .ruff_cache
rm -rf tests/.ruff_cache

docs:
make -C doc html
Expand Down
32 changes: 30 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,13 @@ Alternatively, you can install PennyLane-AQT from the source code by navigating
Software tests
~~~~~~~~~~~~~~

To ensure that PennyLane-AQT is working correctly after installation, the test suite can be
run by navigating to the source code folder and running
To ensure that PennyLane-AQT is working correctly after installation, the test suite should be
run. Begin by installing the required packages via ``pip``
::

$ pip install -r requirements-ci.txt

Then navigate to the source code folder and run
::

$ make test
Expand Down Expand Up @@ -129,6 +134,29 @@ All contributers to PennyLane-AQT will be listed as contributors on the releases
We also encourage bug reports, suggestions for new features and enhancements, and even links to cool
projects or applications built on PennyLane and AQT.

The PennyLane-AQT repository provide a top-level file (``.pre-commit-config.yaml``)
for configuring `pre-commit <https://pre-commit.com/>`_ to run ``black``, ``isort`` and ``pylint`` as a ``git``
pre-commit hook. Once configured, issuing ``git commit`` will run the tools
automatically. If any of the checks fail, committing fails too. A failed
``black`` check will reformat the required files. Running the pre-commit hook
mechanisms can be disabled for a commit by passing the ``-n/--no-verify``
option.

The ``pre-commit`` package can be installed e.g., via ``pip``:

.. code-block:: bash

pip install pre-commit

Then, it can be installed for a specific repository by running

.. code-block:: bash

pre-commit install

in the folder where the ``.pre-commit-config.yaml`` file exists (the top-level
folder for PennyLane-AQT).


Contributors
============
Expand Down
10 changes: 5 additions & 5 deletions pennylane_aqt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This is the top level module from which all PennyLane-AQT device classes can be directly imported.
"""
from .simulator import AQTSimulatorDevice, AQTNoisySimulatorDevice
from ._version import __version__
"""Top level module from which all PennyLane-AQT device classes can be directly imported."""
from . import ops
from ._version import __version__
from .simulator import AQTNoisySimulatorDevice, AQTSimulatorDevice

__all__ = ["AQTNoisySimulatorDevice", "AQTSimulatorDevice", "__version__", "ops"]
6 changes: 2 additions & 4 deletions pennylane_aqt/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Version information."""

"""Version information.
Version number (major.minor.patch[-label])
"""

# Format: (major.minor.patch[-label]).
__version__ = "0.40.0-dev"
20 changes: 10 additions & 10 deletions pennylane_aqt/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
API Client
# ruff: noqa: D205
"""API Client.
==========

**Module name:** :mod:`pennylane_aqt.api_client`
Expand All @@ -32,7 +32,6 @@
~~~~~~~~~~~~
"""

import urllib
import requests

SUPPORTED_HTTP_REQUESTS = ["PUT", "POST"]
Expand All @@ -41,18 +40,14 @@


def verify_valid_status(response):
"""
Check a HTTP response for valid status codes, and raise an exception if
the code is invalid
"""Check a HTTP response for valid status codes, and raise an exception if the code is invalid.

Args:
response[requests.model.Response]: the response containing the error

Returns:
bool: whether the response has an acceptable HTTP status code
response (requests.model.Response): the response containing the error

Raises:
requests.HTTPError: if the status is not valid

"""
if response.status_code not in VALID_STATUS_CODES:
raise requests.HTTPError(response, response.text)
Expand All @@ -67,12 +62,17 @@ def submit(request_type, url, request, headers):
request (str): JSON-formatted payload
headers (dict): HTTP request header

Raises:
ValueError: if invalid HTTP request was provided

Returns:
requests.models.Response: the response from the API

"""
if request_type not in SUPPORTED_HTTP_REQUESTS:
raise ValueError("""Invalid HTTP request method provided. Options are "PUT" or "POST".""")
if request_type == "PUT":
return requests.put(url, request, headers=headers, timeout=DEFAULT_TIMEOUT)
if request_type == "POST":
return requests.post(url, request, headers=headers, timeout=DEFAULT_TIMEOUT)
return None # pragma: no cover
Loading
Loading