← Back to Pull requests

Fix bugs in the cuStateVec and cuTensorNet wrappers #3517

Closed
unknown closed this pull request without merging on Nov 03, 2026 13:24 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 08:35 UTC
Author

Follow-up to #3514, fixing bugs in the cuStateVec and cuTensorNet wrappers that its tests didn't catch, and a few older ones in cuStateVec found while reviewing it. Every fix comes with a test that fails without it.

cuStateVec:

  • expectationsOnPauliBasis returned wrong values for every operator but the first: the basis bit counts were passed as Int64 where the library reads uint32_t (⟨X₁⟩ on |00⟩ came out as 1).

  • version() decoded 1.15.0 as 11.5.0.

  • The new index bit swap scheduler and sub state vector migrator were never destroyed (their destroy functions also take the handle), leaking the migrator's device slices.

  • migrate! rejected host memory, which is what the migrator is for.

  • applyGeneralizedPermutationMatrix! read 32-bit permutations as 64-bit indices, and rejected host diagonals.

  • swapIndexBitsMultiDevice! passed the global and local bit counts the wrong way around, and Julia objects instead of library handles and device pointers. It's now tested with all sub state vectors on one device.

  • mathMode! changed pooled handles, leaking the setting into other tasks. The math mode now follows CUDACore.math_mode(), as with cuBLAS: fast math with :BFloat16x9 precision allows BF16x9 emulation, pedantic math disallows it.

  • Accessors no longer always allocate their optional extra workspace, and samplers are kept alive during library calls.
  • cuTensorNet:

  • Mixed states corrupted memory when computing them or their amplitudes, as buffers were sized without the dual modes.

  • Accessors and marginals didn't check that every projected mode gets a value, letting the library read past the array.

  • insert_tensor! defaulted the orthogonality center to a region that's only valid for one-site environments.

  • Network input tensors are now keyed by the ids the library returns, which aren't guaranteed to be sequential (they are with the current library, so this isn't covered by a test).
  • Left for later: preparations aren't invalidated when the state changes (e.g. applying an operator after creating an accessor), and configure!/attribute! pass values as is, so integer attributes need an explicit Int32.

    Diff: 269 lines (+201 / -68) across 3 files Reviewer: kshyatt Review duration: 289m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 269 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.335
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3517"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.4% (MEDIUM) · Higher = larger blast radius
    39.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.6% · Safe to merge
    15.6%