Skip to content

[python] Surface dem_from_kernel errors as RuntimeError#4676

Open
mitchdz wants to merge 2 commits into
mainfrom
fix-dem-noncliff-macos
Open

[python] Surface dem_from_kernel errors as RuntimeError#4676
mitchdz wants to merge 2 commits into
mainfrom
fix-dem-noncliff-macos

Conversation

@mitchdz

@mitchdz mitchdz commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

cudaq.dem_from_kernel runs the kernel under a dlopen'd stim analysis plugin. A non-Clifford gate makes Stim throw std::runtime_error from inside that plugin; on macOS the exception escapes uncaught at the binding boundary and the process aborts (SIGABRT / "Fatal Python error: Aborted"), crashing the test worker instead of raising in Python.

Wrap the call in dem_from_kernel_impl and re-throw a fresh runtime_error owned by this module (with a catch-all fallback) so the error reliably surfaces as a Python RuntimeError on all platforms. Mirrors the catch-and-rethrow guard already used at other binding boundaries (e.g. runtime/cudaq/realtime.cpp).

Fixes the macOS 'Python metapackage validation' failure on test_dem_from_kernel.py::test_non_clifford_raises.

See https://github.com/NVIDIA/cuda-quantum/actions/runs/26986910544/job/79748077581

[gw0] node down: Not properly terminated
Thread 0x000000016e587000 (most recent call first):
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 534 in read
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 567 in from_io
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 1160 in _thread_receiver
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 341 in run
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 411 in _perform_spawn

Current thread 0x00000001f300e2c0 (most recent call first):
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/cudaq/runtime/dem.py", line 52 in dem_from_kernel
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/cudaq/util/trace.py", line 64 in wrapper
  File "/Users/runner/work/cuda-quantum/cuda-quantum/build/validation/tests/analysis/test_dem_from_kernel.py", line 165 in test_non_clifford_raises
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/python.py", line 166 in pytest_pyfunc_call
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/python.py", line 1720 in runtest
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/runner.py", line 179 in pytest_runtest_call
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/runner.py", line 245 in <lambda>
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/runner.py", line 353 in from_call
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/runner.py", line 244 in call_and_report
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/runner.py", line 137 in runtestprotocol
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/runner.py", line 118 in pytest_runtest_protocol
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/xdist/remote.py", line 227 in run_one_test
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/xdist/remote.py", line 206 in pytest_runtestloop
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/main.py", line 372 in _main
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/main.py", line 318 in wrap_session
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/_pytest/main.py", line 365 in pytest_cmdline_main
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/xdist/remote.py", line 427 in <module>
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 1291 in executetask
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 341 in run
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 411 in _perform_spawn
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 389 in integrate_as_primary_thread
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 1273 in serve
  File "/Users/runner/.venv/cudaq-validation/lib/python3.12/site-packages/execnet/gateway_base.py", line 1806 in serve
  File "<string>", line 8 in <module>
  File "<string>", line 1 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator, scipy._lib._ccallback_c, scipy.special._ufuncs_cxx, scipy.special._ellip_harm_2, scipy.special._special_ufuncs, scipy.special._gufuncs, scipy.special._ufuncs, scipy.special._specfun, scipy.special._comb, scipy.linalg._fblas, scipy.linalg._flapack, _cyutility, scipy._cyutility, scipy.linalg.cython_lapack, scipy.linalg._cythonized_array_utils, scipy.linalg._solve_toeplitz, scipy.linalg._decomp_lu_cython, scipy.linalg._matfuncs_schur_sqrtm, scipy.linalg._matfuncs_expm, scipy.linalg._linalg_pythran, scipy.linalg.cython_blas, scipy.linalg._decomp_update, scipy.sparse._sparsetools, _csparsetools, scipy.sparse._csparsetools, scipy.integrate._odepack, scipy.integrate._quadpack, scipy.integrate._vode, scipy.integrate._dop, scipy.integrate._lsoda, scipy.sparse.linalg._dsolve._superlu, scipy.sparse.linalg._eigen.arpack._arpack, scipy.sparse.linalg._propack._spropack, scipy.sparse.linalg._propack._dpropack, scipy.sparse.linalg._propack._cpropack, scipy.sparse.linalg._propack._zpropack, scipy.optimize._group_columns, scipy._lib.messagestream, scipy.optimize._trlib._trlib, scipy.optimize._lbfgsb, _moduleTNC, scipy.optimize._moduleTNC, scipy.optimize._slsqplib, scipy.optimize._minpack, scipy.optimize._lsq.givens_elimination, scipy.optimize._zeros, scipy._lib._uarray._uarray, scipy.linalg._decomp_interpolative, scipy.optimize._bglu_dense, scipy.optimize._lsap, scipy.spatial._ckdtree, scipy.spatial._qhull, scipy.spatial._voronoi, scipy.spatial._hausdorff, scipy.spatial._distance_wrap, scipy.spatial.transform._rotation, scipy.spatial.transform._rigid_transform, scipy.optimize._direct (total: 70)
[gw0] [  9%] FAILED ../../../../../../../Users/runner/work/cuda-quantum/cuda-quantum/build/validation/tests/analysis/test_dem_from_kernel.py::test_non_clifford_raises 

…orting

cudaq.dem_from_kernel runs the kernel under a dlopen'd `stim` analysis
plugin. A non-Clifford gate makes Stim throw std::runtime_error from
inside that plugin; on macOS the exception escapes uncaught at the
binding boundary and the process aborts (SIGABRT / "Fatal Python error:
Aborted"), crashing the test worker instead of raising in Python.

Wrap the call in dem_from_kernel_impl and re-throw a fresh runtime_error
owned by this module (with a catch-all fallback) so the error reliably
surfaces as a Python RuntimeError on all platforms. Mirrors the
catch-and-rethrow guard already used at other binding boundaries
(e.g. runtime/cudaq/realtime.cpp).

Fixes the macOS 'Python metapackage validation' failure on
test_dem_from_kernel.py::test_non_clifford_raises.

Signed-off-by: mdzurick <mitch_dz@hotmail.com>
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

CI Summary (push) — ✅ passed

Run #27035095469 · ✅ 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

@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:36 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:44 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:44 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:44 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:44 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:44 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:44 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:45 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:51 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:51 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:51 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 16:52 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 17:39 — with GitHub Actions Inactive
@mitchdz mitchdz temporarily deployed to ghcr-deployment June 5, 2026 17:39 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 17:44 — with GitHub Actions Inactive

@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 👍

Review follow-up: the catch-all guard added previously also intercepted
nanobind::python_error (which derives from std::runtime_error) thrown by
marshal_and_launch_module during argument marshalling/launch, flattening
a real Python error to a generic RuntimeError (losing its type/traceback)
or mislabeling it as a Clifford error.

Catch nanobind::python_error first and re-throw it unchanged so genuine
Python exceptions propagate intact; only foreign C++ exceptions fall
through to the RuntimeError translation.

Signed-off-by: mdzurick <mitch_dz@hotmail.com>
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
@bettinaheim bettinaheim temporarily deployed to ghcr-deployment June 5, 2026 19:05 — with GitHub Actions Inactive
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.

3 participants