From b158f921e5d9dc5d701078202802342588e97319 Mon Sep 17 00:00:00 2001 From: Justin Pickering <79890410+justinpickering@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:57:24 -0500 Subject: [PATCH] Add warning message to Gradients and training documentation about `ComplexWarnings` (#6543) **Context:** - This PR addresses a recurring ComplexWarning issue that appears when using differentiable workflows involving both complex and float types, particularly during backpropagation. Users have reported this issue (see an example [here](https://discuss.pennylane.ai/t/casting-of-complex-to-float-when-using-phaseshift-in-circuit-for-qml/7439)), and [internal discussions](https://xanaduhq.slack.com/archives/C0743CNS9E3/p1730329623028289) have concluded that while the warning is generally harmless, it can still be confusing for users. **Description of the Change:** - A warning note has been added to the Gradients and training page in the documentation. The note explains the origin of the ComplexWarning, assures users that it is non-critical in this context, and provides a code snippet to suppress the warning. **Benefits:** - Clarifies to users that the ComplexWarning does not indicate a calculation error, which can help avoid unnecessary troubleshooting. - Offers an easy method to suppress the warning **Possible Drawbacks:** - Suppressing warnings could potentially hide other, less common issues involving complex numbers in more advanced workflows - Users may overlook the warning's informational value if they suppress it without fully understanding the implications **Related GitHub Issues:** --------- Co-authored-by: Mudit Pandey --- doc/introduction/interfaces.rst | 11 +++++++++++ doc/releases/changelog-dev.md | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/introduction/interfaces.rst b/doc/introduction/interfaces.rst index 7eb3d391600..61ff7aeb61f 100644 --- a/doc/introduction/interfaces.rst +++ b/doc/introduction/interfaces.rst @@ -34,6 +34,17 @@ a :class:`QNode `, e.g., If no interface is specified, PennyLane will automatically determine the interface based on provided arguments and keyword arguments. See ``qml.workflow.SUPPORTED_INTERFACES`` for a list of all accepted interface strings. +.. warning:: + + ``ComplexWarning`` messages may appear when running differentiable workflows involving both complex and float types, particularly + with certain interfaces. These warnings are common in backpropagation due to the nature of complex casting and do not + indicate an error in computation. If desired, you can suppress these warnings by adding the following code: + + .. code-block:: python + + import warnings + warnings.filterwarnings("ignore", category=np.ComplexWarning) + This will allow native numerical objects of the specified library (NumPy arrays, JAX arrays, Torch Tensors, or TensorFlow Tensors) to be passed as parameters to the quantum circuit. It also makes the gradients of the quantum circuit accessible to the classical library, enabling the diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index 50f62fd7899..d95737af09d 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -52,6 +52,9 @@

Documentation 📝

+* Add a warning message to Gradients and training documentation about ComplexWarnings + [(#6543)](https://github.com/PennyLaneAI/pennylane/pull/6543) +

Bug fixes 🐛

Contributors ✍️

@@ -60,5 +63,7 @@ This release contains contributions from (in alphabetical order): Shiwen An Astral Cai, -Pietropaolo Frisoni, -Andrija Paurevic +Andrija Paurevic, +Justin Pickering +Pietropaolo Frisoni +