Skip to content

Commit

Permalink
Fix isort config (#647)
Browse files Browse the repository at this point in the history
* 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 <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rashid N H M <95639609+rashidnhm@users.noreply.github.com>
  • Loading branch information
3 people committed Mar 21, 2024
1 parent c82198b commit 1dae57c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.36.0-dev14"
__version__ = "0.36.0-dev15"
11 changes: 4 additions & 7 deletions pennylane_lightning/lightning_gpu/lightning_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions pennylane_lightning/lightning_kokkos/lightning_kokkos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}")
Expand Down
5 changes: 1 addition & 4 deletions pennylane_lightning/lightning_qubit/_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions tests/lightning_qubit/test_adjoint_jacobian_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions tests/lightning_qubit/test_measurements_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1dae57c

Please sign in to comment.