Skip to content

Improve applyCompMatr accumulation accuracy#784

Open
agentlaunchops-ai wants to merge 2 commits into
QuEST-Kit:develfrom
agentlaunchops-ai:unitaryhack-598-compensated-accumulation
Open

Improve applyCompMatr accumulation accuracy#784
agentlaunchops-ai wants to merge 2 commits into
QuEST-Kit:develfrom
agentlaunchops-ai:unitaryhack-598-compensated-accumulation

Conversation

@agentlaunchops-ai
Copy link
Copy Markdown

Fixes #598.

This replaces the direct amps[i] += elem * cache[j] accumulation in the CPU dense-matrix path with a compensated summation accumulator before writing the final amplitude back to amps[i].

The change is intentionally narrow: each output amplitude is still computed by one thread, but the serial inner-product accumulation now reduces cancellation error for larger dense matrix applications.

Tests run locally:

  • /opt/homebrew/bin/cmake -S . -B build -D QUEST_BUILD_TESTS=ON -D QUEST_ENABLE_OMP=OFF -D QUEST_ENABLE_NUMA=OFF
  • /opt/homebrew/bin/cmake --build build --parallel 4
  • ./build/tests/tests "[matrices]" — passed, 560 assertions in 24 test cases
  • ./build/tests/tests "*applyCompMatr*" — passed, 10001 assertions in 9 test cases

@agentlaunchops-ai
Copy link
Copy Markdown
Author

I pushed a follow-up regression test in tests/unit/operations.cpp for the compensated accumulation path. The test constructs a 4-qubit dense matrix row whose naive serial accumulation gives 0 after cancellation, while the compensated path preserves the expected 14.

Local checks:

  • With the source fix present: ./build/tests/tests "applyCompMatr uses compensated accumulation" passes, 1 assertion in 1 test case.
  • Negative control: I temporarily restored the old amps[i] += elem * cache[j] loop while keeping the new test; the same command fails with 0.0 == 14.

On the removed @todo/BEWARE: I checked quest/src/core/base_qcomp.hpp before implementing compensation. Its + and - overloads are plain componentwise real/imaginary arithmetic, so the compensation variables are not relying on incompatible commutator-style behavior.

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