Generalize AsyCost#538
Open
ajay-mk wants to merge 8 commits into
Open
Conversation
Replace the hard-coded (active-occupied, virtual) pair with an ExponentMap<IndexSpace, size_t> so an AsyCost term can carry any number of index spaces. Ordering is driven by IndexSpace's own ordering. ops() now takes an ExtentMap and falls back to extent 1 for any space absent from it. Entries print via IndexSpace::base_key(). The old AsyCost(nocc, nvirt) constructors are removed in favor of AsyCost(ExponentMap, count=1).
9156e91 to
8f33716
Compare
Krzmbrzl
reviewed
Jun 2, 2026
Sort by the sum of exponents (overall polynomial / worst-case scaling) first, falling back to the existing space-by-space comparison only as a tie-breaker. Update the generalized-spaces test that asserted the old "highest space dominates" semantics.
space_counts was a non-template free function with internal linkage, living in an anonymous namespace in a header; TUs that include the header but never call it tripped -Wunneeded-internal-declaration under -Werror, which a [[maybe_unused]] attribute had been silencing. Move NodePos, space_counts, and ContractedIndexCount into sequant::detail and mark space_counts inline. The function now has external linkage with a single merged definition, so the warning is gone for the right reason and the attribute is no longer needed.
- Include aux slots (const_braketaux_indices) in space_counts so DF/THC auxiliary spaces contribute to the cost - Support batched indices: present in left, right, and result - Add eval_node tests covering PPL + density-fitting, batched-index cost, and an MRCC-like example
Contributor
There was a problem hiding this comment.
Pull request overview
This PR generalizes AsyCost from a fixed occupied/virtual (O/V) polynomial representation to a map keyed by arbitrary IndexSpace, enabling asymptotic cost and memory scalings to be expressed over any number of index spaces (including auxiliary and batching spaces).
Changes:
- Replaced O/V exponent pairs with an
IndexSpace -> exponentmap and updated printing/comparison semantics accordingly. - Updated flop/memory accounting in
eval_nodeto count indices byIndexSpace(including aux slots). - Updated and expanded unit tests to construct/compare costs via the exponent-map API and to cover generalized spaces.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
SeQuant/core/asy_cost.hpp |
Updates AsyCost public API and documentation to use IndexSpace-keyed exponent maps. |
SeQuant/core/asy_cost.cpp |
Implements generalized exponent-map storage, printing, ordering, and numeric evaluation via extents. |
SeQuant/core/eval/eval_node.hpp |
Updates flop/memory estimation to count indices per IndexSpace (including auxiliary indices). |
SeQuant/core/eval/cache_manager.hpp |
Adjusts documentation to match generalized AsyCost semantics. |
tests/unit/test_asy_cost.cpp |
Refactors tests for new API and adds coverage for >2 spaces and missing extents behavior. |
tests/unit/test_eval_node.cpp |
Updates expected costs to the new API and adds tests for density-fitting, batching, and MR-like examples. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Drop the unused counts(NodePos) accessor and add comments
2ffed47 to
5a94615
Compare
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.
Generalize
AsyCostfrom O/V to arbitraryIndexSpaceAsyCostpreviously hard-coded asymptotic cost as a polynomial in exactly two orbital spaces: occupied (O) and virtual (V), with each entry storing a fixed (occ, virt) exponent pair.This PR replaces the fixed O/V representation with a general map from
IndexSpaceto integer exponent, so a cost term is now a rational multiplier times a product of arbitrary space sizes raised to integer powersChanges
IndexSpaceto exponent instead of fixed occupied/virtual powers, so any number of spaces is supported.ops()takes a map of space extents instead of two numbers.IndexSpace.test_asy_cost.cppandtest_eval_node.cppupdated to construct costs via the exponent-map API, and new tests are added with generalIndexSpaces.