-
Notifications
You must be signed in to change notification settings - Fork 188
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 QAOA-Maxcut demo with a few good practices #1251
base: master
Are you sure you want to change the base?
Conversation
👋 Hey, looks like you've updated some demos! 🐘 Don't forget to update the Please hide this comment once the field(s) are updated. Thanks! |
Thank you for opening this pull request. You can find the built site at this link. Deployment Info:
Note: It may take several minutes for updates to this pull request to be reflected on the deployed site. |
|
||
.. meta:: | ||
:property="og:description": Implementing the quantum approximate optimization algorithm using PennyLane to solve the MaxCut problem. | ||
:property="og:image": https://pennylane.ai/qml/_static/demonstration_assets/qaoa_maxcut_partition.png | ||
|
||
.. related:: | ||
tutorial_qaoa_intro Intro to QAOA | ||
|
||
*Author: Angus Lowe — Posted: 11 October 2019. Last updated: 13 April 2021.* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ikurecic could you confirm that this should be removed? I'm not particularly familiar with how qml
metadata is stored. I know about the JSON files, but I'm not aware if any other metadata is used or not.
qml.CNOT(wires=edge) | ||
qml.RZ(gamma, wires=edge[1]) | ||
qml.CNOT(wires=edge) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just an IsingZZ
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, up to a global phase. I was considering to change it but the text explicitly describes this and has a circuit diagram, so I thought it could be fine without change.
But I'm all for reduction if we don't consider that too invasive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should I change it ? :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I won't because I'm not the original author, and Angus put effort into making that figure etc. I'll just add a comment in a note
environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not responding, I think it's good to leave it as is based on the context you gave. Thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The graphs with the distribution for the bit-strings looks great! However, the actual numerical values in the demo output are dramatically different:
Published version:
p=1
Objective after step 5: 2.0000000
Objective after step 10: 2.0000000
Objective after step 15: 4.0000000
Objective after step 20: 3.0000000
Objective after step 25: 1.0000000
Objective after step 30: 2.0000000
Optimized (gamma, beta) vectors:
[[-0.82383311]
[-1.13584295]]
Most frequently sampled bit string is: 0101
p=2
Objective after step 5: 4.0000000
Objective after step 10: 3.0000000
Objective after step 15: 4.0000000
Objective after step 20: 3.0000000
Objective after step 25: 4.0000000
Objective after step 30: 3.0000000
Optimized (gamma, beta) vectors:
[[ 0.87696449 1.31508883]
[ 0.90138291 -0.34955715]]
Most frequently sampled bit string is: 0101
After this PR:
p=1
Objective after step 5: 0.5000000
Objective after step 10: 0.5000000
Objective after step 15: 0.5000000
Objective after step 20: 2.5000000
Objective after step 25: 0.5000000
Objective after step 30: 2.5000000
Optimized (gamma, beta) vectors:
[[-0.90759251]
[-1.2352846 ]]
Most frequently sampled bit string is: 1010
p=2
Objective after step 5: 0.5000000
Objective after step 10: 2.5000000
Objective after step 15: 2.5000000
Objective after step 20: 2.5000000
Objective after step 25: 2.5000000
Objective after step 30: 2.5000000
Optimized (gamma, beta) vectors:
[[ 1.54174446 -0.7153231 ]
[ 0.35679571 -0.72652338]]
Most frequently sampled bit string is: 0101
I think this is happening because the device only has one shot. Before, that would give 4 samples due to 4 executions, but now there's only one sample. It's surprising to see that the distribution still looks as good as it does 😆. I'm guessing changing this line to the following will fix it:
dev = qml.device("lightning.qubit", wires=n_wires, shots=len(graph))
Thanks for the analysis @mudit2812 , that's a good catch!
where Mhm. |
Thanks @dwierichs . It sounds like a non-trivial change. Maybe it makes sense to go over the demo body as well just to make sure that the text is not inconsistent with the new implementation. Otherwise, happy to approve. |
@mudit2812 The variance discussion stands, but I actually noticed a small bug I encoded with the change: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Title:
Summary:
Just updating the MaxCut demo with a few tiny changes that incorporate good practices in Python/PennyLane, which have changed since the creation back in 2019.
Relevant references:
Possible Drawbacks:
Related GitHub Issues:
If you are writing a demonstration, please answer these questions to facilitate the marketing process.
GOALS — Why are we working on this now?
Eg. Promote a new PL feature or show a PL implementation of a recent paper.
AUDIENCE — Who is this for?
Eg. Chemistry researchers, PL educators, beginners in quantum computing.
KEYWORDS — What words should be included in the marketing post?
Which of the following types of documentation is most similar to your file?
(more details here)