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

Inverse circuit not computed correctly in pennylane 0.15.0 #1242

Closed
EliasCombarro opened this issue Apr 20, 2021 · 10 comments · Fixed by #1243
Closed

Inverse circuit not computed correctly in pennylane 0.15.0 #1242

EliasCombarro opened this issue Apr 20, 2021 · 10 comments · Fixed by #1243
Labels
bug 🐛 Something isn't working
Milestone

Comments

@EliasCombarro
Copy link

EliasCombarro commented Apr 20, 2021

Issue description

I do not know if it has to do with this other issue #1240 but it seems that in version 0.15.0 the inverse of a circuit is not computed correctly. I noticed it while executing the kernel classifier from https://pennylane.ai/qml/demos/tutorial_kernel_based_training.html

In fact, when executing

kernel(X_train[0], X_train[0])

I obtain 0.15190944036912452

and when printing the circuit I get

[ 0.35866332  2.73124718 -0.94364311 -0.68644165]
 0: ──RX(0.359)───RX(0.359)───╭┤ ⟨H0⟩ 
 1: ──RX(2.73)────RX(2.73)────├┤ ⟨H0⟩ 
 2: ──RX(-0.944)──RX(-0.944)──├┤ ⟨H0⟩ 
 3: ──RX(-0.686)──RX(-0.686)──╰┤ ⟨H0⟩ 

with not inverse in the second column of rotations)

  • Expected behavior: (What you expect to happen)

This works correctly with pennylane 0.14.1, with which I obtain

0.9999999999999998
[ 0.35866332  2.73124718 -0.94364311 -0.68644165]
 0: ──RX(0.359)───RX(0.359)⁻¹───╭┤ ⟨H0⟩ 
 1: ──RX(2.73)────RX(2.73)⁻¹────├┤ ⟨H0⟩ 
 2: ──RX(-0.944)──RX(-0.944)⁻¹──├┤ ⟨H0⟩ 
 3: ──RX(-0.686)──RX(-0.686)⁻¹──╰┤ ⟨H0⟩ 
  • Actual behavior: (What actually happens)

The one described above

  • Reproduces how often: (What percentage of the time does it reproduce?)

100%

  • System information: (post the output of import pennylane as qml; qml.about())

Name: PennyLane
Version: 0.15.0
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/XanaduAI/pennylane
Author: None
Author-email: None
License: Apache License 2.0
Location: /usr/local/lib/python3.7/dist-packages
Requires: scipy, toml, appdirs, numpy, semantic-version, autograd, networkx
Required-by:
Platform info: Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
Python version: 3.7.10
Numpy version: 1.19.5
Scipy version: 1.4.1
Installed devices:

@josh146
Copy link
Member

josh146 commented Apr 20, 2021

Thanks for catching this @EliasCombarro! This is certainly a concerning bug, we'll look into this and see if we can uncover what is happening.

@EliasCombarro
Copy link
Author

My pleasure

@antalszava antalszava added the bug 🐛 Something isn't working label Apr 20, 2021
@josh146 josh146 linked a pull request Apr 21, 2021 that will close this issue
@josh146
Copy link
Member

josh146 commented Apr 21, 2021

@EliasCombarro, a quick update: I believe I have found the issue and fixed it in #1243

@EliasCombarro
Copy link
Author

Thanks! Just a quick question: what should I use instead of qml.inv()?

@josh146
Copy link
Member

josh146 commented Apr 22, 2021

Hey @EliasCombarro!

If you install PennyLane from the branch in the PR,

pip install git+https://github.com/PennyLaneAI/pennylane.git@fix-inv

then you should be able to use either qml.inv() or the new qml.adjoint() function to invert your templates 🙂

Note that, while qml.inv() is still present, it has been deprecated, and will long-term be replaced with qml.adjoint().

@EliasCombarro
Copy link
Author

Excellent, thank you.

@josh146
Copy link
Member

josh146 commented Apr 23, 2021

no worries @EliasCombarro!

@EliasCombarro
Copy link
Author

Thank you!

@josh146
Copy link
Member

josh146 commented May 3, 2021

Hi @EliasCombarro - we just realized a bugfix version of PennyLane, v0.15.1, that fixes this bug 🙂 The kernel demo on the website should now also be returning the correct result

@EliasCombarro
Copy link
Author

Great! Thanks so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants