Update to Ajc/qaoa pr 4805#5029
Closed
mrvee-qC-bee wants to merge 10 commits intoQiskit:mainfrom
Closed
Conversation
Making updates to match the updated tutorial template --------- Co-authored-by: abbycross <across@us.ibm.com> Co-authored-by: Mirko Amico <31739486+miamico@users.noreply.github.com>
Rewrite and update content, bugfixes and code review
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Contributor
|
Thanks for contributing to Qiskit documentation! Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌 One or more of the following people are relevant to this code:
|
Contributor
Author
|
@abbycross fyi! |
Collaborator
|
I've moved the changes to #4813; we can close this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR to update QAOA notebook
best_solution was broken. It sets min_cost = 1000 but never updates it inside the loop, so basically every sample passes the <= check and the function returns whatever happens to come last. Made it toupdate min_cost when we find something better.
The docstring on build_max_cut_paulis refers to a build_max_cut_graph function that doesn't exist anywhere — looks like a leftover from wherever this code originally lived. Rewrote it to describe what the function actually returns.
The HCH_C HC formula was written two different ways in two different places — Background had ∑QijZiZj\sum Q_{ij} Z_iZ_j ∑QijZiZj, Step 1 had ∑ZiZj\sum Z_iZ_j ∑ZiZj. Made them match, with Step 1 explicitly saying "for unweighted Max-Cut this reduces to…".
Step 1 had a dangling "Start by defining a 5-node graph:" sentence that led into nothing (the graph was already defined in a prior cell, and the next thing was building the Hamiltonian). Deleted.
Put back the general Hamiltonian HC=∑ijQijZiZj+∑ibiZiH_C = \sum_{ij} Q_{ij} Z_iZ_j + \sum_i b_i Z_i HC=∑ijQijZiZj+∑ibiZi in Background with a note that bi=0b_i = 0 bi=0 for unweighted Max-Cut. The rewrite had trimmed it to the simplified form only, which left readers with no hook if they wanted to adapt this to weighted graphs or other QUBO problems.
Brought back the single-job / batch / session illustration in Step 3 — the rewrite had dropped it when compressing the explanation.
Renamed the "Small-scale simulator example" heading to just "Small-scale example." The code in that section runs on real hardware (simulator=False), so "simulator example" is incorrect. Added a sentence making this explicit.
Split the 85-line utility-scale cell into four cells, one per step, with short markdown transitions between them. Matches the style of the small-scale walkthrough and makes the block less intimidating to scroll through.
Fixed the grammar on "The steps to build the workflow are followed the same as above" — now reads "The workflow follows the same steps as above, applied to a much larger graph."
Added a classical brute-force baseline after the 5-node example. At n=5 you're enumerating 32 bitstrings, which is trivial, and it gives readers a way to see how close QAOA actually got to the real optimum.
Added a comment explaining the evaluate_sparse_pauli bit-trick. The np.packbits / np.bitwise_xor.reduce stuff is dense, and without context it's not obvious why you'd do that instead of just calling SparsePauliOp.expectation_value. The answer is performance — it's dramatically faster across 10,000 samples — and the comment now says so.
Added interpretation for the convergence plot. A reader looking at a jagged curve shouldn't have to guess whether that's normal or a sign something's wrong. Walks through what a healthy curve looks like, what a bad one means, and the specific way COBYLA fails when the noise exceeds the per-step cost improvement (COBYLA is derivative-free, so its linear-approximation model just can't tell descent from jitter).
Added a short comment on the initial γ, β values. The original just set them with no explanation. Made it clear that these aren't principled defaults, just bounded midpoints of the periodic parameter ranges.
Added a one-liner on what optimization_level=3 means — slower to transpile, shorter circuits, more robust on hardware. Otherwise a newcomer sees the number and has to guess what the range is.
Replaced the hardcoded "Heron device" label in the CDF plot with backend.name. That string was going to read wrong the moment anyone ran this on a different backend.
Renamed the module-scope n = 5 and n = 100 to n_small and n_large. Notebooks get executed out of order all the time, and having both bound to n is asking for a confusing bug.
Dropped the redundant bare import matplotlib (was only used for one matplotlib.rcParams.update call that works identically as plt.rcParams.update).