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

__call__(inputs, output, size_dict[, …])

Parameters
  • input_sets (list) – List of sets that represent the lhs side of the einsum subscript

__delattr__

Implement delattr(self, name).

__dir__

Default dir() implementation.

__eq__

Return self==value.

__format__

Default object formatter.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init__([nbranch, cutoff_flops_factor, …])

Initialize self.

__init_subclass__

This method is called when a class is subclassed.

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__

Create and return a new object.

__reduce__

Helper for pickle.

__reduce_ex__

Helper for pickle.

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__

Size of object in memory, in bytes.

__str__

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

Attributes

__dict__

__doc__

__module__

__weakref__

list of weak references to the object (if defined)

path