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

Make moment str/text diagrams stable (independent of insertion order) #5474

Merged
merged 7 commits into from
Jun 25, 2022

Conversation

tanujkhattar
Copy link
Collaborator

Fixes #5404

@tanujkhattar tanujkhattar requested review from a team, vtomole and cduck as code owners June 9, 2022 20:11
@tanujkhattar tanujkhattar requested a review from dabacon June 9, 2022 20:11
@CirqBot CirqBot added the size: S 10< lines changed <50 label Jun 9, 2022
@dabacon
Copy link
Collaborator

dabacon commented Jun 9, 2022

Amazed that this does not break any tests!!!!

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.

One question

cirq-core/cirq/circuits/moment.py Outdated Show resolved Hide resolved
@tanujkhattar
Copy link
Collaborator Author

@dabacon The PR is ready for a re-review. PTAL!

@@ -91,6 +91,7 @@ def __init__(self, *contents: 'cirq.OP_TREE') -> None:
ValueError: A qubit appears more than once.
"""
self._operations = tuple(op_tree.flatten_to_ops(contents))
self._sorted_operations = tuple(sorted(self._operations, key=lambda op: op.qubits))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit worried about hit we take here for time and memory. Already our circuit code isn't particularly fast and this doubles the memory and time for constructing moments.

Does it make sense to maybe have this be a cached value (like measurement key obs and control keys) that is only populated when used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, although I think it would have little value since sorted operations is used in common functions like to_text_diagram and _eq_.

@quantumlib quantumlib deleted a comment from review-notebook-app bot Jun 21, 2022
@tanujkhattar
Copy link
Collaborator Author

@dabacon This is ready for another review. PTAL.

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.

LGTM

@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Jun 25, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Jun 25, 2022
@CirqBot CirqBot merged commit 3a31e95 into master Jun 25, 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 Jun 25, 2022
@CirqBot CirqBot deleted the fix_moment_str branch June 25, 2022 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Moments with overlapping operations should produce consistent diagrams, by not depending upon insertion order
3 participants