Compensated summation for cpu_statevec_anyCtrlAnyTargDenseMatr_sub (#598) - [unitaryHACK]#791
Open
mk0dz wants to merge 1 commit into
Open
Compensated summation for cpu_statevec_anyCtrlAnyTargDenseMatr_sub (#598) - [unitaryHACK]#791mk0dz wants to merge 1 commit into
mk0dz wants to merge 1 commit into
Conversation
…uEST-Kit#598) The dense-matrix subroutine's inner reduction is liable to catastrophic cancellation for many target qubits. This adds an opt-in compensated path (-DQUEST_COMPENSATE_DENSEMATR_SUM=ON); base_qcomp's operators are plain IEEE arithmetic so the compensation is honoured directly. Single-CPU benchmarks (fp32/fp64/fp80): relative error improves ~25-58x at 12 targets, the benefit growing with target count; runtime cost is ~2-3.3x (compute-bound) falling to ~1.8x in the large-statevector regime. Left opt-in (off by default) per that trade-off.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional compensated-summation path to improve numerical accuracy in CPU dense-matrix target evolution.
The implementation introduces a thinner reduction in
cpu_statevec_anyCtrlAnyTargDenseMat_sub(), controlled by the compile-time flag:The feature is disabled by default to preserve existing performance characteristics.
Implementation Notes
cpu_qcompvariable and writes it back once after the reduction.Files Changed
quest/src/cpu/cpu_subroutines.cppquest/src/cpu/CMakeLists.txtAccuracy & Performance
Benchmarked against a
__float128reference using the naive vs. compensated Kahan implementation across all three floating-point precisions.Observations
Validation
All existing dense
CompMatrtests pass for both compensated and uncompensated builds, including:applyCompMatrTest results:
Rationale for Default-Off
The improvement is primarily beneficial for large or ill-conditioned matrices, while introducing a consistent ~2–3× runtime overhead.
Keeping the feature disabled by default preserves current performance expectations while allowing users to opt in when higher numerical accuracy is required.
Future Work
A possible alternative is pairwise summation, which offers:
O(log N)This can be evaluated separately in a future PR.
I also acknowledge claude for guiding me thorough it.
/claim #598
Closes #598.