Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove magic numbers in Lightning stopping_conditions #926

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

### Improvements

* Remove dynamic decomposition rules in Lightning.
[(#926)](https://github.com/PennyLaneAI/pennylane-lightning/pull/926)

* Add the `ci:use-gpu-runner` GitHub label to `lightning.kokkos` GPU Testing CIs.
[(#916)](https://github.com/PennyLaneAI/pennylane-lightning/pull/916)

Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ PennyLane-Lightning high performance simulators include the following backends:
* ``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.
* ``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.
* ``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).

.. header-end-inclusion-marker-do-not-remove

The following table summarizes the supported platforms and the primary installation mode:
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.39.0-dev32"
__version__ = "0.39.0-dev33"
4 changes: 0 additions & 4 deletions pennylane_lightning/core/lightning_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ def stopping_condition(self):
and observable) and returns ``True`` if supported by the device."""

def accepts_obj(obj):
if isinstance(obj, qml.QFT):
return len(obj.wires) < 10
if isinstance(obj, qml.GroverOperator):
return len(obj.wires) < 13
is_not_tape = not isinstance(obj, qml.tape.QuantumTape)
is_supported = getattr(self, "supports_operation", lambda name: False)(obj.name)
return is_not_tape and is_supported
Expand Down
6 changes: 0 additions & 6 deletions pennylane_lightning/lightning_kokkos/lightning_kokkos.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@

def stopping_condition(op: Operator) -> bool:
"""A function that determines whether or not an operation is supported by ``lightning.kokkos``."""
# To avoid building matrices beyond the given thresholds.
# This should reduce runtime overheads for larger systems.
if isinstance(op, qml.QFT):
return len(op.wires) < 10
if isinstance(op, qml.GroverOperator):
return len(op.wires) < 13
if isinstance(op, qml.PauliRot):
word = op._hyperparameters["pauli_word"] # pylint: disable=protected-access
# decomposes to IsingXX, etc. for n <= 2
Expand Down
7 changes: 0 additions & 7 deletions pennylane_lightning/lightning_qubit/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@

def stopping_condition(op: Operator) -> bool:
"""A function that determines whether or not an operation is supported by ``lightning.qubit``."""
# To avoid building matrices beyond the given thresholds.
# This should reduce runtime overheads for larger systems.
if isinstance(op, qml.QFT):
return len(op.wires) < 10
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(op, qml.GroverOperator):
return len(op.wires) < 13

# As ControlledQubitUnitary == C(QubitUnitrary),
# it can be removed from `_operations` to keep
# consistency with `lightning_qubit.toml`
Expand Down
7 changes: 0 additions & 7 deletions pennylane_lightning/lightning_tensor/lightning_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@

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

if isinstance(op, qml.ControlledQubitUnitary):
return True

Expand Down
13 changes: 6 additions & 7 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def circuit():
class TestQFT:
"""Test the QFT algorithm."""

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

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

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


class TestAQFT:
Expand Down
Loading