Skip to content

[python] Fix dynamics target evolve_async regression#4703

Open
huaweil-nv wants to merge 3 commits into
NVIDIA:mainfrom
huaweil-nv:fix-dynamics-evolve-async
Open

[python] Fix dynamics target evolve_async regression#4703
huaweil-nv wants to merge 3 commits into
NVIDIA:mainfrom
huaweil-nv:fix-dynamics-evolve-async

Conversation

@huaweil-nv

Copy link
Copy Markdown
Collaborator

Summary

  • Add the missing Python binding for the callable evolve_async overload used by the dynamics target.
  • Propagate callable failures through the async evolution future so AsyncEvolveResult.get() raises instead of terminating the worker.
  • Add regression coverage for successful dynamics async evolution, intermediate result modes, observable expectation values, and async error propagation.

How To Reproduce

This is a regression. The sample below works with CUDA-Q 0.13.0, but fails with CUDA-Q 0.14.0.

import cupy as cp
import cudaq
from cudaq import operators, Schedule

cudaq.set_target("dynamics")

steps = [0.0, 0.1]
schedule = Schedule(steps, ["t"])
hamiltonian = operators.number(0)
dimensions = {0: 2}

state = cp.zeros(2, dtype=cp.complex128)
state[1] = 1.0
initial_state = cudaq.State.from_data(state)

result = cudaq.evolve_async(
    hamiltonian,
    dimensions,
    schedule,
    initial_state,
).get()

print(result.final_state())

The dynamics target dispatches cudaq.evolve_async() by passing a Python callable to cudaq_runtime.evolve_async():

cudaq_runtime.evolve_async(lambda: evolve_dynamics(...))

The runtime bindings already covered the kernel-based async overloads, but did not expose the callable overload to Python. This caused dynamics target async evolution to fail with an incompatible function arguments error.

This PR adds a callable overload binding and updates the callable async implementation to catch exceptions from the queued callable and store them on the promise. With this behavior, failures in evolve_dynamics() are reported when users call .get(), matching normal future semantics.

Bind the callable async evolution path used by the dynamics target and propagate callable failures through the returned future.

Signed-off-by: huaweil <huaweil@nvidia.com>
@huaweil-nv huaweil-nv requested review from 1tnguyen and sacpis June 9, 2026 06:39
@copy-pr-bot

copy-pr-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@1tnguyen 1tnguyen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@1tnguyen

1tnguyen commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

/ok to test 3a29086

Command Bot: Processing...

@1tnguyen 1tnguyen enabled auto-merge June 9, 2026 06:49
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

CI Summary (push) — ✅ passed

Run #27247880606 · ✅ 6 · ⏩ 7 · ❌ 0 · ⛔ 0

Top-level jobs (13)
Job Result
binaries ⏩ skipped
build_and_test ✅ success
config_devdeps ✅ success
config_source_build ⏩ skipped
config_wheeldeps ✅ success
devdeps ✅ success
docker_image ⏩ skipped
gen_code_coverage ⏩ skipped
metadata ✅ success
python_metapackages ⏩ skipped
python_wheels ⏩ skipped
source_build ⏩ skipped
wheeldeps ✅ success
⏩ Skipped jobs (7) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
binaries
config_source_build
docker_image
gen_code_coverage
python_metapackages
python_wheels
source_build
All sub-jobs (42) — every matrix leg, with links
Job Status Link
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
CI Summary ❔ in_progress view
Configure build (devdeps) ✅ success view
Configure build (source_build) ⏩ skipped view
Configure build (wheeldeps) ✅ success view
Create CUDA Quantum installer ⏩ skipped view
Create Docker images ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create Python wheels ⏩ skipped view
Gen code coverage ⏩ skipped view
Load dependencies (amd64, gcc12) / Caching ✅ success view
Load dependencies (amd64, gcc12) / Finalize ✅ success view
Load dependencies (amd64, gcc12) / Metadata ✅ success view
Load dependencies (amd64, llvm) / Caching ✅ success view
Load dependencies (amd64, llvm) / Finalize ✅ success view
Load dependencies (amd64, llvm) / Metadata ✅ success view
Load dependencies (arm64, gcc12) / Caching ✅ success view
Load dependencies (arm64, gcc12) / Finalize ✅ success view
Load dependencies (arm64, gcc12) / Metadata ✅ success view
Load dependencies (arm64, llvm) / Caching ✅ success view
Load dependencies (arm64, llvm) / Finalize ✅ success view
Load dependencies (arm64, llvm) / Metadata ✅ success view
Load source build cache ⏩ skipped view
Load wheel dependencies (amd64, 12.6) / Caching ✅ success view
Load wheel dependencies (amd64, 12.6) / Finalize ✅ success view
Load wheel dependencies (amd64, 12.6) / Metadata ✅ success view
Load wheel dependencies (amd64, 13.0) / Caching ✅ success view
Load wheel dependencies (amd64, 13.0) / Finalize ✅ success view
Load wheel dependencies (amd64, 13.0) / Metadata ✅ success view
Load wheel dependencies (arm64, 12.6) / Caching ✅ success view
Load wheel dependencies (arm64, 12.6) / Finalize ✅ success view
Load wheel dependencies (arm64, 12.6) / Metadata ✅ success view
Load wheel dependencies (arm64, 13.0) / Caching ✅ success view
Load wheel dependencies (arm64, 13.0) / Finalize ✅ success view
Load wheel dependencies (arm64, 13.0) / Metadata ✅ success view
Prepare cache clean-up ❔ in_progress view
Retrieve PR info ✅ success view
✅ Required checks (6/6) — declared in .github/required-checks.yml for push
Required check Status Link
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view

@1tnguyen 1tnguyen added this pull request to the merge queue Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

CI Summary (merge_group) — ❌ failed

Run #27192378281 · ✅ 9 · ⏩ 2 · ❌ 2 · ⛔ 0

❌ Failed or cancelled
Job Result Link
docker_image ❌ failure view
python_wheels ❌ failure view
Top-level jobs (13)
Job Result
binaries ✅ success
build_and_test ✅ success
config_devdeps ✅ success
config_source_build ✅ success
config_wheeldeps ✅ success
devdeps ✅ success
docker_image ❌ failure
gen_code_coverage ⏩ skipped
metadata ✅ success
python_metapackages ⏩ skipped
python_wheels ❌ failure
source_build ✅ success
wheeldeps ✅ success
⏩ Skipped jobs (2) — intentionally skipped on PR builds; run on merge_group / workflow_dispatch
Job
gen_code_coverage
python_metapackages
All sub-jobs (132) — every matrix leg, with links
Job Status Link
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
CI Summary ❔ in_progress view
Configure build (devdeps) ✅ success view
Configure build (source_build) ✅ success view
Configure build (wheeldeps) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Build CUDA Quantum assets ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Minimal OpenMPI installation ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Prepare cache clean-up ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Prepare validation ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Staging ⏩ skipped view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (debian:12) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (fedora:42) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (opensuse/leap:15.5) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (redhat/ubi9:9.6) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (ubuntu:22.04) ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Build CUDA Quantum assets ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Minimal OpenMPI installation ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Prepare cache clean-up ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Prepare validation ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Staging ⏩ skipped view
Create CUDA Quantum installer (amd64, 13.0) / Validate installer (debian:12) ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Validate installer (fedora:42) ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Validate installer (opensuse/leap:15.5) ✅ success view
Create CUDA Quantum installer (amd64, 13.0) / Validate installer (ubuntu:22.04) ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Build CUDA Quantum assets ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Minimal OpenMPI installation ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Prepare cache clean-up ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Prepare validation ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Staging ⏩ skipped view
Create CUDA Quantum installer (arm64, 12.6) / Validate installer (redhat/ubi9:9.6) ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Validate installer (ubuntu:22.04) ✅ success view
Create CUDA Quantum installer (arm64, 13.0) / Build CUDA Quantum assets ✅ success view
Create CUDA Quantum installer (arm64, 13.0) / Minimal OpenMPI installation ✅ success view
Create CUDA Quantum installer (arm64, 13.0) / Prepare cache clean-up ✅ success view
Create CUDA Quantum installer (arm64, 13.0) / Prepare validation ✅ success view
Create CUDA Quantum installer (arm64, 13.0) / Staging ⏩ skipped view
Create CUDA Quantum installer (arm64, 13.0) / Validate installer (ubuntu:22.04) ✅ success view
Create Docker images (amd64) / Documentation ⏩ skipped view
Create Docker images (amd64) / Metadata ✅ success view
Create Docker images (amd64) / Prepare cache clean-up ✅ success view
Create Docker images (amd64) / Staging ⏩ skipped view
Create Docker images (amd64) / Validation ✅ success view
Create Docker images (amd64) / cuda-quantum (release) ✅ success view
Create Docker images (amd64) / cuda-quantum-dev (debug) ❌ failure view
Create Docker images (amd64) / open-mpi ⏩ skipped view
Create Docker images (arm64) / Documentation ⏩ skipped view
Create Docker images (arm64) / Metadata ✅ success view
Create Docker images (arm64) / Prepare cache clean-up ✅ success view
Create Docker images (arm64) / Staging ⛔ cancelled view
Create Docker images (arm64) / Validation ⛔ cancelled view
Create Docker images (arm64) / cuda-quantum (release) ✅ success view
Create Docker images (arm64) / cuda-quantum-dev (debug) ✅ success view
Create Docker images (arm64) / open-mpi ⏩ skipped view
Create Python metapackages ⏩ skipped view
Create Python wheels (amd64, 3.11, 12.6) / Build Python 3.11 wheel ⛔ cancelled view
Create Python wheels (amd64, 3.11, 12.6) / Prepare validation ✅ success view
Create Python wheels (amd64, 3.11, 12.6) / Staging ⛔ cancelled view
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel ⛔ cancelled view
Create Python wheels (amd64, 3.11, 13.0) / Build Python 3.11 wheel ⛔ cancelled view
Create Python wheels (amd64, 3.11, 13.0) / Prepare validation ✅ success view
Create Python wheels (amd64, 3.11, 13.0) / Staging ⛔ cancelled view
Create Python wheels (amd64, 3.11, 13.0) / Validate wheel ⛔ cancelled view
Create Python wheels (amd64, 3.13, 12.6) / Build Python 3.13 wheel ❌ failure view
Create Python wheels (amd64, 3.13, 12.6) / Prepare validation ✅ success view
Create Python wheels (amd64, 3.13, 12.6) / Staging ⏩ skipped view
Create Python wheels (amd64, 3.13, 12.6) / Validate wheel ⏩ skipped view
Create Python wheels (amd64, 3.13, 13.0) / Build Python 3.13 wheel ⛔ cancelled view
Create Python wheels (amd64, 3.13, 13.0) / Prepare validation ✅ success view
Create Python wheels (amd64, 3.13, 13.0) / Staging ⛔ cancelled view
Create Python wheels (amd64, 3.13, 13.0) / Validate wheel ⛔ cancelled view
Create Python wheels (arm64, 3.11, 12.6) / Build Python 3.11 wheel ⛔ cancelled view
Create Python wheels (arm64, 3.11, 12.6) / Prepare validation ✅ success view
Create Python wheels (arm64, 3.11, 12.6) / Staging ⛔ cancelled view
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel ⛔ cancelled view
Create Python wheels (arm64, 3.11, 13.0) / Build Python 3.11 wheel ⛔ cancelled view
Create Python wheels (arm64, 3.11, 13.0) / Prepare validation ✅ success view
Create Python wheels (arm64, 3.11, 13.0) / Staging ⛔ cancelled view
Create Python wheels (arm64, 3.11, 13.0) / Validate wheel ⛔ cancelled view
Create Python wheels (arm64, 3.13, 12.6) / Build Python 3.13 wheel ⛔ cancelled view
Create Python wheels (arm64, 3.13, 12.6) / Prepare validation ✅ success view
Create Python wheels (arm64, 3.13, 12.6) / Staging ⛔ cancelled view
Create Python wheels (arm64, 3.13, 12.6) / Validate wheel ⛔ cancelled view
Create Python wheels (arm64, 3.13, 13.0) / Build Python 3.13 wheel ⛔ cancelled view
Create Python wheels (arm64, 3.13, 13.0) / Prepare validation ✅ success view
Create Python wheels (arm64, 3.13, 13.0) / Staging ⛔ cancelled view
Create Python wheels (arm64, 3.13, 13.0) / Validate wheel ⛔ cancelled view
Gen code coverage ⏩ skipped view
Load dependencies (amd64, gcc12) / Caching ✅ success view
Load dependencies (amd64, gcc12) / Finalize ✅ success view
Load dependencies (amd64, gcc12) / Metadata ✅ success view
Load dependencies (amd64, llvm) / Caching ✅ success view
Load dependencies (amd64, llvm) / Finalize ✅ success view
Load dependencies (amd64, llvm) / Metadata ✅ success view
Load dependencies (arm64, gcc12) / Caching ✅ success view
Load dependencies (arm64, gcc12) / Finalize ✅ success view
Load dependencies (arm64, gcc12) / Metadata ✅ success view
Load dependencies (arm64, llvm) / Caching ✅ success view
Load dependencies (arm64, llvm) / Finalize ✅ success view
Load dependencies (arm64, llvm) / Metadata ✅ success view
Load source build cache (amd64, 12.6) / Caching ✅ success view
Load source build cache (amd64, 12.6) / Finalize ✅ success view
Load source build cache (amd64, 12.6) / Metadata ✅ success view
Load source build cache (amd64, 13.0) / Caching ✅ success view
Load source build cache (amd64, 13.0) / Finalize ✅ success view
Load source build cache (amd64, 13.0) / Metadata ✅ success view
Load source build cache (arm64, 12.6) / Caching ✅ success view
Load source build cache (arm64, 12.6) / Finalize ✅ success view
Load source build cache (arm64, 12.6) / Metadata ✅ success view
Load source build cache (arm64, 13.0) / Caching ✅ success view
Load source build cache (arm64, 13.0) / Finalize ✅ success view
Load source build cache (arm64, 13.0) / Metadata ✅ success view
Load wheel dependencies (amd64, 12.6) / Caching ✅ success view
Load wheel dependencies (amd64, 12.6) / Finalize ✅ success view
Load wheel dependencies (amd64, 12.6) / Metadata ✅ success view
Load wheel dependencies (amd64, 13.0) / Caching ✅ success view
Load wheel dependencies (amd64, 13.0) / Finalize ✅ success view
Load wheel dependencies (amd64, 13.0) / Metadata ✅ success view
Load wheel dependencies (arm64, 12.6) / Caching ✅ success view
Load wheel dependencies (arm64, 12.6) / Finalize ✅ success view
Load wheel dependencies (arm64, 12.6) / Metadata ✅ success view
Load wheel dependencies (arm64, 13.0) / Caching ✅ success view
Load wheel dependencies (arm64, 13.0) / Finalize ✅ success view
Load wheel dependencies (arm64, 13.0) / Metadata ✅ success view
Prepare cache clean-up ✅ success view
Retrieve PR info ✅ success view
⚠️ Required checks (20/39) — 19 missing — declared in .github/required-checks.yml for merge_group
Required check Status Link
Build and test (amd64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, llvm, openmpi) / Dev environment (Python) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (amd64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Build and test (arm64, gcc12, openmpi) / Dev environment (Debug) ✅ success view
Build and test (arm64, gcc12, openmpi) / Dev environment (Python) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Build CUDA Quantum assets ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Minimal OpenMPI installation ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (debian:12) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (fedora:42) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (opensuse/leap:15.5) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (redhat/ubi9:9.6) ✅ success view
Create CUDA Quantum installer (amd64, 12.6) / Validate installer (ubuntu:22.04) ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Build CUDA Quantum assets ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Minimal OpenMPI installation ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Validate installer (redhat/ubi9:9.6) ✅ success view
Create CUDA Quantum installer (arm64, 12.6) / Validate installer (ubuntu:22.04) ✅ success view
Create Docker images (amd64) / Documentation ⏩ skipped view
Create Docker images (amd64) / Validation ✅ success view
Create Docker images (arm64) / Validation ⛔ cancelled view
Create Python metapackages / Build Python metapackages ❔ missing
Create Python metapackages / Test Python metapackages (3.11) ❔ missing
Create Python metapackages / Test Python metapackages (3.13) ❔ missing
Create Python metapackages / Test Python metapackages (12.6, 3.11) ❔ missing
Create Python metapackages / Test Python metapackages (12.6, 3.13) ❔ missing
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel (debian:12, --user) ❔ missing
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel (debian:12) ❔ missing
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel (fedora:42, --user) ❔ missing
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel (fedora:42) ❔ missing
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel (redhat/ubi8:8.10, --user) ❔ missing
Create Python wheels (amd64, 3.11, 12.6) / Validate wheel (redhat/ubi8:8.10) ❔ missing
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel (debian:12, --user) ❔ missing
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel (debian:12) ❔ missing
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel (fedora:42, --user) ❔ missing
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel (fedora:42) ❔ missing
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel (redhat/ubi8:8.10, --user) ❔ missing
Create Python wheels (arm64, 3.11, 12.6) / Validate wheel (redhat/ubi8:8.10) ❔ missing

@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 9, 2026
Comment on lines +168 to +172
try {
p.set_value(evolveFunctor());
} catch (...) {
p.set_exception(std::current_exception());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should we apply this try/catch block in the other 2 overloads?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated. The other two evolve_async overloads now also catch worker exceptions and propagate them through the returned future.

@sacpis sacpis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @huaweil-nv.

@schweitzpgi schweitzpgi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thanks!

huaweil-nv and others added 2 commits June 10, 2026 01:44
Ensure kernel-based evolve_async overloads report worker exceptions through the returned future and clear noise state on failure.

Signed-off-by: huaweil <huaweil@nvidia.com>
@huaweil-nv

huaweil-nv commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test 3ccb768

Command Bot: Processing...

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.

4 participants