Skip to content

Add Hamiltonian energy optimization example with SPSA#63

Open
ssmswapnil wants to merge 1 commit into
ionq:mainfrom
ssmswapnil:examples/hamiltonian-energy-optimization
Open

Add Hamiltonian energy optimization example with SPSA#63
ssmswapnil wants to merge 1 commit into
ionq:mainfrom
ssmswapnil:examples/hamiltonian-energy-optimization

Conversation

@ssmswapnil
Copy link
Copy Markdown

@ssmswapnil ssmswapnil commented Jun 7, 2026

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.md with 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 — clean
  • ruff format --check examples/ — clean
  • ty check examples/ — clean

Also 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.

@ssmswapnil ssmswapnil requested a review from a team as a code owner June 7, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an examples/ quantum-function workload (Hamiltonian energy) with parameter optimization

1 participant