Skip to content

Commit 1c1f36e

Browse files
Remove magic numbers in Lightning stopping_conditions (#926)
### 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-74414] --------- Co-authored-by: ringo-but-quantum <[email protected]>
1 parent c607b6c commit 1c1f36e

File tree

8 files changed

+11
-32
lines changed

8 files changed

+11
-32
lines changed

.github/CHANGELOG.md

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

3535
### Improvements
3636

37+
* Remove dynamic decomposition rules in Lightning.
38+
[(#926)](https://github.com/PennyLaneAI/pennylane-lightning/pull/926)
39+
3740
* Add the `ci:use-gpu-runner` GitHub label to `lightning.kokkos` GPU Testing CIs.
3841
[(#916)](https://github.com/PennyLaneAI/pennylane-lightning/pull/916)
3942

README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ PennyLane-Lightning high performance simulators include the following backends:
5050
* ``lightning.gpu``: is a state-vector simulator based on the `NVIDIA cuQuantum SDK <https://developer.nvidia.com/cuquantum-sdk>`_. It notably implements a distributed state-vector simulator based on MPI.
5151
* ``lightning.kokkos``: is a state-vector simulator written with `Kokkos <https://kokkos.github.io/kokkos-core-wiki/index.html>`_. It can exploit the inherent parallelism of modern processing units supporting the `OpenMP <https://www.openmp.org/>`_, `CUDA <https://developer.nvidia.com/cuda-toolkit>`_ or `HIP <https://docs.amd.com/projects/HIP/en/docs-5.3.0/index.html>`_ programming models.
5252
* ``lightning.tensor``: is a tensor network simulator based on the `NVIDIA cuQuantum SDK <https://developer.nvidia.com/cuquantum-sdk>`_ (requires NVIDIA GPUs with SM 7.0 or greater). The supported method is Matrix Product State (MPS).
53+
5354
.. header-end-inclusion-marker-do-not-remove
5455
5556
The following table summarizes the supported platforms and the primary installation mode:

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-dev32"
19+
__version__ = "0.39.0-dev33"

pennylane_lightning/core/lightning_base.py

-4
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ def stopping_condition(self):
9494
and observable) and returns ``True`` if supported by the device."""
9595

9696
def accepts_obj(obj):
97-
if isinstance(obj, qml.QFT):
98-
return len(obj.wires) < 10
99-
if isinstance(obj, qml.GroverOperator):
100-
return len(obj.wires) < 13
10197
is_not_tape = not isinstance(obj, qml.tape.QuantumTape)
10298
is_supported = getattr(self, "supports_operation", lambda name: False)(obj.name)
10399
return is_not_tape and is_supported

pennylane_lightning/lightning_kokkos/lightning_kokkos.py

-6
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@
151151

152152
def stopping_condition(op: Operator) -> bool:
153153
"""A function that determines whether or not an operation is supported by ``lightning.kokkos``."""
154-
# To avoid building matrices beyond the given thresholds.
155-
# This should reduce runtime overheads for larger systems.
156-
if isinstance(op, qml.QFT):
157-
return len(op.wires) < 10
158-
if isinstance(op, qml.GroverOperator):
159-
return len(op.wires) < 13
160154
if isinstance(op, qml.PauliRot):
161155
word = op._hyperparameters["pauli_word"] # pylint: disable=protected-access
162156
# decomposes to IsingXX, etc. for n <= 2

pennylane_lightning/lightning_qubit/lightning_qubit.py

-7
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@
170170

171171
def stopping_condition(op: Operator) -> bool:
172172
"""A function that determines whether or not an operation is supported by ``lightning.qubit``."""
173-
# To avoid building matrices beyond the given thresholds.
174-
# This should reduce runtime overheads for larger systems.
175-
if isinstance(op, qml.QFT):
176-
return len(op.wires) < 10
177-
if isinstance(op, qml.GroverOperator):
178-
return len(op.wires) < 13
179-
180173
# As ControlledQubitUnitary == C(QubitUnitrary),
181174
# it can be removed from `_operations` to keep
182175
# consistency with `lightning_qubit.toml`

pennylane_lightning/lightning_tensor/lightning_tensor.py

-7
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,6 @@
168168

169169
def stopping_condition(op: Operator) -> bool:
170170
"""A function that determines whether or not an operation is supported by the ``mps`` method of ``lightning.tensor``."""
171-
# TODOs: These thresholds are from ``lightning.qubit`` and should be adjuested based on the benchmarking tests for the MPS
172-
# simulator (against both max_mps_bond_dim and number of qubits).
173-
if isinstance(op, qml.QFT):
174-
return len(op.wires) < 10
175-
if isinstance(op, qml.GroverOperator):
176-
return len(op.wires) < 13
177-
178171
if isinstance(op, qml.ControlledQubitUnitary):
179172
return True
180173

tests/test_templates.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def circuit():
726726
class TestQFT:
727727
"""Test the QFT algorithm."""
728728

729-
@pytest.mark.parametrize("n_qubits", range(2, 20, 2))
729+
@pytest.mark.parametrize("n_qubits", range(2, 15, 2))
730730
def test_qft(self, n_qubits):
731731
lightning_tensor_check(n_qubits)
732732
dev = qml.device(device_name, wires=n_qubits)
@@ -745,9 +745,9 @@ def circuit(basis_state):
745745
assert np.allclose(res, ref)
746746

747747
@pytest.mark.skipif(not LightningDevice._new_API, reason="New API required")
748-
@pytest.mark.parametrize("wires", [5, 9, 10, 13])
748+
@pytest.mark.parametrize("wires", [5, 13])
749749
def test_preprocess_qft_decomposition(self, wires):
750-
"""Test that qml.QFT is not decomposed for less than 10 wires."""
750+
"""Test that qml.QFT is always decomposed for any wires."""
751751
tape = qml.tape.QuantumScript(
752752
[qml.QFT(wires=list(range(wires)))], [qml.expval(qml.PauliZ(0))]
753753
)
@@ -756,10 +756,9 @@ def test_preprocess_qft_decomposition(self, wires):
756756
program, _ = dev.preprocess()
757757
[new_tape], _ = program([tape])
758758

759-
if wires >= 10:
760-
assert all(not isinstance(op, qml.QFT) for op in new_tape.operations)
761-
else:
762-
assert tape.operations == [qml.QFT(wires=list(range(wires)))]
759+
# assert all(not isinstance(op, qml.QFT) for op in new_tape.operations)
760+
# else:
761+
assert tape.operations == [qml.QFT(wires=list(range(wires)))]
763762

764763

765764
class TestAQFT:

0 commit comments

Comments
 (0)