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

FIx bug density_matrix and torch #2643

Merged
merged 19 commits into from
Jun 3, 2022
Merged

FIx bug density_matrix and torch #2643

merged 19 commits into from
Jun 3, 2022

Conversation

rmoyard
Copy link
Contributor

@rmoyard rmoyard commented May 31, 2022

Context:
When using torch returning the density matrix yields wrong format results.

Description of the Change:
The Torch _asarray function in default.qubit.torch is always unrolling the tensor. I created a specific case for density matrix.

Benefits:
qml.density_matrix works with Torch interface.

Related GitHub Issues:
Closes #2553

@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.

@rmoyard
Copy link
Contributor Author

rmoyard commented May 31, 2022

[sc-19818]

@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #2643 (297ce60) into master (89439a8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2643   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files         248      248           
  Lines       19972    19975    +3     
=======================================
+ Hits        19889    19892    +3     
  Misses         83       83           
Impacted Files Coverage Δ
pennylane/_qubit_device.py 98.78% <ø> (ø)
pennylane/devices/default_qubit_torch.py 92.30% <100.00%> (+0.22%) ⬆️

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 89439a8...297ce60. Read the comment docs.

Copy link
Contributor

@eddddddy eddddddy left a comment

Choose a reason for hiding this comment

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

Hi @rmoyard, looks good to me! Just a minor change and a question, then should be good to go.

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
tests/test_measurements.py Outdated Show resolved Hide resolved
rmoyard and others added 2 commits May 31, 2022 22:15
Co-authored-by: Edward Jiang <34989448+eddddddy@users.noreply.github.com>
tests/test_measurements.py Outdated Show resolved Hide resolved
tests/test_measurements.py Outdated Show resolved Hide resolved
Co-authored-by: Edward Jiang <34989448+eddddddy@users.noreply.github.com>
Copy link
Contributor

@antalszava antalszava left a comment

Choose a reason for hiding this comment

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

@rmoyard this is awesome! 🥇 🎉

There was a major thing I wondered about related to the change in logic, though the fix seems to overall check out. 👍

doc/introduction/interfaces.rst Show resolved Hide resolved
doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
tests/test_measurements.py Outdated Show resolved Hide resolved
tests/test_measurements.py Outdated Show resolved Hide resolved
tests/test_measurements.py Show resolved Hide resolved
pennylane/devices/default_qubit_torch.py Outdated Show resolved Hide resolved
@rmoyard rmoyard requested a review from antalszava June 3, 2022 15:24
Copy link
Contributor

@antalszava antalszava left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@rmoyard rmoyard merged commit 2b07d22 into master Jun 3, 2022
@rmoyard rmoyard deleted the fix_bug_torch_density branch June 3, 2022 18:06
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.

[BUG] qml.density_matrix() has incorrect shape with PyTorch and backprop
3 participants