Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Torch tensor.to_numpy dispatch to stay compatible with torch<=1.9.0 #1825

Merged
merged 9 commits into from
Nov 1, 2021

Conversation

antalszava
Copy link
Contributor

@antalszava antalszava commented Oct 29, 2021

import pennylane as qml
import torch

feat = torch.tensor([0,1])

qml.templates.embeddings.AmplitudeEmbedding(feat, range(1), pad_with=0.0, normalize=True)
~/xanadu/pennylane/pennylane/math/single_dispatch.py in _to_numpy_torch(x)
    270 
    271 def _to_numpy_torch(x):
--> 272     if x.is_conj():
    273         x = x.resolve_conj()
    274 

AttributeError: 'Tensor' object has no attribute 'is_conj'

@github-actions
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

@antalszava antalszava changed the title Torch conj adjust Update Torch tensor.to_numpy dispatch to stay compatible with torch<=1.9.0 Oct 29, 2021
@codecov
Copy link

codecov bot commented Oct 29, 2021

Codecov Report

Merging #1825 (aa85ddd) into master (5316f82) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1825   +/-   ##
=======================================
  Coverage   98.96%   98.96%           
=======================================
  Files         218      218           
  Lines       16368    16368           
=======================================
  Hits        16199    16199           
  Misses        169      169           
Impacted Files Coverage Δ
pennylane/math/single_dispatch.py 99.54% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5316f82...aa85ddd. Read the comment docs.

@antalszava antalszava marked this pull request as ready for review October 29, 2021 22:38
@@ -269,7 +269,7 @@ def _scatter_element_add_tf(tensor, index, value):


def _to_numpy_torch(x):
if x.is_conj():
if getattr(x, "is_conj", False) and x.is_conj():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, nice catch @antalszava!

Comment on lines 22 to 28
- {python-version: 3.7, interfaces: ['torch'], interface_version: 1.9.0+cpu}
- {python-version: 3.7, interfaces: ['torch'], interface_version: 1.10.0+cpu}
- {python-version: 3.8, interfaces: ['torch'], interface_version: 1.10.0+cpu}

- {python-version: 3.7, interfaces: ['tf'], interface_version: 2.5}
- {python-version: 3.7, interfaces: ['tf'], interface_version: 2.6}
- {python-version: 3.8, interfaces: ['tf'], interface_version: 2.6}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it’s good to test as many configurations as we can, but I would like to balance it against ensuring the CI does not take too long for contributors. I also want to lesson the maintenance load on the development team.

What do you think about ensuring PennyLane compatibility with only the latest 2.X (TF) and 1.X (PyTorch) versions via the CI suite?

  • With semantic versioning, TensorFlow and PyTorch should not be introducing breaking changes in minor release versions (Torch complex number support is the one exception, since complex support was not available in 1.0)

  • The onus on the developers for maintenance then shifts to ensuring that the QML demos work with the latest releases of TF and Torch, which I think is more important for users than ensuring PL works for older versions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we can re-evaluate when there are new major version releases, but with semantic versioning, I think it makes sense to guarantee support for only the latest minor versions.

Note: this doesn’t mean we actively remove support for older minor versions, just that the CI only verifies the PL test suite against the latest minor versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense and also was wondering if we should have these many checks here.

What if we had a weekly/on dispatch check that runs with multiple interface versions? That way we could double-check from time to time if we have an implementation in PennyLane that breaks with older versions of an ML framework.

Having many checks on every PR run might indeed decrease the development momentum.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert the changes to this file for now. They were meant to just double-check that the changes in place were effective.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we had a weekly/on dispatch check that runs with multiple interface versions? That way we could double-check from time to time if we have an implementation in PennyLane that breaks with older versions of an ML framework.

Makes more sense I think than having it in the main CI!

Although, we should definitely codify our dependency support; with semantic versioning, the onus should not be on PennyLane to test against older minor versions of dependencies.

@josh146 josh146 merged commit ed20510 into master Nov 1, 2021
@josh146 josh146 deleted the torch_conj_adjust branch November 1, 2021 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants