(Anti)symmetrization operators include normalization to ensure idempotency#464
(Anti)symmetrization operators include normalization to ensure idempotency#464
Conversation
…azam/feature/addNormFactor
…azam/feature/addNormFactor
…azam/feature/addNormFactor
9c92c78 to
88535ca
Compare
…mFactor # Conflicts: # SeQuant/core/eval/result.hpp
There was a problem hiding this comment.
Pull request overview
This pull request fixes the normalization factor implementation for A (antisymmetrizer) and S (symmetrizer) operators to align with the SeQuant manuscript. The key changes are:
Purpose:
- S operators now have normalization factor
nf = 1/factorial(ket_size) - A operators now have normalization factor
nf = 1/(factorial(bra_size) * factorial(ket_size))
Changes:
- Updated symbolic expansion functions (
expand_A_op,symmetrize_expr,S_maps) to apply the new normalization factors - Updated numerical evaluation functions (
column_symmetrize_ta/btas,particle_antisymmetrize_ta/btas) to apply matching normalization - Updated the
tensor::A()function to pre-multiply by factorial to compensate for normalization in expansion - Updated all affected tests to reflect the new expected values
- Removed the
factorize_Sfunction from the codebase - Removed unnecessary normalization code from
closed_shell_CC_spintrace_v2
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/test_spin.cpp | Updated test expectations for A and S operator expansions with new normalization factors; added new test cases for symmetrization |
| tests/unit/test_mbpt.cpp | Updated latex output expectations for operator tensor forms; added test for S operator action |
| tests/unit/test_eval_ta.cpp | Updated numerical tests for antisymmetrization and symmetrization with correct normalization factors |
| tests/unit/test_eval_btas.cpp | Updated numerical tests for antisymmetrization with correct normalization factors |
| SeQuant/domain/mbpt/spin.hpp | Removed declaration of factorize_S function |
| SeQuant/domain/mbpt/spin.cpp | Added normalization factor application in expand_A_op, symmetrize_expr, and S_maps; removed factorize_S implementation; removed redundant normalization from closed_shell_CC_spintrace_v2 |
| SeQuant/domain/mbpt/op.cpp | Added factorial multiplication to tensor::A() function; added spinfree basis validation to tensor::S() |
| SeQuant/core/eval/backends/tiledarray/result.hpp | Added normalization factor application in column_symmetrize_ta and particle_antisymmetrize_ta |
| SeQuant/core/eval/backends/btas/result.hpp | Added normalization factor application in column_symmetrize_btas and particle_antisymmetrize_btas |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e2b4ef7 to
a18d5f6
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "g{a_1,a_3;a_4,a_5}:N-C-S * t{a_2,a_4,a_5;i_3,i_1,i_2}:N-C-S - 4 " | ||
| " 8 g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_3,i_1,i_2}:N-C-S + " | ||
| "2" | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4" |
There was a problem hiding this comment.
Missing space after "4" in the expected result string. Should be "4 " for consistency.
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4" | |
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4 " |
| "g{a_1,a_3;a_4,a_5}:N-C-S * t{a_2,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4 " | ||
| "g{a_2,a_3;a_4,a_5}:N-C-S * t{a_1,a_4,a_5;i_3,i_2,i_1}:N-C-S + 2 " | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_2,i_3}:N-C-S + 2 " | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_2,i_3}:N-C-S + 2" |
There was a problem hiding this comment.
Missing space after "2" in the expected result string. Should be "2 " for consistency.
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_2,i_3}:N-C-S + 2" | |
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_2,i_3}:N-C-S + 2 " |
| EquivalentTo( | ||
| "8 g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_3,i_1,i_2}:N-C-S + " | ||
| "2 " | ||
| "8 g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_3,i_1,i_2}:N-C-S + 2" |
There was a problem hiding this comment.
Missing space after "2" in the expected result string. Should be "2 " for consistency.
| "8 g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_3,i_1,i_2}:N-C-S + 2" | |
| "8 g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_3,i_1,i_2}:N-C-S + 2 " |
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_2,i_1,i_3}:N-C-S - 4" | ||
| "g{a_2,a_3;a_4,a_5}:N-C-S * t{a_1,a_4,a_5;i_2,i_1,i_3}:N-C-S+ 2 " |
There was a problem hiding this comment.
Missing spaces after numbers in multiple places in the expected result string. Lines 1141, 1142, 1145, and 1146 are missing spaces after "4". This should be consistent with proper spacing like "4 g{..." instead of "4g{...".
| "g{a_1,a_3;a_4,a_5}:N-C-S * t{a_2,a_4,a_5;i_3,i_1,i_2}:N-C-S - 4 " | ||
| " 8 g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_3,i_1,i_2}:N-C-S + " | ||
| "2" | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4" |
There was a problem hiding this comment.
Missing space after "2" in the expected result string. Should be "2 " for consistency with the surrounding lines.
| "g{a_2,a_3;a_4,a_5}:N-C-S * t{a_1,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4 " | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_3,i_2}:N-C-S - 4 " | ||
| "g{a_2,a_3;a_4,a_5}:N-C-S * t{a_1,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4" | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_3,i_2}:N-C-S - 4" |
There was a problem hiding this comment.
Missing spaces after numbers in the expected result string. Should be "4 " instead of "4" for consistency.
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_3,i_2}:N-C-S - 4" | |
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_1,i_3,i_2}:N-C-S - 4 " |
| #include <range/v3/view/interface.hpp> | ||
| #include <range/v3/view/transform.hpp> | ||
| #include <range/v3/view/view.hpp> |
There was a problem hiding this comment.
The added includes for range-v3 view headers (interface.hpp, transform.hpp, view.hpp) on lines 33-35 may be redundant since line 32 already includes "range/v3/all.hpp" which should transitively include these headers. Consider removing these specific includes to reduce compilation dependencies unless they're needed for some specific reason.
| Tensor A = expr.is<Sum>() ? expr->at(0)->at(0)->as<Tensor>() | ||
| : expr->at(0)->as<Tensor>(); |
There was a problem hiding this comment.
The use of 'expr.is()' without checking if expr is nullptr could be problematic. Consider using 'expr->is()' for consistency with the rest of the codebase, or ensure that expr is never null at this point.
| "2" | ||
| "g{a_1,a_2;a_4,a_5}:N-C-S * t{a_3,a_4,a_5;i_2,i_3,i_1}:N-C-S - 4" |
There was a problem hiding this comment.
There is inconsistent spacing in this expected result string. Line 1105 has "2" at the end without a space after it, while other lines have proper spacing. This should be "2 " or aligned consistently with the rest of the string for better readability.
This PR fixed normalization factor (nf) issue (symbolically and numerically) for A and S operators, making them consistent with the SeQuant manuscript.
now S has nf = 1/factorial(ket_size)
and A has nf = 1/(factorial(ket_size) * factorial(bra_size))
Affected functions:
expand_A_opsymmetrize_exprS_mapsclosed_shell_CC_spintrace_v1 and v2column_symmetrize_taand btasparticle_antisymmetrize_taand btasand their corresponding tests (test_spin.cpp, test_eval_ta.cpp, test_eval_btas.cpp)