Avoid operator creation in transpiler (backport #12826) #12875
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
This removes very nearly all of the use of
DAGOpNode.op
in the default transpiler paths. The sole exception is inInverseCancellation
, which currently would involve some quite awkward gymnastics for little near-term benefit. The pass should move fully to Rust soon, making it not worth the effort.Most of the tricks here involve using the knowledge that most operations will involve only Rust-space standard gates, and that these cannot be control-flow operations.
Details and comments
This always includes a reno for a couple of the new methods added to
DAGOpNode
andCircuitInstruction
.I measured this as being ~25% faster for some toy workloads at transpilation levels 0 and 1, probably mostly driven by the new methods letting us avoid a lot of
isinstance
checks in most cases.This is an automatic backport of pull request #12826 done by Mergify.