Dedicated method for creating circuit from op tree with EARLIEST strategy#5332
Dedicated method for creating circuit from op tree with EARLIEST strategy#5332CirqBot merged 34 commits intoquantumlib:masterfrom
Conversation
This reverts commit 9c1d3ed.
dstrain115
left a comment
There was a problem hiding this comment.
Nice speedup! Looking forward to having this in. Was thinking of looking into this the other day and am now very happy that it is already taken care of!
I added some notes that this should have more commenting.
| else: | ||
| self.append(contents, strategy=strategy) | ||
|
|
||
| def _create_from_earliest(self, contents): |
There was a problem hiding this comment.
We may want to consider adding a docstring or other comments, especially since there are subtleties here in how to do earliest (with measurement keys, controlled ops, etc).
I certainly find it challenging to follow without comments.
There was a problem hiding this comment.
Added comments and types. LMK what you think.
|
@dstrain115 I updated the documentation. Should this be merged before 0.15? |
dstrain115
left a comment
There was a problem hiding this comment.
Sorry, I lost track of this. Let's merge this!
|
Merge label? I don't have authz |
| ) | ||
| # limit index to 0..len(self._moments), also deal with indices smaller 0 | ||
| k = max(min(index if index >= 0 else len(self._moments) + index, len(self._moments)), 0) | ||
| for moment_or_op in moments_and_operations: |
…tegy (quantumlib#5332) We keep track of the latest moment that contains each qubit and measurement key. Then we know where to put each operation in constant time. We don't create the actual Moments until the very end, when we know where everything goes. Also added explicit key protocol impls for EigenGate, preempting the protocol from attempting a bunch of fallback options. On my laptop this speeds up creating circuits with EARLIEST strategy by almost infinity percent. (On my laptop, the circuit in the new test goes from 29.00s on master to 0.13s here).
…tegy (quantumlib#5332) We keep track of the latest moment that contains each qubit and measurement key. Then we know where to put each operation in constant time. We don't create the actual Moments until the very end, when we know where everything goes. Also added explicit key protocol impls for EigenGate, preempting the protocol from attempting a bunch of fallback options. On my laptop this speeds up creating circuits with EARLIEST strategy by almost infinity percent. (On my laptop, the circuit in the new test goes from 29.00s on master to 0.13s here).
We keep track of the latest moment that contains each qubit and measurement key. Then we know where to put each operation in constant time. We don't create the actual Moments until the very end, when we know where everything goes. Also added explicit key protocol impls for EigenGate, preempting the protocol from attempting a bunch of fallback options. On my laptop this speeds up creating circuits with EARLIEST strategy by almost infinity percent. (On my laptop, the circuit in the new test goes from 29.00s on master to 0.13s here).