-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dimension ordering bug with sum_expand (#5702)
**Context:** `sum_expand` incorrectly order the dimensions when combining shot vectors, multiple measurements, and parameter broadcasting. Additionally, `qml.math.dot` raises an error when when only one of the operands is a scaler. For example: ```pycon >>> import pennylane.numpy as np >>> arr = np.array([1,2,3]) >>> qml.math.dot(arr, 2) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/astral.cai/Workspace/pennylane/pennylane/math/multi_dispatch.py", line 151, in wrapper return fn(*args, **kwargs) File "/Users/astral.cai/Workspace/pennylane/pennylane/math/multi_dispatch.py", line 365, in dot return np.tensordot(x, y, axes=[[-1], [-2]], like=like) File "/Users/astral.cai/Workspace/pennylane/venv/lib/python3.9/site-packages/autoray/autoray.py", line 80, in do return get_lib_fn(backend, fn)(*args, **kwargs) File "/Users/astral.cai/Workspace/pennylane/pennylane/numpy/wrapper.py", line 117, in _wrapped res = obj(*args, **kwargs) File "/Users/astral.cai/Workspace/pennylane/venv/lib/python3.9/site-packages/autograd/tracer.py", line 48, in f_wrapped return f_raw(*args, **kwargs) File "/Users/astral.cai/Workspace/pennylane/venv/lib/python3.9/site-packages/numpy/core/numeric.py", line 1091, in tensordot if as_[axes_a[k]] != bs[axes_b[k]]: IndexError: tuple index out of range ``` **Description of the Change:** - Fixes the bug with `sum_expand`. - Updates `dot` in to use `*` if either operand is a scaler. **Related GitHub Issues:** Fixes #5700 [sc-63541]
- Loading branch information
Showing
5 changed files
with
70 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters