Skip to content

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

@splch

Description

@splch

Background

IonQ's Hosted Hybrid Service exposes Quantum Functions — e.g. Hamiltonian-energy evaluation (ansatz + Hamiltonian + params → energy). It's part of the public API, and ionq-core already ships typed models: QuantumFunctionJobCreationPayload (a create_job body variant) built from HamiltonianEnergyInput, Ansatz, and HamiltonianPauliTerm (under ionq_core.models). It runs on the free simulator, but there's no example and no examples/ directory.

What to build

An examples/ script that builds a Hamiltonian-energy quantum function with the typed models, evaluates the energy via create_job + wait_for_job, and optimizes the parameters to minimize it with a client-side optimizer.

Keep the Hamiltonian, ansatz, and optimizer open-ended (SPSA, COBYLA, scipy.optimize, or hand-rolled) — the point is the end-to-end variational shape, not a specific algorithm. Structure: an energy callback (params → submit → wait_for_job → energy) driven by the optimizer, printing per-iteration energy and the final optimal parameters, against the free simulator.

Definition of done

  • examples/ script and examples/README.md (setup: pip install ionq-core, export IONQ_API_KEY=...), linked from the top-level README.md.
  • Builds the quantum function with the typed ionq_core.models payloads, submits via create_job, polls with wait_for_job, and minimizes the energy; module docstring states the chosen Hamiltonian / ansatz / optimizer.
  • Uses public API (IonQClient, create_job, wait_for_job, the quantum-function models); SPDX header (AGENTS.md).
  • uv run ruff check, uv run ruff format --check, and uv run ty check examples/ pass. (Needn't run in CI — no API key — but must lint and type-check.)

Notes

httpx-only; apiKey auth, not Bearer. Don't add an optimizer (e.g. scipy) to the core package's runtime deps — keep it example-only. References: Hosted Hybrid guide, the typed models under ionq_core/models/ (quantum_function_job_creation_payload.py, hamiltonian_energy_input.py, ansatz.py, hamiltonian_pauli_term.py), and polling in ionq_core/polling.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestunitaryHACK26unitaryHACK 2026 bounty issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions