opt_einsum.paths.BranchBound

class opt_einsum.paths.BranchBound(nbranch=None, cutoff_flops_factor=4, minimize='flops', cost_fn='memory-removed')[source]

Explores possible pair contractions in a depth-first recursive manner like the optimal approach, but with extra heuristic early pruning of branches as well sieving by memory_limit and the best path found so far. Returns the lowest cost path. This algorithm still scales factorially with respect to the elements in the list input_sets if nbranch is not set, but it scales exponentially like nbranch**len(input_sets) otherwise.

Parameters:
  • nbranch (None or int, optional) – How many branches to explore at each contraction step. If None, explore all possible branches. If an integer, branch into this many paths at each step. Defaults to None.
  • cutoff_flops_factor (float, optional) – If at any point, a path is doing this much worse than the best path found so far was, terminate it. The larger this is made, the more paths will be fully explored and the slower the algorithm. Defaults to 4.
  • minimize ({‘flops’, ‘size’}, optional) – Whether to optimize the path with regard primarily to the total estimated flop-count, or the size of the largest intermediate. The option not chosen will still be used as a secondary criterion.
  • cost_fn (callable, optional) – A function that returns a heuristic ‘cost’ of a potential contraction with which to sort candidates. Should have signature cost_fn(size12, size1, size2, k12, k1, k2).
__init__(nbranch=None, cutoff_flops_factor=4, minimize='flops', cost_fn='memory-removed')[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([nbranch, cutoff_flops_factor, …]) Initialize self.

Attributes

path