-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] recursive, depth-first optimizer (#73)
* initial recursive optimal * add recursive greedy implementation * tidy up and replace optimal/greedy update docs * implement memory_limit for optimal & branch * docs and tweaks * update docs, add 'branch-1' to 'auto' mode * clean up docstrings and function signatures
- Loading branch information
Showing
15 changed files
with
584 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
================== | ||
The Branching Path | ||
================== | ||
|
||
While the ``optimal`` path is guaranteed to find the smallest estimate FLOP | ||
cost, it spends a lot of time exploring paths which are not likely to result in | ||
an optimal path. For instance, outer products are usually not advantageous | ||
unless absolutely necessary. Additionally, by trying a 'good' path first, it | ||
should be possible to quickly establish a threshold FLOP cost which can then be | ||
used to prune many bad paths. | ||
|
||
The **branching** strategy (provided by :func:`~opt_einsum.paths.branch`) does | ||
this by taking the recursive, depth-first approach of | ||
:func:`~opt_einsum.paths.optimal`, whilst also sorting potential contractions | ||
based on a heuristic cost, as in :func:`~opt_einsum.paths.greedy`. | ||
|
||
There are two main flavours: | ||
|
||
- ``optimize='branch-all'``: explore **all** inner products, starting with | ||
those that look best according to the cost heuristic. | ||
- ``optimize='branch-2'``: similar, but at each step only explore the | ||
estimated best **two** possible contractions, leading to a maximum of | ||
2^N paths assessed. | ||
|
||
In both cases, :func:`~opt_einsum.paths.branch` takes an active approach to | ||
pruning paths well before they hit the best *total* FLOP count, by comparing | ||
them to the FLOP count (times some factor) achieved by the best path at the | ||
same point in the contraction. | ||
|
||
There is also ``'branch-1'``, which, since it only explores a single path at | ||
each step does not really 'branch' - this is essentially the approach of | ||
``'greedy'``. | ||
In comparison, ``'branch-1'`` will be slower for large expressions, but for | ||
small to medium expressions it might find slightly higher quality contractions | ||
due to considering individual flop costs at each step. | ||
|
||
The default ``optimize='auto'`` mode of ``opt_einsum`` will use | ||
``'branch-all'`` for 5 or 6 tensors, though it should be able to handle | ||
12-13 tensors in a matter or seconds. Likewise, ``'branch-2'`` will be used for | ||
7 or 8 tensors, though it should be able to handle 20-22 tensors in a matter of | ||
seconds. Finally, ``'branch-1'`` will be used by ``'auto'`` for expressions of | ||
up to 14 tensors. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.