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

Change qubit str representation #5343

Merged
merged 14 commits into from
May 16, 2022
Merged

Conversation

dstrain115
Copy link
Collaborator

@dstrain115 dstrain115 commented May 10, 2022

  • Changes grid qubit string representation from (x, y) to q(x, y)
    and line qubit from 1 to q1.
  • This will make the string representation more distinctive.
  • Added circuit_diagram_info for Qid objects to make circuit diagrams
    customizable for qubits. This allows us to keep circuit diagrams
    largely unchanged.
  • Other components such as pauli strings, that rely on qubit str
    representation for formatting are changed.

This is a BREAKING CHANGE for anyone relying on string representation
of qubits. This also changes default measurement keys and the '.measurements()'
functionality of results, since these use the string representation of qubits.

Fixes: #2405

 - Changes grid qubit string representation from (x, y) to q(x, y)
 and line qubit from 1 to q1.
 - This will make the string representation more distinctive.
 - Added _circuit_diagram_info_ for Qid objects to make circuit diagrams
customizable for qubits.  This allows us to keep circuit diagrams
largely unchanged.
 - Other components such as pauli strings, that rely on qubit str
   representation for formatting are changed.

 This is a BREAKING CHANGE for anyone relying on string representation
 of qubits.

Fixes: quantumlib#2405
@dstrain115 dstrain115 requested review from a team, vtomole and cduck as code owners May 10, 2022 20:23
@dstrain115 dstrain115 added the BREAKING CHANGE For pull requests that are important to mention in release notes. label May 10, 2022
@CirqBot CirqBot added the size: M 50< lines changed <250 label May 10, 2022
Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

With the q function, line qubits would look like q(0), q(1) instead of q0, q1. Do we want to use the parenthesized form instead?

One place we should think carefully about is that qubit string representations get included in measurement keys by default if no key is specified. I think this should be ok, but there may be some places where we assume the form of these measurement keys.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@dstrain115 dstrain115 requested a review from maffoo May 11, 2022 16:35
@dstrain115
Copy link
Collaborator Author

Ok, I have cleared out all the test failures, and this is now ready for review.

Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

This looks good to me, just a few minor comments and one question about whether we want to revert to the (x, y) form for grid device diagrams (as we use in circuit diagrams). Also, I think it'd be good to have some other folks look at this before we do it, since the measurement key changes in particular may pose compatibility concerns for results that were saved with the old format. @zchen088, would this be an issue for datasets we've saved internally?

cirq-core/cirq/circuits/circuit.py Outdated Show resolved Hide resolved
2: ───H(2)───
2: ───H(q(2))───
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit odd to me that controlled operation shows the applied qubits like this, since that should be clear from the qubit lines. Would be nice to change this to just show the gate diagram info if possible. But that could be a future PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just a custom gate in the test code and is not used outside the test, so I am not too worried about it. Normal controlled operations are unaffected.

cirq-core/cirq/sim/simulator_test.py Outdated Show resolved Hide resolved
q(3, 0)───q(3, 1)
q(4, 0)───q(4, 1)"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use the circuit diagram info representation in grid device, as we do when labeling qubit lines in circuits?

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.

@dstrain115
Copy link
Collaborator Author

@maffoo This change was announced at cirq-cync, but I am open to other modes of communication, especially internally.

@dstrain115
Copy link
Collaborator Author

I will be submitting this change soon, so chime in if you have any requested changes.

@dstrain115 dstrain115 merged commit 2d84676 into quantumlib:master May 16, 2022
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
* Change qubit str representation

 - Changes grid qubit string representation from (x, y) to q(x, y)
 and line qubit from 1 to q1.
 - This will make the string representation more distinctive.
 - Added _circuit_diagram_info_ for Qid objects to make circuit diagrams
customizable for qubits.  This allows us to keep circuit diagrams
largely unchanged.
 - Other components such as pauli strings, that rely on qubit str
   representation for formatting are changed.

 This is a BREAKING CHANGE for anyone relying on string representation
 of qubits.

Fixes: quantumlib#2405

* Fix a bunch of tests.

* A few more errors.

* Switch to q(0) and fix a bunch of tests.

* Formatting and more tests fixed.

* Fix more tests.

* Fix two last tests.

* Fix bb84 example.

* Fix contrib and notebook tests.

* Update cirq-core/cirq/sim/simulator_test.py

Co-authored-by: Matthew Neeley <mneeley@gmail.com>

* Update cirq-core/cirq/circuits/circuit.py

Co-authored-by: Matthew Neeley <mneeley@gmail.com>

* Revert Grid Device to use circuit diagram names instead.

Co-authored-by: Matthew Neeley <mneeley@gmail.com>
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
* Change qubit str representation

 - Changes grid qubit string representation from (x, y) to q(x, y)
 and line qubit from 1 to q1.
 - This will make the string representation more distinctive.
 - Added _circuit_diagram_info_ for Qid objects to make circuit diagrams
customizable for qubits.  This allows us to keep circuit diagrams
largely unchanged.
 - Other components such as pauli strings, that rely on qubit str
   representation for formatting are changed.

 This is a BREAKING CHANGE for anyone relying on string representation
 of qubits.

Fixes: quantumlib#2405

* Fix a bunch of tests.

* A few more errors.

* Switch to q(0) and fix a bunch of tests.

* Formatting and more tests fixed.

* Fix more tests.

* Fix two last tests.

* Fix bb84 example.

* Fix contrib and notebook tests.

* Update cirq-core/cirq/sim/simulator_test.py

Co-authored-by: Matthew Neeley <mneeley@gmail.com>

* Update cirq-core/cirq/circuits/circuit.py

Co-authored-by: Matthew Neeley <mneeley@gmail.com>

* Revert Grid Device to use circuit diagram names instead.

Co-authored-by: Matthew Neeley <mneeley@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE For pull requests that are important to mention in release notes. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

str(GridQubit) too similar to str(tuple)
3 participants