cotengra.slicer¶
Functionality for identifying indices to sliced.
Attributes¶
Classes¶
A simplified struct for tracking the contraction costs of a path only. |
|
An object to help find the best indices to slice over in order to reduce |
Module Contents¶
- cotengra.slicer.IDX_INVOLVED = 0¶
- cotengra.slicer.IDX_LEGS = 1¶
- cotengra.slicer.IDX_SIZE = 2¶
- cotengra.slicer.IDX_FLOPS = 3¶
- class cotengra.slicer.ContractionCosts(contractions, size_dict, nslices=1, original_flops=None)[source]¶
A simplified struct for tracking the contraction costs of a path only.
- Parameters:
contractions (sequence of Contraction) – The set of individual operations that make up a full contraction path.
size_dict (dict[str, int]) – The sizes of the indices involved.
nslices (int, optional) – For keeping track of the ‘multiplicity’ of this set of contractions if part of a sliced contration where indices have been removed.
- __slots__ = ('size_dict', 'contractions', 'nslices', 'original_flops', '_flops', '_sizes',...¶
- size_dict¶
- contractions¶
- _flops = 0¶
- _sizes¶
- _flop_reductions¶
- _write_reductions¶
- _where¶
- nslices = 1¶
- original_flops = None¶
- classmethod from_contraction_tree(contraction_tree, **kwargs)[source]¶
Generate a set of contraction costs from a
ContractionTree
object.
- classmethod from_info(info, **kwargs)[source]¶
Generate a set of contraction costs from a
PathInfo
object.
- property size¶
- property flops¶
- property total_flops¶
- property overhead¶
- class cotengra.slicer.SliceFinder(tree_or_info, target_size=None, target_overhead=None, target_slices=None, temperature=0.01, minimize='flops', allow_outer=True, seed=None)[source]¶
An object to help find the best indices to slice over in order to reduce the memory footprint of a contraction as much as possible whilst introducing as little extra overhead. It searches for and stores
ContractionCosts
.- Parameters:
tree_or_info (ContractionTree or opt_einsum.PathInfo) – Object describing the target full contraction to slice.
target_size (int, optional) – The target number of entries in the largest tensor of the sliced contraction. The search algorithm will terminate after this is reached.
target_slices (int, optional) – The target or minimum number of ‘slices’ to consider - individual contractions after slicing indices. The search algorithm will terminate after this is breached. This is on top of the current number of slices.
target_overhead (float, optional) – The target increase in total number of floating point operations. For example, a value of
2.0
will terminate the search just before the cost of computing all the slices individually breaches twice that of computing the original contraction all at once.temperature (float, optional) – When sampling combinations of indices, how far to randomly stray from what looks like the best (local) choice.
- info¶
- costs¶
- temperature = 0.01¶
- rng¶
- target_size = None¶
- target_overhead = None¶
- target_slices = None¶
- minimize¶
- best(k=None, target_size=None, target_overhead=None, target_slices=None)[source]¶
Return the best contraction slicing, subject to target filters.
- trial(target_size=None, target_overhead=None, target_slices=None, temperature=None)[source]¶
A single slicing attempt, greedily select indices from the popular pool, subject to the score function, terminating when any of the target criteria are met.