Skip to content

(Anti)symmetrization operators include normalization to ensure idempotency#464

Merged
evaleev merged 31 commits intomasterfrom
azam/feature/addNormFactor
Jan 26, 2026
Merged

(Anti)symmetrization operators include normalization to ensure idempotency#464
evaleev merged 31 commits intomasterfrom
azam/feature/addNormFactor

Conversation

@ABesharat
Copy link
Contributor

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_op
symmetrize_expr
S_maps
closed_shell_CC_spintrace_v1 and v2
column_symmetrize_ta and btas
particle_antisymmetrize_ta and btas

and their corresponding tests (test_spin.cpp, test_eval_ta.cpp, test_eval_btas.cpp)

@ABesharat ABesharat force-pushed the azam/feature/addNormFactor branch from 9c92c78 to 88535ca Compare January 21, 2026 17:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_S function 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.

@evaleev evaleev force-pushed the azam/feature/addNormFactor branch from e2b4ef7 to a18d5f6 Compare January 25, 2026 21:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@evaleev evaleev changed the title Azam/feature/add-normalization-factor (Anti)symmetrization operators include normalization to ensure idempotency Jan 26, 2026
@evaleev evaleev requested a review from Copilot January 26, 2026 00:21
@evaleev evaleev marked this pull request as ready for review January 26, 2026 00:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after "4" in the expected result string. Should be "4 " for consistency.

Suggested change
"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 "

Copilot uses AI. Check for mistakes.
"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"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after "2" in the expected result string. Should be "2 " for consistency.

Suggested change
"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 "

Copilot uses AI. Check for mistakes.
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"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after "2" in the expected result string. Should be "2 " for consistency.

Suggested change
"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 "

Copilot uses AI. Check for mistakes.
Comment on lines +1141 to +1142
"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 "
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{...".

Copilot uses AI. Check for mistakes.
"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"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after "2" in the expected result string. Should be "2 " for consistency with the surrounding lines.

Copilot uses AI. Check for mistakes.
"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"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing spaces after numbers in the expected result string. Should be "4 " instead of "4" for consistency.

Suggested change
"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 "

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +35
#include <range/v3/view/interface.hpp>
#include <range/v3/view/transform.hpp>
#include <range/v3/view/view.hpp>
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1626 to +1627
Tensor A = expr.is<Sum>() ? expr->at(0)->at(0)->as<Tensor>()
: expr->at(0)->as<Tensor>();
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +1105 to +1106
"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"
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@evaleev evaleev merged commit 1660274 into master Jan 26, 2026
28 checks passed
@evaleev evaleev deleted the azam/feature/addNormFactor branch January 26, 2026 02:22
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.

3 participants

Comments