Add Hamiltonian energy optimization example with SPSA#63
Open
ssmswapnil wants to merge 1 commit into
Open
Conversation
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.
Summary
This adds an
examples/folder with a script that shows how to run a Hamiltonian energy optimization loop using ionq-core's typed models end to end.The idea is pretty straightforward — build the quantum function payload, submit it with
create_job, wait for the result, pull out the energy, and let an optimizer tweak the parameters. Rinse and repeat until we converge. I used SPSA as the optimizer since it handles noisy objectives well and only needs two function evals per step. It's written from scratch so we don't pull in scipy or anything extra.For the problem I went with a simple two-qubit transverse-field Ising Hamiltonian (
-ZZ - 0.5(XI + IX)) and a Ry/Rz + CNOT ansatz with 4 params in OpenQASM 3. Runs against the free simulator.Also added an
examples/README.mdwith setup instructions and linked it from the main README.Closes #58
Test plan
Ran all three checks the issue asks for:
ruff check examples/ README.md— cleanruff format --check examples/— cleanty check examples/— cleanAlso sanity-checked that the payload serializes to the right JSON structure. Can't actually run it in CI since there's no API key, but that's expected per the issue.