From 50049a9eeb28cfc92433d9f496d297a6f863e3a7 Mon Sep 17 00:00:00 2001 From: JakeKitchen <155792753+JakeKitchen@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:53:49 -0400 Subject: [PATCH] Update qft.py (#6434) **Context:** The original implementation recalculated the length of the `shifts` list inside the loop during each iteration, which introduces unnecessary repetition. --- **Description of the Change:** moving the computation of `shift_len = len(shifts)` outside the loop in the `compute_decomposition` function., it is now computed once before the loop starts and reused. --- **Benefits:** - **Performance Improvement:** The length of the `shifts` list is now only computed once, reducing unnecessary calculations and slightly improving performance, especially for cases with a large number of wires or repeated calls. - **Readability:** The code is clearer as the intent to calculate the length only once is explicitly shown. - **Maintainability:** It simplifies the logic by ensuring that `shift_len` is calculated only once, reducing the risk of future errors or bugs related to recalculating the list length. --- **Possible drawbacks:** - None --- **Related GitHub Issues:** - N/A --------- Co-authored-by: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com> --- doc/releases/changelog-dev.md | 4 ++++ pennylane/templates/subroutines/qft.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 8708dac5538..8728c2de687 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -189,6 +189,9 @@ * A more sensible error message is raised from a `RecursionError` encountered when accessing properties and methods of a nested `CompositeOp` or `SProd`. [(#6375)](https://github.com/PennyLaneAI/pennylane/pull/6375) +* Moved the calculation of `shift_len = len(shifts)` outside of a loop in the `QFT.compute_decomposition` static method, reducing redundant recalculations and improving performance. + [(#6434)](https://github.com/PennyLaneAI/pennylane/pull/6434) +