Skip to content

Use compensated summation in applyCompMatr CPU path#788

Open
qdwg wants to merge 1 commit into
QuEST-Kit:develfrom
qdwg:unitaryhack-compensated-apply-comp-matr
Open

Use compensated summation in applyCompMatr CPU path#788
qdwg wants to merge 1 commit into
QuEST-Kit:develfrom
qdwg:unitaryhack-compensated-apply-comp-matr

Conversation

@qdwg

@qdwg qdwg commented Jun 11, 2026

Copy link
Copy Markdown

Summary

  • Adds explicit component-wise compensated summation in cpu_statevec_anyCtrlAnyTargDenseMatr_sub().
  • Targets the dynamic many-target dense-matrix path used by applyCompMatr/left-right multiplication APIs.
  • Replaces the old per-term amps[i] += elem * cache[j] accumulation with a local sum plus Neumaier compensation for real and imaginary components.

Validation

Built and tested locally on macOS with CPU-only, non-OpenMP configuration. The local CommandLineTools default SDK did not expose C++ standard library headers, so I had to point CMake at the installed MacOSX15.5 SDK C++ include path.

SDK=/Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk
SDKROOT=$SDK cmake -S . -B build-macos155 \
  -DQUEST_BUILD_TESTS=ON \
  -DQUEST_ENABLE_OMP=OFF \
  -DQUEST_ENABLE_MPI=OFF \
  -DQUEST_ENABLE_CUDA=OFF \
  -DQUEST_ENABLE_HIP=OFF \
  -DCMAKE_OSX_SYSROOT=$SDK \
  -DCMAKE_CXX_FLAGS="-isystem $SDK/usr/include/c++/v1" \
  -DCMAKE_BUILD_TYPE=Release
SDKROOT=$SDK cmake --build build-macos155 --target tests -j4
SDKROOT=$SDK ./build-macos155/tests/tests "leftapplyCompMatr,rightapplyCompMatr"

Result: all tests passed, 5879 assertions in 2 test cases.

Notes

  • This is intentionally scoped to the CPU many-target dense-matrix subroutine mentioned in Improve applyCompMatr accuracy with compensated summation #598.
  • I did not include broad benchmark claims in this PR; the change improves numerical summation behavior but adds arithmetic in the hot loop, so maintainers may want to profile the desired regimes.

AI disclosure

This contribution was developed with assistance from OpenAI Codex. I reviewed the patch and ran the validation above before submitting.

Closes #598.

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.

1 participant