opt_einsum.path_random.RandomOptimizer¶
- class opt_einsum.path_random.RandomOptimizer(max_repeats=32, max_time=None, minimize='flops', parallel=False, pre_dispatch=128)[source]¶
Base class for running any random path finder that benefits from repeated calling, possibly in a parallel fashion. Custom random optimizers should subclass this, and the
setupmethod should be implemented with the following signature:def setup(self, inputs, output, size_dict): # custom preparation here ... return trial_fn, trial_args
Where
trial_fnitself should have the signature:def trial_fn(r, *trial_args): # custom computation of path here return ssa_path, cost, size
Where
ris the run number and could for example be used to seed a random number generator. SeeRandomGreedyfor an example.- Parameters:
max_repeats (int, optional) – The maximum number of repeat trials to have.
max_time (float, optional) – The maximum amount of time to run the algorithm for.
minimize ({‘flops’, ‘size’}, optional) – Whether to favour paths that minimize the total estimated flop-count or the size of the largest intermediate created.
parallel ({bool, int, or executor-pool like}, optional) – Whether to parallelize the random trials, by default
False. IfTrue, use aconcurrent.futures.ProcessPoolExecutorwith the same number of processes as cores. If an integer is specified, use that many processes instead. Finally, you can supply a custom executor-pool which should have an API matching that of the python 3 standard library moduleconcurrent.futures. Namely, asubmitmethod that returnsFutureobjects, themselves withresultandcancelmethods.pre_dispatch (int, optional) – If running in parallel, how many jobs to pre-dispatch so as to avoid submitting all jobs at once. Should also be more than twice the number of workers to avoid under-subscription. Default: 128.
- Variables:
path (list[tuple[int]]) – The best path found so far.
costs (list[int]) – The list of each trial’s costs found so far.
sizes (list[int]) – The list of each trial’s largest intermediate size so far.
See also
- __init__(max_repeats=32, max_time=None, minimize='flops', parallel=False, pre_dispatch=128)[source]¶
Methods
__call__(inputs, output, size_dict, memory_limit)Call self as a function.
__del__()__delattr__(name, /)Implement delattr(self, name).
__dir__()Default dir() implementation.
__eq__(value, /)Return self==value.
__format__(format_spec, /)Default object formatter.
__ge__(value, /)Return self>=value.
__getattribute__(name, /)Return getattr(self, name).
__getstate__()Helper for pickle.
__gt__(value, /)Return self>value.
__hash__()Return hash(self).
__init__([max_repeats, max_time, minimize, ...])__init_subclass__This method is called when a class is subclassed.
__le__(value, /)Return self<=value.
__lt__(value, /)Return self<value.
__ne__(value, /)Return self!=value.
__new__(**kwargs)__reduce__()Helper for pickle.
__reduce_ex__(protocol, /)Helper for pickle.
__repr__()Return repr(self).
__setattr__(name, value, /)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().
_cancel_futures()_check_args_against_first_call(inputs, ...)Utility that stateful optimizers can use to ensure they are not called with different contractions across separate runs.
_gen_results_parallel(repeats, trial_fn, args)Lazily generate results from an executor without submitting all jobs at once.
setup(inputs, output, size_dict)Attributes
__annotations____dict____doc____module____weakref__list of weak references to the object
parallelpathThe best path found so far.