Skip to content

Commit

Permalink
bump tensorflow to 2.15 in CI (#4847)
Browse files Browse the repository at this point in the history
For some reason in 2.15, the `ndim()` of an abstract tensor with shape
specified as `None` was -1, so it didn't raise an error, and didn't get
handled with [this exception
handling](https://github.com/PennyLaneAI/pennylane/blob/aab9ed91110ac95938fe2275625e1845970d5a9c/pennylane/operation.py#L1091)

**Description of the change**
`qml.math.ndim(tensor)` always returns `len(tensor.shape)` for
tensorflow. this will still raise errors as expected for abstract
tensors with abstract shapes (only happens when the user specifies the
shape as None before compiling a function).

ran a bunch of tests (tf interface tests, the `tf.function` test that
failed in test_operation.py) locally with python 3.9, TF 2.10 just to
make sure I didn't break old versions of tensorflow, they all passed 🙌
  • Loading branch information
timmysilv authored Nov 16, 2023
1 parent bce513e commit 93a8716
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/interface-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:
description: The version of TensorFlow to install for any job that requires TensorFlow
required: false
type: string
default: 2.13.0
default: 2.15.0
pytorch_version:
description: The version of PyTorch to install for any job that requires PyTorch
required: false
Expand Down
8 changes: 1 addition & 7 deletions pennylane/math/single_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,7 @@ def _round_tf(tensor, decimals=0):


def _ndim_tf(tensor):
try:
ndim = _i("tf").experimental.numpy.ndim(tensor)
if ndim is None:
return len(tensor.shape)
return ndim
except AttributeError:
return len(tensor.shape)
return len(tensor.shape)


ar.register_function("tensorflow", "ndim", _ndim_tf)
Expand Down

0 comments on commit 93a8716

Please sign in to comment.