-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up synthesis passes when there is nothing to synthesize (#10788)
* Speed up synthesis passes when there is nothing to synthesize This commit makes a small optimization to the UnitarySynthesis and HighLevelSynthesis synthesis passes when there are no gates to synthesize. Previously these passes would iterate over the entire DAG and check every gate to determine that None needed to be synthesized. While this is relatively quick for very large circuits this can take 100s of ms. However, this was wasted work because the DAG carries a dictionary of op names in the circuit so we can determine in constant time whether any of the operations to synthesize are present up front and skip the bulk of the iteration. To improve the impact here the DAGCircuit.count_ops() method is updated to skip the recursion if no control flow operations are present. Otherwise we'd still be iterating over the DAG (in a faster manner) which would limit the improvement from this commit. This isn't the best approach for that as it uses a hardcoded list of control flow operations which doesn't seem super general purpose, but as this hard coded set of instructions is already used elsewhere in the DAGCircuit this isn't making the situation any worse. If/when we expand recursive objects this can be revisited (and we'll likely not be able to avoid the iteration in count ops). With these changes the time these passes take when there are no operations to synthesize only takes ~5-15 microseconds. A similar optimization should be considered for UnrollCustomDefinitions as this takes an even longer amount of time to iterate when there is nothing to translate. However, it wasn't done as part of this PR as to check the equivalence library has an entry we need to work with gate objects (well actually name and number of qubits as that's all that's used from the object for a lookup) and the name from the op count dictionary is not sufficient for a lookup. So this will need to be handled independently in a separate PR. * Remove duplicated check in unitary synthesis * Unify hardcoded sets of control flow op names
- Loading branch information
Showing
5 changed files
with
24 additions
and
19 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