@@ -74,11 +74,10 @@ SparseState apply_operator_impl_naive(bool is_antihermitian, const SparseOperato
7474 Determinant sign_mask; // a temporary determinant to store the sign mask
7575 Determinant idx; // a temporary determinant to store the index of the determinant
7676 for (const auto & [sqop, t] : sop) {
77- compute_sign_mask (sqop.cre (), sqop.ann (), sign_mask, idx);
7877 for (const auto & [det, c] : state) {
7978 if (det.faster_can_apply_operator (sqop.cre (), sqop.ann ())) {
80- auto value =
81- faster_apply_operator_to_det (det, new_det, sqop. cre (), sqop.ann (), sign_mask );
79+ auto value = faster_apply_operator_to_det (det, new_det, sqop. cre (), sqop. ann (),
80+ sqop.sign_mask () );
8281 new_terms[new_det] += value * t * c;
8382 }
8483 }
@@ -89,11 +88,10 @@ SparseState apply_operator_impl_naive(bool is_antihermitian, const SparseOperato
8988 }
9089
9190 for (const auto & [sqop, t] : sop) {
92- compute_sign_mask (sqop.ann (), sqop.cre (), sign_mask, idx);
9391 for (const auto & [det, c] : state) {
9492 if (det.faster_can_apply_operator (sqop.ann (), sqop.cre ())) {
95- auto value =
96- faster_apply_operator_to_det (det, new_det, sqop. ann (), sqop.cre (), sign_mask );
93+ auto value = faster_apply_operator_to_det (det, new_det, sqop. ann (), sqop. cre (),
94+ sqop.sign_mask () );
9795 new_terms[new_det] -= value * t * c;
9896 }
9997 }
@@ -109,18 +107,18 @@ template <bool positive>
109107void apply_operator_kernel (const auto & sop_groups, const auto & state_sorted,
110108 const auto & screen_thresh, auto & new_terms) {
111109 Determinant new_det;
112- Determinant sign_mask;
110+ // Determinant sign_mask;
113111 Determinant idx;
114112 for (const auto & [sqop_ann, sqop_group] : sop_groups) {
115113 for (const auto & [det, c] : state_sorted) {
116114 if (det.fast_a_and_b_equal_b (sqop_ann)) {
117115 // loop over the creation operators in this group
118- for (const auto & [sqop_cre, t] : sqop_group) {
116+ for (const auto & [sqop_cre, sqop_sign_mask, t] : sqop_group) {
119117 if (det.fast_a_and_b_minus_c_eq_zero (sqop_cre, sqop_ann)) {
120118 if (std::abs (c * t) > screen_thresh) {
121- compute_sign_mask (sqop_cre, sqop_ann, sign_mask, idx);
122- const auto value = faster_apply_operator_to_det (det, new_det, sqop_cre,
123- sqop_ann, sign_mask );
119+ // compute_sign_mask(sqop_cre, sqop_ann, sign_mask, idx);
120+ const auto value = faster_apply_operator_to_det (
121+ det, new_det, sqop_cre, sqop_ann, sqop_sign_mask );
124122 if constexpr (positive) {
125123 new_terms[new_det] += value * t * c;
126124 } else {
@@ -151,11 +149,12 @@ SparseState apply_operator_impl_grouped(bool is_antihermitian, const SparseOpera
151149 [](const auto & a, const auto & b) { return a.first < b.first ; });
152150
153151 // Group the operators by common annihilation strings
154- std::unordered_map<Determinant, std::vector<std::pair<Determinant, sparse_scalar_t >>,
152+ std::unordered_map<Determinant,
153+ std::vector<std::tuple<Determinant, Determinant, sparse_scalar_t >>,
155154 Determinant::Hash>
156155 sop_groups;
157156 for (const auto & [sqop, t] : sop.elements ()) {
158- sop_groups[sqop.ann ()].emplace_back (sqop.cre (), t);
157+ sop_groups[sqop.ann ()].emplace_back (sqop.cre (), sqop. sign_mask (), t);
159158 }
160159
161160 // Call the kernel to apply the operator (adding the result)
@@ -169,7 +168,7 @@ SparseState apply_operator_impl_grouped(bool is_antihermitian, const SparseOpera
169168 // Here we swap the annihilation and creation operators for the antihermitian case
170169 sop_groups.clear ();
171170 for (const auto & [sqop, t] : sop.elements ()) {
172- sop_groups[sqop.cre ()].emplace_back (sqop.ann (), t);
171+ sop_groups[sqop.cre ()].emplace_back (sqop.ann (), sqop. sign_mask (), t);
173172 }
174173
175174 // Call the kernel to apply the operator (subtracting the result)
@@ -186,18 +185,15 @@ template <bool positive>
186185void apply_operator_kernel_string (const auto & sop_groups, const auto & state_groups,
187186 const auto & screen_thresh, auto & new_terms) {
188187 Determinant new_det;
189- Determinant sign_mask;
190- Determinant idx;
191188 for (const auto & [sqop_ann_a, sqop_group] : sop_groups) {
192189 for (const auto & [det_a, state_group] : state_groups) {
193190 // can we annihilate the alfa string?
194191 if (det_a.fast_a_and_b_equal_b (sqop_ann_a)) {
195192 // loop over the creation operators in this group
196- for (const auto & [sqop_ann, sqop_cre, t] : sqop_group) {
193+ for (const auto & [sqop_ann, sqop_cre, sign_mask, t] : sqop_group) {
197194 for (const auto & [det, c] : state_group) {
198195 if (det.faster_can_apply_operator (sqop_cre, sqop_ann)) {
199196 if (std::abs (c * t) > screen_thresh) {
200- compute_sign_mask (sqop_cre, sqop_ann, sign_mask, idx);
201197 const auto value = faster_apply_operator_to_det (
202198 det, new_det, sqop_cre, sqop_ann, sign_mask);
203199 if constexpr (positive) {
@@ -232,11 +228,13 @@ SparseState apply_operator_impl_grouped_string(bool is_antihermitian, const Spar
232228 }
233229
234230 // Group the operators by common alfa annihilation strings
235- std::unordered_map<String, std::vector<std::tuple<Determinant, Determinant, sparse_scalar_t >>,
236- String::Hash>
231+ std::unordered_map<
232+ String, std::vector<std::tuple<Determinant, Determinant, Determinant, sparse_scalar_t >>,
233+ String::Hash>
237234 sop_groups;
238235 for (const auto & [sqop, t] : sop.elements ()) {
239- sop_groups[sqop.ann ().get_alfa_bits ()].emplace_back (sqop.ann (), sqop.cre (), t);
236+ sop_groups[sqop.ann ().get_alfa_bits ()].emplace_back (sqop.ann (), sqop.cre (),
237+ sqop.sign_mask (), t);
240238 }
241239
242240 // Call the kernel to apply the operator (adding the result)
@@ -250,7 +248,8 @@ SparseState apply_operator_impl_grouped_string(bool is_antihermitian, const Spar
250248 // Here we swap the annihilation and creation operators for the antihermitian case
251249 sop_groups.clear ();
252250 for (const auto & [sqop, t] : sop.elements ()) {
253- sop_groups[sqop.cre ().get_alfa_bits ()].emplace_back (sqop.cre (), sqop.ann (), t);
251+ sop_groups[sqop.cre ().get_alfa_bits ()].emplace_back (sqop.cre (), sqop.ann (),
252+ sqop.sign_mask (), t);
254253 }
255254
256255 // Call the kernel to apply the operator (subtracting the result)
0 commit comments