Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedicated method for creating circuit from op tree with EARLIEST strategy #5332

Merged
merged 34 commits into from
Jul 11, 2022

Conversation

daxfohl
Copy link
Contributor

@daxfohl daxfohl commented May 5, 2022

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).

@daxfohl daxfohl requested review from a team, vtomole and cduck as code owners May 5, 2022 03:03
@daxfohl daxfohl requested a review from mpharrigan May 5, 2022 03:03
@CirqBot CirqBot added the size: M 50< lines changed <250 label May 5, 2022
Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments and types. LMK what you think.

cirq-core/cirq/circuits/circuit_test.py Show resolved Hide resolved
Copy link
Collaborator

@dabacon dabacon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

@daxfohl
Copy link
Contributor Author

daxfohl commented Jun 16, 2022

@dstrain115 I updated the documentation. Should this be merged before 0.15?

Copy link
Collaborator

@dstrain115 dstrain115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I lost track of this. Let's merge this!

@daxfohl
Copy link
Contributor Author

daxfohl commented Jul 11, 2022

Merge label? I don't have authz

@mpharrigan mpharrigan added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jul 11, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jul 11, 2022
@CirqBot CirqBot merged commit ef40777 into quantumlib:master Jul 11, 2022
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Jul 11, 2022
# 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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link

@daxfohl daxfohl deleted the builder2 branch August 12, 2022 05:16
@mpharrigan mpharrigan removed their request for review August 23, 2022 22:28
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…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).
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/performance size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants