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

[unitaryhack] Add SPSA optimization #2661

Merged
merged 96 commits into from Jun 13, 2022

Conversation

ixime
Copy link
Contributor

@ixime ixime commented Jun 4, 2022

Context:
Adding a feature as part of unitaryhack related to issue #2451

Description of the Change:
The qml.SPSAOptimizer was added with its corresponding tests based on:

J. Spall, "An Overview of the Simultaneous Perturbation Method for Efficient Optimization." Johns Hopkins api technical digest, 19(4), 482-492, 1998

Benefits:

  • The Simultaneous Perturbation Stochastic Approximation method (SPSA) is an iterative algorithm for optimization ideal for noisy loss functions.
  • In contrast to other methods that perform multiple operations to determine the gradient, SPSA only measures two times the loss function to obtain it.

Possible Drawbacks:

Related GitHub Issues:
Closes #2451

@ixime ixime changed the title Add spsa optimization ixime Add spsa optimization [unitaryhack] [WIP] Jun 4, 2022
@ixime ixime changed the title Add spsa optimization [unitaryhack] [WIP] [WIP] Add spsa optimization [unitaryhack] Jun 4, 2022
@ixime
Copy link
Contributor Author

ixime commented Jun 4, 2022

I think I finished everything, but I am not sure about the cases of hybrid classical-quantum workflows. as I commented in #2451

@codecov
Copy link

codecov bot commented Jun 4, 2022

Codecov Report

Merging #2661 (a016cd1) into master (57f20b7) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #2661   +/-   ##
=======================================
  Coverage   99.61%   99.61%           
=======================================
  Files         251      252    +1     
  Lines       20662    20726   +64     
=======================================
+ Hits        20582    20646   +64     
  Misses         80       80           
Impacted Files Coverage Δ
pennylane/optimize/__init__.py 100.00% <100.00%> (ø)
pennylane/optimize/spsa.py 100.00% <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 57f20b7...a016cd1. Read the comment docs.

@ixime ixime changed the title [WIP] Add spsa optimization [unitaryhack] Add spsa optimization [unitaryhack] Jun 4, 2022
@antalszava antalszava self-requested a review June 6, 2022 13:07
@MoritzWillmann
Copy link
Contributor

Did you compare the optimizer to qiskit's ? I only compared it to noisyopt's implementation

Not yet, but I can do it smile

Hey @MoritzWillmann, please do this comparison too. I'm using both noisyopt and Qiskit currently and do not want any surprises when I switch too this implementation! 😆 😅

I yield similar results for a couple of different functions. I think you're good to go 😆

pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
tests/optimize/test_spsa.py Outdated Show resolved Hide resolved
tests/optimize/test_spsa.py Outdated Show resolved Hide resolved
tests/optimize/test_spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated 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.

Hi @ixime and @MoritzWillmann! This is looking amazing overall. 👏 🎆

The suggestions I have this time are smaller. Once they are addressed, I'll make another pass, but the overall addition here is very near approval.

Note: some conflicts will have to be resolved when merging master in.

pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
doc/releases/changelog-dev.md Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
pennylane/optimize/spsa.py Outdated Show resolved Hide resolved
tests/optimize/test_spsa.py Outdated Show resolved Hide resolved
@antalszava antalszava changed the title Add spsa optimization [unitaryhack] [unitaryhack] Add spsa optimization Jun 10, 2022
@antalszava antalszava changed the title [unitaryhack] Add spsa optimization [unitaryhack] Add SPSA optimization Jun 10, 2022
ixime and others added 10 commits June 10, 2022 19:19
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
Co-authored-by: antalszava <antalszava@gmail.com>
@ixime
Copy link
Contributor Author

ixime commented Jun 11, 2022

I tried to solve the conflicts, but I don't have write access to solve them. My fork master is up to date and apparently I merged successfully my local branch with my up to date local master 🤷‍♀️ I am little lost here.. did I miss some step?

@josh146
Copy link
Member

josh146 commented Jun 11, 2022

@ixime It should be fixed now :)

@ixime
Copy link
Contributor Author

ixime commented Jun 13, 2022

Hi @antalszava why some times the codecov report is fine and the next check is all wrong without changing a bit on the code, just the docstring?

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 @ixime, @MoritzWillmann! 🎉 🎆 This is an amazing and high-quality addition, congrats 🙂 👏

Adding the Unitary HACK accepted label too.

Hi @antalszava why some times the codecov report is fine and the next check is all wrong without changing a bit on the code, just the docstring?

I think the issue came from a previous state where one test was failing and it didn't report to Codecov correctly. Now it should be okay 👍

@antalszava antalszava added the unitaryhack-accepted This contribution has been accepted for a UnitaryHack issue label Jun 13, 2022
@antalszava antalszava merged commit 963f17b into PennyLaneAI:master Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unitaryhack-accepted This contribution has been accepted for a UnitaryHack issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SPSA optimization method
5 participants