Sqdrift tutorial (CPP and Python) - #5667
Shobhit Pandey (Shobhit21287) wants to merge 15 commits into
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
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:
|
Henry Zou (henryzou50)
left a comment
There was a problem hiding this comment.
Thanks, Shobhit! The Python notebook and C++ companion are taking shape. Before merging, could you address the following?
- Tutorial placement and discoverability
- Move the notebook to docs/tutorials/sqdrift.ipynb, alongside the other tutorials. Update its paths in _toc.json, index.mdx, qiskit_bot.yaml, and notebook-testing.toml.
- Add a prominent note above “Learning outcomes” linking to the C++ tutorial directory in this repository, where readers can find the README, build instructions, and source. The current plain-text SqDRIFT.cpp reference isn’t enough to navigate there.
Something like:
<Admonition type="note" title="Looking for the C++ version?">
This tutorial uses Python. For the C++ implementation, including source code and build instructions, see the [C++ SqDRIFT tutorial](https://github.com/Qiskit/documentation/tree/main/docs/tutorials/sqdrift/SqDRIFT_Tutorial_CPP).
</Admonition>- Keeping the supporting files under docs/tutorials/sqdrift/ is fine for now. Kaelyn Ferris (@kaelynj), could you advise on the preferred structure for these files? As one of our first non-Python tutorials, this could establish a useful pattern.
- Make both examples runnable from the instructions
- Python: The notebook reads fcidump_files/N2_sto_3g without explaining how to obtain it. Please add a download cell or explicit download instructions before its first use. Update both reads after moving the notebook.
- C++ diagonalization: The README’s ln -sf ../../../../fcidump_files/N2_sto_3g fcidump.txt points to a nonexistent location. With the current layout, it needs ../../../../../fcidump_files/N2_sto_3g.
- C++ build guide: The complete build example needs cd .. before ./SqDRIFT, because the executable is written to the project root. Please also remove the reference to the missing set_dyld_path.sh and make the Windows support statements consistent between the two guides.
- Add a short description of the FCIDUMP’s source and molecular geometry so readers can identify and reproduce the example.
- Tighten the scientific explanations
- The explanation of filter_diagonal_terms() says these terms contribute only a global phase. In general, number-operator terms introduce relative phases that can affect later interference. Please explain the assumptions or approximation that justify removing them here.
- In the qDRIFT equations, distinguish the number of Hamiltonian terms from the number of sampled operators. The notebook currently mixes N and n. Also clarify how coefficient signs are retained in the evolved operators. Please update the C++ README’s equations consistently.
- The Python/C++ comparison should mention that the examples also differ in circuit count, evolution times, and diagonal-term filtering—not just postselection versus configuration recovery. Please avoid attributing the energy difference solely to recovery without a controlled comparison.
- Replace the blanket statement that systems beyond 20 qubits require HPC with an explanation that classical cost depends on the selected-subspace size and available resources.
- Minor items:
- Please remove the empty markdown cell above Learning Outcomes
…e explaination of final circuit created as the sign is required to ensure convergence when combining samples across operators, towards the fully trotterized hamiltonian.
…or the background
Henry Zou (henryzou50)
left a comment
There was a problem hiding this comment.
Thanks, Shobhit! Most of the earlier feedback is addressed. I have a few remaining requests before approving:
- Clarify the diagonal-term filtering explanation.
The notebook still says these terms cannot change the observed bitstrings. They do not directly change occupation probabilities, but their relative phases can affect later interference. Please remove the claim that filtering leaves sampling unchanged. Possible wording:
We remove diagonal terms from the circuit-generation Hamiltonian to focus sampling on excitation terms. This changes the generated evolution and can change the sampling distribution. The classical diagonalization still uses the full Hamiltonian, including its diagonal terms.
Please confirm that this describes the intended approximation and clarify any implications for the convergence guarantees discussed earlier.
-
Update the simulator note to match the refreshed results.
The note before SQD post-processing says subspace dimensions stay constant across iterations, but the new output shows them increasing, for example, from 5538 to 6080. Please remove that assertion, as noiseless sampling does not guarantee a constant selected-subspace dimension. -
Remove the stale C++ results paragraph.
Immediately before “How this differs from the Python SqDRIFT tutorial,” the README still mentions 1,694 surviving shots and 54 strings. The updated results show 1,103 shots and 45 α-determinants. Please update or delete this paragraph, and avoid equating the α-determinant count with the full α/β subspace dimension. -
Pin the Runtime dependency to a tested commit.
Runtime PR #27 has now merged, so the CMake comment about waiting for it is outdated. Ideally, switch to a pinned upstream commit containing the fix and verify the build/run. Alternatively, you can pin the fork commit you already tested and track the upstream migration as a follow-up.
|
@Shobhit-Pandey1 following up on my earlier question about where the C++ files should live: I synced with Kaelyn Ferris (@kaelynj) and nathanearnestnoble , and we landed on a new shared location for non-Python tutorial files: For this PR, that means:
The Things that will need updating after the move:
The Julia tutorial (#5557) is moving to the same structure, so this keeps the non-Python tutorials consistent. Let me know if anything is unclear! |
Henry Zou (henryzou50)
left a comment
There was a problem hiding this comment.
LGTM! Thanks, Shobhit! The latest updates address my remaining review comments, and the tutorial looks good from my side. Since this PR comes from a fork, I’ll carry the reviewed commits into a branch in Qiskit/documentation and open a replacement PR so CI can access the required repository secrets. I’ll preserve your authorship, link back to this PR, and ask Abby for a final review.
|
Work continuing at #5683 |
## Summary - Publishes the Python notebook at `docs/tutorials/sqdrift.ipynb`, covering simulator and hardware workflows. - Adds the C++ companion, build instructions, and shared input data under `docs/tutorials/assets/sqdrift/`. - Links prominently to the C++ companion from the Python tutorial and registers the tutorial in navigation. This PR supersedes Qiskit#5667. The tutorial was authored by @Shobhit21287, and his original commits and authorship are preserved. The reviewed changes are carried onto an internal branch so CI can access the repository secrets unavailable to fork PRs. --------- Co-authored-by: shobhit pandey <shobhit21287@iiitd.ac.in> Co-authored-by: Shobhit Pandey <102307364+Shobhit21287@users.noreply.github.com> Co-authored-by: abbycross <across@us.ibm.com>
Summary
This tutorial demonstrates the SqDRIFT algorithm for ground state energy estimation, applied to an N2 molecule in an STO-3G basis. SqDRIFT builds on sample-based quantum diagonalization by using a randomized qDRIFT Trotterization to prepare the states that are sampled, then diagonalizing the resulting subspace classically.
The tutorial is presented in two forms. The Python notebook is the rendered page and is written for teaching: it walks through the algorithm step by step with explanation alongside each stage. The accompanying C++ implementation in
SqDRIFT_Tutorial_CPP/shows the same workflow built directly against the Qiskit C/C++ API, for readers who need the lower-level path. The notebook points to the C++ version, and the C++ README and build instructions cover compiling it with CMake throughFetchContent, with no bash scripts required.Files
The PR adds the following files:
docs/tutorials/sqdrift/sqdrift.ipynb, which is therendered tutorial page
docs/tutorials/sqdrift/N2_sto_3g, the FCIDump input definingthe molecular system
docs/tutorials/sqdrift/SqDRIFT_Tutorial_CPP/:SqDRIFT.cpp,CMakeLists.txt,README.md,BUILD_INSTRUCTIONS.md