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: See also
-
__init__(max_repeats=32, max_time=None, minimize='flops', parallel=False, pre_dispatch=128)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__([max_repeats, max_time, minimize, …])Initialize self. setup(inputs, output, size_dict)Attributes
parallelpathThe best path found so far. -
path¶ The best path found so far.