Skip to content

✨ Add DD resource limits and cancellation - #2848

Closed
burgholzer wants to merge 2 commits into
mainfrom
feat/dd-resource-control
Closed

burgholzer wants to merge 2 commits into
mainfrom
feat/dd-resource-control

Conversation

@burgholzer

@burgholzer burgholzer commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Description

Allow C++ DD callers to share an optional storage budget and cancellation token across separate packages. dd::ResourceControl accounts for DD storage and reports cancellation or a byte-budget failure through ResourceLimitExceeded. Existing package construction remains supported, with no cancellation polling or timer thread when controls are omitted.

This is the standalone DD prerequisite for native equivalence checking, rebased onto 67bd68b3a5. It preserves #2841's slab overflow guards and contains no verifier, MLIR runtime, orchestration, or Python binding changes.

Timeouts belong to the caller: one optional C++20 std::jthread waits until the deadline and requests cancellation. DD checkpoints never read the clock. The documented example uses a stop-aware wait so early completion does not wait for the deadline. The caller owns the extra thread budget and distinguishes timeout from user cancellation when needed. Both are cooperative and have no hard termination bound.

The control must outlive its users, and callers must destroy an affected package after interruption. Accounted storage includes slabs, tables, roots, and trace scratch; it excludes dense exports, sampling, serialization, statistics scratch, allocator overhead, and stack storage. Reserved bytes are neither cumulative allocation volume nor process RSS.

A DD-specific standard allocator and std::scoped_allocator_adaptor preserve nested accounting and the macOS 13.3 deployment target without introducing PMR runtime requirements. Stop sources remain mutable for libc++ and MSVC.

Performance and review:

  • Paired optimized public-DD probes use the existing 20-qubit Grover simulation and 16-qubit QFT construction. Recursive deadline polling previously added roughly 74–100% execution time; caller-owned timing removes that cost. A timer adds about 53 microseconds to the measured tiny one-qubit call, so it is created only on request. Measurements are Linux ARM results, not cross-platform guarantees or full-verifier benchmarks.
  • An LLVM specialist reviewed the connected code and optimized Clang 23 IR. The successful checkpoint path has a stop-state null check and an acquire load/bit test, with no clock read or allocation. LLVM profiling timers and task pools do not provide a better timeout mechanism. No forced inlining, batching counter, custom atomics, or additional infrastructure is introduced.

Validation on the final code:

  • All 4,113 native tests passed, including 234 DD tests and 10 resource-control tests.
  • All 64 Python DD tests passed against the rebuilt extension.
  • The new caller-timer test covers expiration and early shutdown. It fails when normal timer shutdown incorrectly requests computation cancellation. Existing recursive cancellation, shared-budget, alignment, nested storage, and cleanup tests remain intact.
  • Resource-control tests compile against libc++; repository lint and full changed-file C++ lint passed with zero findings.
  • Executable documentation and internal links passed. Both C++ examples compiled and ran; the rendered timeout section was inspected in Chrome (only the preview's missing favicon failed).
  • Final paired probes (10 interleaved samples per case, equal -O3/LTO flags, CPU 19, no concurrent builds) measured median wall times: baseline 175.13 / 117.07 ms, controls disabled 174.14 / 117.02 ms, caller timer 175.24 / 118.70 ms, and the old direct deadline 304.27 / 228.34 ms for Grover / QFT. Default-path differences are within noise; paired caller-timer overhead was 0.1% / 1.1%. Construction and destruction are included, and process CPU includes timer work. Memory accounting was unchanged.
  • One specialist Ponytail review found no remaining substantiated defects. Both rebased commits are signed and verified.

Implemented and reviewed with GPT-6 via Codex assistance. Actual macOS/MSVC execution was unavailable locally; hosted CI and human review remain pending.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@burgholzer burgholzer added feature New feature or request DD Anything related to the DD package c++ Anything related to C++ code labels Oct 25, 2026
@burgholzer burgholzer self-assigned this Oct 25, 2026
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.81481% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/dd/ResourceControl.cpp 87.5% 4 Missing ⚠️
include/mqt-core/dd/ComputeTable.hpp 87.5% 1 Missing ⚠️
include/mqt-core/dd/ResourceControl.hpp 95.2% 1 Missing ⚠️
include/mqt-core/dd/UnaryComputeTable.hpp 85.7% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@burgholzer burgholzer added this to the v4.2.0 - SC26 milestone Oct 25, 2026
@burgholzer
burgholzer force-pushed the feat/dd-resource-control branch from 78ad6aa to 0ff773e Compare October 25, 2026 16:06
@mergify mergify Bot added the conflict label Oct 25, 2026
🤖 *AI text below* 🤖

Add optional shared storage budgets, deadlines, and stop tokens to DD
packages. Preserve default call sites and the slab overflow guards.

Use a DD-specific standard allocator and scoped allocator propagation to
retain the macOS 13.3 deployment target without requiring PMR symbols.
Keep stop sources mutable as required by libc++ and MSVC.

Document cooperative checkpoints, counted storage, ownership, and package
disposal after interruption. Test shared budgets, nested storage, aligned
entries, cleanup, and cancellation without changing numerical settings.

Assisted-by: GPT-6 via Codex
Remove deadlines and clock reads from DD resource checkpoints. Keep the
optional shared byte budget and stop-token cancellation; callers that omit
resource control retain their existing behavior.

Document one optional C++20 timer per computation with stop-aware shutdown.
Test expiration and early completion, preserving all cancellation and
accounting contracts. The regression detects cancellation on normal timer
shutdown. LLVM 23 inspection confirms no clock read or allocation on the
successful checkpoint path.

Assisted-by: GPT-6 via Codex
@burgholzer
burgholzer force-pushed the feat/dd-resource-control branch from 0ff773e to 2e989aa Compare October 25, 2026 19:33
@burgholzer

Copy link
Copy Markdown
Member Author

🤖 AI text below 🤖

Closing as superseded by a simpler verifier design. Exception-based interruption of DD arithmetic and allocation conflicts with the exception-free direction of #2545. Strict recoverable allocation limits and recursive cancellation are not prerequisites for the initial verifier.

The verifier will be developed on upstream main while #2545 remains in progress. Optional timeouts will use a caller-owned timer and normal result-returning cancellation checks between DD operations and within verifier-owned loops. Cancellation and timeout yield an explicit inconclusive outcome. One expensive DD operation may delay cancellation and worker joining; no strict timeout or memory guarantee is promised.

We will defer the allocator and recursive-checkpoint plumbing, retain the existing tests and performance evidence as reference, and follow #2545's error-returning direction without depending on its unfinished implementation.

@burgholzer burgholzer closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code DD Anything related to the DD package feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant