Skip to content

Commit 8796bab

Browse files
Uniform Python format to adhere PL style; Always decompose qml.QFT in Lightning (#924)
### 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 [`tests`](../tests) 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 `.github/CHANGELOG.md` file, summarizing the change, and including a link back to the PR. - [ ] Ensure that code is properly formatted by running `make format`. 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:** [sc-74415] --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent 1c1f36e commit 8796bab

22 files changed

+38
-88
lines changed

.github/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434

3535
### Improvements
3636

37+
* Always decompose `qml.QFT` in Lightning.
38+
[(#924)](https://github.com/PennyLaneAI/pennylane-lightning/pull/924)
39+
40+
* Uniform Python format to adhere PennyLane style.
41+
[(#924)](https://github.com/PennyLaneAI/pennylane-lightning/pull/924)
42+
3743
* Remove dynamic decomposition rules in Lightning.
3844
[(#926)](https://github.com/PennyLaneAI/pennylane-lightning/pull/926)
3945

.github/workflows/format.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:
20-
python-version: '3.11'
20+
python-version: '3.12'
2121

2222
- name: Checkout PennyLane-Lightning
2323
uses: actions/checkout@v4
2424

2525
- name: Install dependencies
2626
run:
27-
python -m pip install -r requirements-dev.txt
27+
python -m pip install -r requirements.txt
2828

2929
- name: Run isort & black --check
3030
run: make format-python check=1 verbose=1
@@ -38,7 +38,7 @@ jobs:
3838
uses: actions/checkout@v4
3939

4040
- name: Install dependencies
41-
run: sudo apt update && sudo apt -y install python3 python3-pip python-is-python3 && python -m pip install -r requirements-dev.txt
41+
run: sudo apt update && sudo apt -y install python3 python3-pip python-is-python3 && python -m pip install -r requirements.txt
4242

4343
- name: Run formatter
4444
run: PATH=$PATH:/home/ubuntu/.local/bin/:$(dirname $(which python3))/ ./bin/format --check ./pennylane_lightning/core/src

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ format-cpp:
131131
./bin/format $(CHECK) ./pennylane_lightning
132132

133133
format-python:
134-
isort --py 311 --profile black -l 100 -p pennylane_lightning ./pennylane_lightning ./mpitests ./tests ./scripts $(ICHECK) $(VERBOSE)
135-
black -l 100 ./pennylane_lightning ./mpitests ./tests ./scripts $(CHECK) $(VERBOSE)
134+
isort --py 312 --profile black -l 100 -p pennylane_lightning ./pennylane_lightning ./mpitests ./tests ./scripts $(ICHECK) $(VERBOSE)
135+
black -t py310 -t py311 -t py312 -l 100 ./pennylane_lightning ./mpitests ./tests ./scripts $(CHECK) $(VERBOSE)
136136

137137
.PHONY: check-tidy
138138
check-tidy:

pennylane_lightning/core/_state_vector_base.py

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class LightningBaseStateVector(ABC):
3838
"""
3939

4040
def __init__(self, num_wires: int, dtype: Union[np.complex128, np.complex64]):
41-
4241
if dtype not in [np.complex64, np.complex128]:
4342
raise TypeError(f"Unsupported complex type: {dtype}")
4443

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.39.0-dev33"
19+
__version__ = "0.39.0-dev34"

pennylane_lightning/lightning_gpu/lightning_gpu.py

-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def _mebibytesToBytes(mebibytes):
172172
"QubitCarry",
173173
"QubitSum",
174174
"OrbitalRotation",
175-
"QFT",
176175
"ECR",
177176
"BlockEncode",
178177
"C(BlockEncode)",

pennylane_lightning/lightning_gpu/lightning_gpu.toml

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ GlobalPhase = { properties = [ "differentiable" ] }
5050
[operators.gates.decomp]
5151

5252
BasisState = {}
53-
QFT = {}
5453
QubitStateVector = {}
5554
StatePrep = {}
5655
MultiControlledX = {}

pennylane_lightning/lightning_kokkos/_measurements.py

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def __init__(
4646
self,
4747
kokkos_state,
4848
) -> None:
49-
5049
super().__init__(kokkos_state)
5150

5251
self._measurement_lightning = self._measurement_dtype()(kokkos_state.state_vector)

pennylane_lightning/lightning_kokkos/_state_vector.py

-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ def __init__(
6464
kokkos_args=None,
6565
sync=True,
6666
): # pylint: disable=too-many-arguments
67-
6867
super().__init__(num_wires, dtype)
6968

7069
self._device_name = "lightning.kokkos"
@@ -280,7 +279,6 @@ def _apply_lightning(
280279
elif isinstance(operation, qml.ops.Controlled) and isinstance(
281280
operation.base, qml.GlobalPhase
282281
): # apply n-controlled gate
283-
284282
# Kokkos do not support the controlled gates except for GlobalPhase
285283
self._apply_lightning_controlled(operation)
286284
else: # apply gate as a matrix

pennylane_lightning/lightning_kokkos/lightning_kokkos.py

-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"QubitCarry",
121121
"QubitSum",
122122
"OrbitalRotation",
123-
"QFT",
124123
"ECR",
125124
"BlockEncode",
126125
"C(BlockEncode)",

pennylane_lightning/lightning_kokkos/lightning_kokkos.toml

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ T = { properties = [ "invertible", "differe
5050

5151
BasisState = {}
5252
MultiControlledX = {}
53-
QFT = {}
5453
QubitStateVector = {}
5554
StatePrep = {}
5655
ControlledQubitUnitary = {}

pennylane_lightning/lightning_qubit/_measurements.py

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def __init__(
5858
kernel_name: str = None,
5959
num_burnin: int = None,
6060
) -> None:
61-
6261
super().__init__(qubit_state)
6362

6463
self._mcmc = mcmc

pennylane_lightning/lightning_qubit/_state_vector.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class LightningStateVector(LightningBaseStateVector): # pylint: disable=too-few
5151
"""
5252

5353
def __init__(self, num_wires, dtype=np.complex128):
54-
5554
super().__init__(num_wires, dtype)
5655

5756
self._device_name = "lightning.qubit"

pennylane_lightning/lightning_qubit/lightning_qubit.py

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
"QubitCarry",
140140
"QubitSum",
141141
"OrbitalRotation",
142-
"QFT",
143142
"ECR",
144143
"BlockEncode",
145144
"C(BlockEncode)",

pennylane_lightning/lightning_qubit/lightning_qubit.toml

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ T = { properties = [ "invertible", "controllable", "differe
4747
# default, but can be useful to express a deviation from this device's regular
4848
# strategy in PennyLane.
4949
MultiControlledX = {}
50-
QFT = {}
5150

5251
# Gates which should be translated to QubitUnitary
5352
[operators.gates.matrix]

pennylane_lightning/lightning_tensor/lightning_tensor.py

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@
140140
"QubitCarry",
141141
"QubitSum",
142142
"OrbitalRotation",
143-
"QFT",
144143
"ECR",
145144
"BlockEncode",
146145
"C(BlockEncode)",

requirements-dev.txt

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
git+https://github.com/PennyLaneAI/pennylane.git@master
21
build
32
ninja
4-
flaky
53
pybind11
6-
pytest~=8.0.0
4+
pre-commit>=2.19.0
5+
pytest>=7.1.2
76
pytest-benchmark
8-
pytest-cov
9-
pytest-mock
7+
pytest-cov>=3.0.0
8+
pytest-mock>=3.7.0
9+
pytest-xdist>=2.5.0
1010
pytest-split
11-
pytest-xdist
12-
pre-commit>=2.19.0
13-
black==24.3.0
11+
flaky>=3.7.0
12+
black>=21
1413
clang-tidy~=16.0
1514
clang-format~=16.0
1615
isort==5.13.2
1716
click==8.0.4
1817
cmake
1918
custatevec-cu12
2019
cutensornet-cu12
21-
pylint
22-
scipy
20+
pylint==2.7.4
21+
git+https://github.com/PennyLaneAI/pennylane.git@master

requirements-tests.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pytest~=8.0.0
1+
pytest>=7.1.2
22
pytest-benchmark
3-
pytest-cov
4-
pytest-mock
5-
pytest-xdist
6-
flaky
7-
git+https://github.com/PennyLaneAI/pennylane.git@master
3+
pytest-cov>=3.0.0
4+
pytest-mock>=3.7.0
5+
pytest-xdist>=2.5.0
6+
flaky>=3.7.0
7+
git+https://github.com/PennyLaneAI/pennylane.git@master

requirements.txt

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
ninja
2-
flaky
3-
pennylane>=0.34
42
pybind11
5-
pytest~=8.0.0
6-
pytest-cov
7-
pytest-mock
8-
scipy
9-
pytest-xdist
3+
pytest>=7.1.2
4+
pytest-cov>=3.0.0
5+
pytest-mock>=3.7.0
6+
pytest-xdist>=2.5.0
7+
flaky>=3.7.0
8+
black>=21
9+
clang-tidy~=16.0
10+
clang-format~=16.0
11+
isort==5.13.2
12+
pylint==2.7.4
13+
pennylane>=0.37

tests/lightning_qubit/test_jacobian_method.py

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def calculate_reference(tape, execute_and_derivatives=False):
5151

5252
@staticmethod
5353
def process_and_execute(statevector, tape, execute_and_derivatives=False):
54-
5554
wires = statevector.num_wires
5655
device = LightningDevice(wires)
5756
if execute_and_derivatives:

tests/test_decomposition.py

-44
This file was deleted.

tests/test_native_mcm.py

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def func(x, y):
9090
):
9191
func(*params)
9292
if device_name == "lightning.kokkos":
93-
9493
with pytest.raises(
9594
qml.DeviceError,
9695
match=r"Measurement shadow\(wires=\[0\]\) not accepted with finite shots on "

0 commit comments

Comments
 (0)