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

QNGOptimizer_Hamiltonian #2524

Merged
merged 10 commits into from
Apr 29, 2022
Merged

QNGOptimizer_Hamiltonian #2524

merged 10 commits into from
Apr 29, 2022

Conversation

KetpuntoG
Copy link
Contributor

@KetpuntoG KetpuntoG commented Apr 29, 2022


Context:

When using QNGOptimizer with DoubleExcitation an error occurred because the DoubleExcitation generator is a Hamiltonian and there is no diagonalization method.

Description of the Change:

A function has been added to check if the generator is a Hamiltonian with more than one term (since if it has only one term it can be treated as a simple operator). If it is a Hamiltonian, we expand the operation.

Benefits:

QNGOptimizer can now be used with more gates

Possible Drawbacks:

Perhaps in other cases it is better not to expand (?)

Related GitHub Issues:

#2502

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

@codecov
Copy link

codecov bot commented Apr 29, 2022

Codecov Report

Merging #2524 (da13c8a) into master (3850713) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2524   +/-   ##
=======================================
  Coverage   99.47%   99.47%           
=======================================
  Files         244      244           
  Lines       19423    19433   +10     
=======================================
+ Hits        19321    19331   +10     
  Misses        102      102           
Impacted Files Coverage Δ
pennylane/transforms/tape_expand.py 100.00% <ø> (ø)
pennylane/operation.py 96.77% <100.00%> (+0.05%) ⬆️

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 3850713...da13c8a. Read the comment docs.

@KetpuntoG KetpuntoG requested a review from josh146 April 29, 2022 12:55
@KetpuntoG KetpuntoG changed the title QNGOptimizer_Hamiltonian [WIP] QNGOptimizer_Hamiltonian Apr 29, 2022
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.

@KetpuntoG this looks like a great fix 💪 Just had one comment, otherwise this is looking 💯

pennylane/operation.py Show resolved Hide resolved
pennylane/transforms/tape_expand.py Outdated Show resolved Hide resolved
tests/optimize/test_qng.py Show resolved Hide resolved
Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

@KetpuntoG this is a great bugfix! Fantastic job fixing a very complicated part of PennyLane. Like Antal, I only have very minor comments.

doc/releases/changelog-dev.md Outdated Show resolved Hide resolved
pennylane/operation.py Outdated Show resolved Hide resolved
pennylane/transforms/tape_expand.py Show resolved Hide resolved
tests/optimize/test_qng.py Show resolved Hide resolved
tests/test_operation.py Show resolved Hide resolved
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 to me! Great fix 👏 The approval is conditioned on addressing Josh's comment on the changelog and the use of isinstance.

KetpuntoG and others added 3 commits April 29, 2022 13:29
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
@KetpuntoG
Copy link
Contributor Author

Thank you very much for your comments @josh146 @antalszava ! This PR has helped me to realize how much I still have to understand about pennylane 😄

Copy link
Member

@josh146 josh146 left a comment

Choose a reason for hiding this comment

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

Looks great @KetpuntoG!

@KetpuntoG KetpuntoG merged commit 207074e into master Apr 29, 2022
@KetpuntoG KetpuntoG deleted the qng_hamiltonian branch April 29, 2022 18:48
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

3 participants