-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable multiple parallel seed trials for SabreSwap (#8572)
* Enable multiple parallel seed trials for SabreSwap The SabreSwap algorithm's output is quite linked to the random seed used to run the algorithm. Typically to get the best result a user will run the pass (or the full transpilation) multiple times with different seeds and pick the best output to get a better result. Since #8388 the SabreSwap pass has moved mostly the domain of Rust. This enables us to leverage multithreading easily to run parallel sabre over multiple seeds and pick the best result. This commit adds a new argument trials to the SabreSwap pass which is used to specify the number of random seed trials to run sabre with. Each trial will perform a complete run of the sabre algorithm and compute the swaps necessary for the algorithm. Then the result with the least number of swaps will be selected and used as the swap mapping for the pass. * Make parallel case fully deterministic The parallel trial code was potentially non-deterministic in it's execution because the way the parallel trials were compared was dependent on execution speed of the pass. This could result in a different output if results with equal number of swaps finished executing in differing amounts of time between runs. This commit addresses this by first collecting the results into an ordered Vec first which is then iterated over serially to find the minimum swap count. This will make the output independent of execution speed of the individual trials. * Fix test failures This commit updates tests which started to fail because of the different RNG behavior used by the parallel SabreSwap seed trials. For the most part these are just mechanical changes that either changed the expected layout with a fixed seed or updating a fixed seed so the output matches the expected result. The one interesting case was the TestTranspileLevelsSwap change which was caused by different swaps being inserted that for optimization level enabled the 2q block optimization passes to synthesize away the swap as part of its optimization. This was fixed by changing the seed, but it was a different case than the other failures. * Add swap_trials argument to SabreLayout This commit adds a swap_trials argument to the SabreLayout pass so that users can control how many trials to run in SabreSwap internally. This is necessary for reproducibility between systems for the same reason it's required on SabreSwap. * Add comment explaining the intermediate Vec usage * Update layout in new test * Update releasenotes/notes/multiple-parallel-rusty-sabres-32bc93f79ae48a1f.yaml Co-authored-by: Kevin Hartman <[email protected]> * Remove intermediate Vec for parallel trials In an earlier commit we switched the parallel iterator to collect into an intermediate `Vec` to ensure the output result was deterministic. The min_by_key() will have a degree of non-determinism for equal entries as the parallel iterator's threads finish. However, collecting to a Vec isn't necessary as we can use the index as an element in a 2 element array we can get the deterministic evaluation and avoid the overhead of collecting into a `Vec`. This commit makes this change to improve the performance of the parallel execution path. Co-authored-by: Kevin Hartman <[email protected]> Co-authored-by: Kevin Hartman <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
a0db581
commit 2ab0ae5
Showing
12 changed files
with
214 additions
and
67 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
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
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
20 changes: 20 additions & 0 deletions
20
releasenotes/notes/multiple-parallel-rusty-sabres-32bc93f79ae48a1f.yaml
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,20 @@ | ||
--- | ||
features: | ||
- | | ||
The :class:`~.SabreSwap` transpiler pass has a new keyword argument on its | ||
constructor, ``trials``. The ``trials`` argument is used to specify the | ||
number of random seed trials to attempt. The output from the | ||
`SABRE algorithm <https://arxiv.org/abs/1809.02573>`__ can differ greatly | ||
based on the seed used for the random number. :class:`~.SabreSwap` will | ||
now run the algorithm with ``trials`` number of random seeds and pick the | ||
best (with the fewest swaps inserted). If ``trials`` is not specified the | ||
pass will default to use the number of physical CPUs on the local system. | ||
- | | ||
The :class:`~.SabreLayout` transpiler pass has a new keyword argument on | ||
its constructor, ``swap_trials``. The ``swap_trials`` argument is used | ||
to specify how many random seed trials to run on the :class:`~.SabreSwap` | ||
pass internally. It corresponds to the ``trials`` arugment on the | ||
:class:`~.SabreSwap` pass. When set, each iteration of | ||
:class:`~.SabreSwap` will be run internally ``swap_trials`` times. | ||
If ``swap_trials`` is not specified the will default to use | ||
the number of physical CPUs on the local system. |
Oops, something went wrong.