diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 076481918b..7fd030a55d 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 91e4143c2b..bb42e3eb47 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 24148a59ae..3d40597db9 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 070aab6b47..134b71b540 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 cbc4a48340..66047852a7 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 d7821660bf..c15c3583a9 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 e26e8fceec..93df57fcbd 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 9b1dd435a8..5450364b32 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 1f0337cd6e..41e5be61e4 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 1f726a55ef..b56ac4ade7 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)