-
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.
Add config option to leverage all cores for sabre (#12780)
* Add config option to leverage all cores for sabre By default when running sabre in parallel we use a fixed number of threads (depending on optimization level). This was a tradeoff made for having deterministic results across multiple systems with a fixed seed set. However when running qiskit on systems with a lot of CPUs available we're leaving potential performance on the table by not using all the available cores. This new flag lets users opt-in to running sabre with n trials for n CPUs to potentially get better output results from the transpiler, with minimal to no runtime overhead, at the cost of the results not necessarily being reproducible when run on a different computer. * Apply suggestions from code review Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> * Rework logic to use the default if larger than CPU_COUNT This commit refactors the logic added in the previous commit to a single helper function. This reduces the code duplication and makes it easier to work with. While doing this the logic has been updated so that when the flag is set and the default number of trials is larger than the CPU_COUNT we use the default. This means the logic when the flag is set is to run `max(default_trials, CPU_COUNT)` which should better match user expectations around the flag. --------- Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
87 additions
and
18 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
26 changes: 26 additions & 0 deletions
26
releasenotes/notes/add-sabre-all-threads-option-ad4ff7a4d045cb2b.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,26 @@ | ||
--- | ||
features_transpiler: | ||
- | | ||
Added a new user config file option ``sabre_all_threads`` and a | ||
corresponding environment variable ``QISKIT_SABRE_ALL_THREADS``. When this | ||
flag is set the preset pass managers will run the :class:`.SabreLayout` | ||
and :class:`.SabreSwap` transpiler passes using all the available | ||
CPUs on the local system. Using this option is a tradeoff between | ||
determinism of output between different computers and potentially better | ||
output with fewer :class:`.SwapGate`\s. | ||
These transpiler passes run multiple random trials in parallel and pick | ||
the output which results in the fewest :class:`.SwapGate`\s. As a rule of | ||
thumb, if you run more trials, this provides the algorithm more opportunities | ||
to find a better result. By default, the preset pass managers use a fixed | ||
number of trials, in this release 5 trials for levels 0 and 1, and 20 | ||
trials for levels 2 and 3, but these numbers may change in future releases | ||
(and were different in historical releases). Using a fixed number of | ||
trials results in deterministic results regardless of the local system, | ||
because even with a fixed seed if you were to default to the number of | ||
local CPUs available the results would different when running between | ||
different computers. | ||
If the default number of trials for a given optimization level is higher | ||
than the number of local CPUs it will use the optimization level default | ||
which is higher. |