Fix order of do-while loop in transpile optimisation #7794
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The previous check would always run the body of the optimisation loop
once after the fixed point had been achieved. As well as being
unnecessary, this also made it possible in theory for the optimisation
loop to "unfix" the point, although hopefully our optimisations on that
front would never increase the number of operations.
Instead, we now do the depth/size scans ahead of the loop, then move the
checking condition to the end. In the best-case scenario for
optimisation (the circuit is already optimised) this would be a 2x
speedup of the optimisation loop for free, but more likely it will
manifest itself as a ~20% or so speedup.
Details and comments
A smallish subset of the transpiler benchmarks:
This should ameliorate the performance regressions caused by #7542. Note though that performance regressions there were expected and should have come with an accompanying improvement in circuit size, which unfortunately wasn't added to the benchmark suite ahead of time.