Skip to content

Commit

Permalink
Fix PennyLane v0.23.1 to work with Autoray 0.3.1 (PennyLaneAI#2548)
Browse files Browse the repository at this point in the history
* Fix PennyLane to work with Autoray 0.3.1

* fix

* update

* add new changelog file

* Update doc/releases/changelog-0.23.1.md

Co-authored-by: antalszava <antalszava@gmail.com>

Co-authored-by: antalszava <antalszava@gmail.com>
  • Loading branch information
josh146 and antalszava authored May 9, 2022
1 parent 6f270a8 commit 6fca066
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions doc/development/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Release notes

This page contains the release notes for PennyLane.

.. mdinclude:: ../releases/changelog-0.23.1.md

.. mdinclude:: ../releases/changelog-0.23.0.md

Expand Down
2 changes: 1 addition & 1 deletion doc/releases/changelog-0.23.0.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:orphan:

# Release 0.23.0 (current release)
# Release 0.23.0

<h3>New features since last release</h3>

Expand Down
14 changes: 14 additions & 0 deletions doc/releases/changelog-0.23.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
:orphan:

# Release 0.23.1 (current release)

<h3>Bug fixes</h3>

* Fixed a bug enabling PennyLane to work with the latest version of Autoray.
[(#2548)](https://github.com/PennyLaneAI/pennylane/pull/2548)

<h3>Contributors</h3>

This release contains contributions from (in alphabetical order):

Josh Izaac
2 changes: 1 addition & 1 deletion pennylane/_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.23.0"
__version__ = "0.23.1"
8 changes: 7 additions & 1 deletion pennylane/math/multi_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,13 @@ def where(condition, x=None, y=None):
interface = _multi_dispatch([condition])
return np.where(condition, like=interface)

return np.where(condition, x, y, like=_multi_dispatch([condition, x, y]))
interface = _multi_dispatch([condition, x, y])
res = np.where(condition, x, y, like=interface)

if interface == "tensorflow":
return np.transpose(np.stack(res))

return res


@multi_dispatch(argnum=[0, 1])
Expand Down
11 changes: 0 additions & 11 deletions pennylane/math/single_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,6 @@ def _to_numpy_torch(x):
ar.register_function("torch", "shape", lambda x: tuple(x.shape))
ar.register_function("torch", "gather", lambda x, indices: x[indices])

try:
if semantic_version.match(">=1.10", _i("torch").__version__):
# Autoray uses the deprecated torch.symeig as an alias for eigh, however this has
# been deprecated in favour of torch.linalg.eigh.
# autoray.py:84: UserWarning: torch.symeig is deprecated in favor of torch.linalg.eigh
# and will be removed in a future PyTorch release.
del ar.autoray._FUNCS["torch", "linalg.eigh"]
except ImportError:
pass


ar.register_function(
"torch",
"sqrt",
Expand Down
4 changes: 2 additions & 2 deletions pennylane/math/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def allclose(a, b, rtol=1e-05, atol=1e-08, **kwargs):
# Some frameworks may provide their own allclose implementation.
# Try and use it if available.
res = np.allclose(a, b, rtol=rtol, atol=atol, **kwargs)
except (TypeError, AttributeError):
except (TypeError, AttributeError, ImportError):
# Otherwise, convert the input to NumPy arrays.
#
# TODO: replace this with a bespoke, framework agnostic
Expand Down Expand Up @@ -111,7 +111,7 @@ def cast(tensor, dtype):
if not isinstance(dtype, str):
try:
dtype = np.dtype(dtype).name
except (AttributeError, TypeError):
except (AttributeError, TypeError, ImportError):
dtype = getattr(dtype, "name", dtype)

return ar.astype(tensor, ar.to_backend_dtype(dtype, like=ar.infer_backend(tensor)))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ toml==0.10
appdirs==1.4
semantic_version==2.6
dask[delayed]==2021.10
autoray>=0.2.5
autoray==0.3.1
matplotlib==3.4
black>=21
opt_einsum==3.3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"toml",
"appdirs",
"semantic_version==2.6",
"autoray",
"autoray>=0.3.1",
"cachetools",
"pennylane-lightning>=0.23",
]
Expand Down
2 changes: 0 additions & 2 deletions tests/math/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,6 @@ def test_where(interface, t):
[0, 0, 1, 1, 2, 0, 0, 2, 2],
[0, 1, 0, 1, 1, 0, 1, 0, 1],
)
if interface == "tf":
expected = qml.math.T(expected)
assert all(fn.allclose(_res, _exp) for _res, _exp in zip(res, expected))


Expand Down

0 comments on commit 6fca066

Please sign in to comment.