cotengra.slicer

Functionality for identifying indices to sliced.

Module Contents

Classes

ContractionCosts

A simplified struct for tracking the contraction costs of a path only.

SliceFinder

An object to help find the best indices to slice over in order to reduce

Attributes

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.

property size
property flops
property total_flops
property overhead
__slots__ = ('size_dict', 'contractions', 'nslices', 'original_flops', '_flops', '_sizes',...
_set_state_from(other)[source]

Copy all internal structure from another ContractionCosts.

copy()[source]

Get a copy of this ContractionCosts.

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.

remove(ix, inplace=False)[source]
__repr__()[source]

Return repr(self).

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.

plot_slicings[source]
plot_slicings_alt[source]
_maybe_default(attr, value)[source]
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.

search(max_repeats=16, temperature=None, target_size=None, target_overhead=None, target_slices=None)[source]

Repeat trial several times and return the best found so far.