binarize uses user-provided external indices#497
Merged
bimalgaudel merged 5 commits intomasterfrom Feb 18, 2026
Merged
Conversation
8ef8c90 to
aae5a7c
Compare
… list of external indices deduced by finding indices that appear once in the expression
aae5a7c to
cfbffcd
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enhances the handling of hyperindices (indices appearing in multiple positions) in expression evaluation by allowing users to explicitly mark indices as external (uncontracted). It also adds convenient accessor methods to ResultExpr for retrieving slots and indices, mirroring the API of the Tensor class.
Changes:
- Extended
binarize(ExprPtr)to accept optional external indices that should not be contracted - Fixed
binarize(ResultExpr)to automatically collect result indices and pass them as external to prevent improper contraction - Added
ResultExpr::slots()andResultExpr::indices()methods for convenient access to all slots and non-null indices
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| SeQuant/core/eval/eval_expr.hpp | Added external parameter to binarize(ExprPtr) and updated binarize(ResultExpr) to collect result indices as external |
| SeQuant/core/expressions/result_expr.hpp | Added slots() and indices() methods with appropriate documentation |
| SeQuant/core/expressions/tensor.hpp | Updated documentation for slots() method for consistency |
| tests/unit/test_eval_expr.cpp | Added comprehensive tests for external hyperindices functionality |
| tests/unit/test_eval_ta.cpp | Refactored helper functions and added cluster-specific RDM test demonstrating the fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bimalgaudel
approved these changes
Feb 18, 2026
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.
Author Summary
even after #495 we cannot handle hyperindices that appear once in bra and once in ker in an expression (and once in result). It's because
binarize(ResultExpr expr)did not correctly useexpr's indices to guide the deduction of the external indices (hence any index that appeared once in bra and once in ket were deemed contracted). This PR fixesbinarize(ResultExpr)to do external index deduction correctly.binarize(ExprPtr)also now accepts extra user-defined external indices (the default is same as before; external indices are those that appear once in an expression). Lastly, this PR introducedResultExpr::{slots,indices}that mirror theirTensorcounterparts.Copilot Summary
This pull request enhances the handling of external indices (hyperindices) in expression evaluation, improves the API for accessing indices in result expressions, and adds comprehensive tests for these scenarios. The changes ensure that indices appearing multiple times in expressions can be explicitly marked as external (uncontracted), and provides more convenient and safer access to slots and indices. Tests now cover these cases, including integration with the TiledArray backend.
Support for external indices in expression evaluation:
binarizefunction ineval_expr.hppnow accepts an optionalexternalparameter, allowing the caller to specify indices that should not be contracted, even if they appear multiple times in the expression. The function asserts that no null indices are passed and properly handles external indices in the expression tree.ResultExpr, the result's non-null indices are automatically collected and passed as external indices to prevent their contraction.API improvements for index and slot access:
ResultExprclass inresult_expr.hppnow providesslots()andindices()methods, returning concatenated views of all slots and all non-null indices, respectively. This makes it easier and safer to access all relevant indices for a result.Testing and integration:
test_eval_expr.cppverify correct handling of external hyperindices, including cases where indices should be kept uncontracted and placed in the auxiliary slot.test_eval_ta.cppdemonstrate thatResultExprbinarization keeps specified indices uncontracted when evaluating with the TiledArray backend. Helper functions were updated to support the new API. [1] [2] [3] [4]