From 1dae57c2ebe38793be929aa4e5c73d3ab1243b0f Mon Sep 17 00:00:00 2001 From: Vincent Michaud-Rioux Date: Thu, 21 Mar 2024 16:25:19 -0400 Subject: [PATCH] Fix isort config (#647) * Fix isort pyver and length * Auto update version * Update changelog. * Use isort GHA. * Specify -p pennylane_lightning * Use black GHA * isort --check --diff * Revert test change. * sort fields. * Update .github/workflows/format.yml Co-authored-by: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> * Update .github/workflows/format.yml Co-authored-by: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> * Auto update version * trigger ci * trigger ci * Use format-python in format.yml. * Auto update version * trigger ci --------- Co-authored-by: Dev version update bot Co-authored-by: Rashid N H M <95639609+rashidnhm@users.noreply.github.com> --- .github/CHANGELOG.md | 3 +++ .github/workflows/format.yml | 9 +++------ Makefile | 8 +++++--- pennylane_lightning/core/_version.py | 2 +- pennylane_lightning/lightning_gpu/lightning_gpu.py | 11 ++++------- .../lightning_kokkos/lightning_kokkos.py | 11 ++++------- pennylane_lightning/lightning_qubit/_measurements.py | 5 +---- tests/lightning_qubit/test_adjoint_jacobian_class.py | 4 +--- tests/lightning_qubit/test_measurements_class.py | 5 +---- tests/test_serialize.py | 5 +---- 10 files changed, 24 insertions(+), 39 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 076481918..7fd030a55 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -41,6 +41,9 @@ ### Bug fixes +* Specify `isort` `--py` (Python version) and `-l` (max line length) to stabilize `isort` across Python versions and environments. + [(#647)](https://github.com/PennyLaneAI/pennylane-lightning/pull/647) + * Fix random `coverage xml` CI issues. [(#635)](https://github.com/PennyLaneAI/pennylane-lightning/pull/635) diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml index 91e4143c2..bb42e3eb4 100644 --- a/.github/workflows/format.yml +++ b/.github/workflows/format.yml @@ -26,11 +26,8 @@ jobs: - name: Checkout PennyLane-Lightning uses: actions/checkout@v3 - - name: Run isort - run: python -m isort --profile black ./pennylane_lightning/ ./mpitests ./tests --check --diff - - - name: Run Black - run: python -m black -l 100 pennylane_lightning/ tests/ --check --verbose + - name: Run isort & black --check + run: make format-python check=1 verbose=1 format-cpp: name: Format (C++) @@ -62,7 +59,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.9' + python-version: '3.11' - name: Install dependencies run: sudo apt update && sudo apt -y install cmake gcc-11 g++-11 ninja-build libomp-14-dev && python -m pip install -r requirements-dev.txt diff --git a/Makefile b/Makefile index 24148a59a..3d40597db 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,11 @@ TESTRUNNER := -m pytest tests --tb=short PL_BACKEND ?= "$(if $(backend:-=),$(backend),lightning_qubit)" ifdef check - CHECK := --check + CHECK := --check --diff + ICHECK := --check else CHECK := + ICHECK := endif ifdef build_options @@ -113,8 +115,8 @@ format-cpp: ./bin/format $(CHECK) ./pennylane_lightning format-python: - isort --profile black ./pennylane_lightning/ ./mpitests ./tests $(CHECK) - black -l 100 ./pennylane_lightning/ ./mpitests ./tests $(CHECK) + isort --py 311 --profile black -l 100 -p pennylane_lightning ./pennylane_lightning/ ./mpitests ./tests $(ICHECK) $(VERBOSE) + black -l 100 ./pennylane_lightning/ ./mpitests ./tests $(CHECK) $(VERBOSE) .PHONY: check-tidy check-tidy: diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 070aab6b4..134b71b54 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.36.0-dev14" +__version__ = "0.36.0-dev15" diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.py b/pennylane_lightning/lightning_gpu/lightning_gpu.py index cbc4a4834..66047852a 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.py +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.py @@ -91,6 +91,10 @@ from pennylane.ops.op_math import Adjoint from pennylane.wires import Wires + # pylint: disable=import-error, no-name-in-module, ungrouped-imports + from pennylane_lightning.core._serialize import QuantumScriptSerializer, global_phase_diagonal + from pennylane_lightning.core._version import __version__ + # pylint: disable=no-name-in-module, ungrouped-imports from pennylane_lightning.lightning_gpu_ops.algorithms import ( AdjointJacobianC64, @@ -99,13 +103,6 @@ create_ops_listC128, ) - # pylint: disable=import-error, no-name-in-module, ungrouped-imports - from pennylane_lightning.core._serialize import ( - QuantumScriptSerializer, - global_phase_diagonal, - ) - from pennylane_lightning.core._version import __version__ - if MPI_SUPPORT: from pennylane_lightning.lightning_gpu_ops.algorithmsMPI import ( AdjointJacobianMPIC64, diff --git a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py index d7821660b..c15c3583a 100644 --- a/pennylane_lightning/lightning_kokkos/lightning_kokkos.py +++ b/pennylane_lightning/lightning_kokkos/lightning_kokkos.py @@ -64,6 +64,10 @@ from pennylane.ops.op_math import Adjoint from pennylane.wires import Wires + # pylint: disable=import-error, no-name-in-module, ungrouped-imports + from pennylane_lightning.core._serialize import QuantumScriptSerializer, global_phase_diagonal + from pennylane_lightning.core._version import __version__ + # pylint: disable=import-error, no-name-in-module, ungrouped-imports from pennylane_lightning.lightning_kokkos_ops.algorithms import ( AdjointJacobianC64, @@ -72,13 +76,6 @@ create_ops_listC128, ) - # pylint: disable=import-error, no-name-in-module, ungrouped-imports - from pennylane_lightning.core._serialize import ( - QuantumScriptSerializer, - global_phase_diagonal, - ) - from pennylane_lightning.core._version import __version__ - def _kokkos_dtype(dtype): if dtype not in [np.complex128, np.complex64]: # pragma: no cover raise ValueError(f"Data type is not supported for state-vector computation: {dtype}") diff --git a/pennylane_lightning/lightning_qubit/_measurements.py b/pennylane_lightning/lightning_qubit/_measurements.py index e26e8fcee..93df57fcb 100644 --- a/pennylane_lightning/lightning_qubit/_measurements.py +++ b/pennylane_lightning/lightning_qubit/_measurements.py @@ -17,10 +17,7 @@ # pylint: disable=import-error, no-name-in-module, ungrouped-imports try: - from pennylane_lightning.lightning_qubit_ops import ( - MeasurementsC64, - MeasurementsC128, - ) + from pennylane_lightning.lightning_qubit_ops import MeasurementsC64, MeasurementsC128 except ImportError: pass diff --git a/tests/lightning_qubit/test_adjoint_jacobian_class.py b/tests/lightning_qubit/test_adjoint_jacobian_class.py index 9b1dd435a..5450364b3 100644 --- a/tests/lightning_qubit/test_adjoint_jacobian_class.py +++ b/tests/lightning_qubit/test_adjoint_jacobian_class.py @@ -23,9 +23,7 @@ from pennylane.tape import QuantumScript from scipy.stats import unitary_group -from pennylane_lightning.lightning_qubit._adjoint_jacobian import ( - LightningAdjointJacobian, -) +from pennylane_lightning.lightning_qubit._adjoint_jacobian import LightningAdjointJacobian from pennylane_lightning.lightning_qubit._state_vector import LightningStateVector if not LightningDevice._new_API: diff --git a/tests/lightning_qubit/test_measurements_class.py b/tests/lightning_qubit/test_measurements_class.py index 1f0337cd6..41e5be61e 100644 --- a/tests/lightning_qubit/test_measurements_class.py +++ b/tests/lightning_qubit/test_measurements_class.py @@ -26,10 +26,7 @@ from scipy.sparse import csr_matrix, random_array try: - from pennylane_lightning.lightning_qubit_ops import ( - MeasurementsC64, - MeasurementsC128, - ) + from pennylane_lightning.lightning_qubit_ops import MeasurementsC64, MeasurementsC128 except ImportError: pass diff --git a/tests/test_serialize.py b/tests/test_serialize.py index 1f726a55e..b56ac4ade 100644 --- a/tests/test_serialize.py +++ b/tests/test_serialize.py @@ -19,10 +19,7 @@ import pytest from conftest import LightningDevice, device_name -from pennylane_lightning.core._serialize import ( - QuantumScriptSerializer, - global_phase_diagonal, -) +from pennylane_lightning.core._serialize import QuantumScriptSerializer, global_phase_diagonal if not LightningDevice._CPP_BINARY_AVAILABLE: pytest.skip("No binary module found. Skipping.", allow_module_level=True)