You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should be able to build time evolution operator that is a product of many Pauli rotations
Actual behavior
RecursionError: maximum recursion depth exceeded while calling a Python object
Additional information
It works fine if lazy=False is set in qml.prod. Seems like if there are too many nested operators in the result from taking qml.prod too many times, it will cause a recursion error. The limit seems to be about 800 terms; for example, setting range() to 370 in the for loop in attached source code runs fine.
Alex-Preciado
changed the title
Recursion error when accessing operator built using qml.prod
[BUG] Recursion error when accessing operator built using qml.prod
Aug 12, 2024
By default, `qml.sum` and `qml.prod` set `lazy=True`, which keeps its
operands nested. Given the recursive nature of such structures, if there
are too many levels of nesting, a `RecursionError` would occur when
accessing many of the properties and methods. Catching these errors and
re-raising a more sensible error message suggesting that the user could
either set `lazy=False` or use the `+` and `@` operators instead, which
sets `lazy=False`.
**Update**
Extending the behaviour to `SProd`
Fixes#5948
[sc-67745]
By default, `qml.sum` and `qml.prod` set `lazy=True`, which keeps its
operands nested. Given the recursive nature of such structures, if there
are too many levels of nesting, a `RecursionError` would occur when
accessing many of the properties and methods. Catching these errors and
re-raising a more sensible error message suggesting that the user could
either set `lazy=False` or use the `+` and `@` operators instead, which
sets `lazy=False`.
**Update**
Extending the behaviour to `SProd`
Fixes#5948
[sc-67745]
Expected behavior
Should be able to build time evolution operator that is a product of many Pauli rotations
Actual behavior
RecursionError: maximum recursion depth exceeded while calling a Python object
Additional information
It works fine if
lazy=False
is set inqml.prod
. Seems like if there are too many nested operators in the result from takingqml.prod
too many times, it will cause a recursion error. The limit seems to be about 800 terms; for example, settingrange()
to 370 in thefor
loop in attached source code runs fine.Source code
Tracebacks
System information
Name: PennyLane Version: 0.36.0 Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network. Home-page: https://github.com/PennyLaneAI/pennylane Author: Author-email: License: Apache License 2.0 Location: /home/serene.shum/.conda/envs/xanadu/lib/python3.9/site-packages Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions Required-by: PennyLane-qiskit, PennyLane_Lightning, vibrant Platform info: Linux-6.5.0-41-generic-x86_64-with-glibc2.35 Python version: 3.9.19 Numpy version: 1.26.4 Scipy version: 1.13.0 Installed devices: - default.clifford (PennyLane-0.36.0) - default.gaussian (PennyLane-0.36.0) - default.mixed (PennyLane-0.36.0) - default.qubit (PennyLane-0.36.0) - default.qubit.autograd (PennyLane-0.36.0) - default.qubit.jax (PennyLane-0.36.0) - default.qubit.legacy (PennyLane-0.36.0) - default.qubit.tf (PennyLane-0.36.0) - default.qubit.torch (PennyLane-0.36.0) - default.qutrit (PennyLane-0.36.0) - default.qutrit.mixed (PennyLane-0.36.0) - null.qubit (PennyLane-0.36.0) - lightning.qubit (PennyLane-Lightning-0.36.0) - qiskit.aer (PennyLane-qiskit-0.36.0) - qiskit.basicaer (PennyLane-qiskit-0.36.0) - qiskit.basicsim (PennyLane-qiskit-0.36.0) - qiskit.ibmq (PennyLane-qiskit-0.36.0) - qiskit.ibmq.circuit_runner (PennyLane-qiskit-0.36.0) - qiskit.ibmq.sampler (PennyLane-qiskit-0.36.0) - qiskit.remote (PennyLane-qiskit-0.36.0)
Existing GitHub issues
The text was updated successfully, but these errors were encountered: