Relabel dimension names to integers when contracting#196
Closed
mtfishman wants to merge 3 commits into
Closed
Conversation
Relabels the dimension names to integers before contracting in `mul_nameddims`, so the contraction-label bookkeeping in `TensorAlgebra.contract` runs on `Int`s rather than on the dimension-name type. A contraction's structure depends only on the equality pattern of the names, so the names are matched to integers once (shared names get the same integer), the bookkeeping runs on the integers, and the result names are recovered by position. This is aimed at `IndexName`, which carries a `UUID` and a tag dictionary and is comparatively expensive to compare and store. The previous path handed the `IndexName`s straight to `TensorAlgebra.contract`, which then re-compared them across every `setdiff` and `findfirst` pass. Matching once up front collapses that to a single name-matching pass. The speedup grows with the number of indices, from roughly 7% for two rank-2 tensors to roughly 34% for two rank-5 tensors, in the small-dimension regime where this bookkeeping is the dominant cost. The gain is dimension-independent in absolute terms, so it fades to nothing once the matrix multiply dominates. Builds directly on the type-stable contraction-label derivation in ITensor/TensorAlgebra.jl#192, which is what makes `Int` labels cheap to run through `contract`. Confined to `mul_nameddims`, with no change to `IndexName`. The in-place `mul!` paths are left as-is.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #196 +/- ##
==========================================
+ Coverage 73.77% 73.99% +0.21%
==========================================
Files 29 29
Lines 1548 1561 +13
==========================================
+ Hits 1142 1155 +13
Misses 406 406
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
Relabels the dimension names to integers before contracting in
mul_nameddims, so the contraction-label bookkeeping inTensorAlgebra.contractruns onInts rather than on the dimension-name type. A contraction's structure depends only on the equality pattern of the names, so the names are matched to integers once (shared names get the same integer), the bookkeeping runs on the integers, and the result names are recovered by position.This is aimed at
IndexName, which carries aUUIDand a tag dictionary and is comparatively expensive to compare and store. The previous path handed theIndexNames straight toTensorAlgebra.contract, which then re-compared them across everysetdiffandfindfirstpass. Matching once up front collapses that to a single name-matching pass. The speedup grows with the number of indices, from roughly 7% for two rank-2 tensors to roughly 34% for two rank-5 tensors, in the small-dimension regime where this bookkeeping is the dominant cost. The saving is a fixed per-call amount, so it fades to nothing at larger dimensions once the matrix multiply dominates.Builds directly on the type-stable contraction-label derivation in ITensor/TensorAlgebra.jl#192, which is what makes
Intlabels cheap to run throughcontract. Confined tomul_nameddims, with no change toIndexName. The in-placemul!paths are left as-is.