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

Add double-line diagrams for control keys #4627

Merged
merged 43 commits into from
Nov 18, 2021

Conversation

daxfohl
Copy link
Contributor

@daxfohl daxfohl commented Nov 4, 2021

Adds double-line wires to diagrams between measurement gates and their associated control gates.

  • Cbits are represented similarly as qubits with a double-line axis.
  • The measurement key name is the label of the cbit (and the key label from M is removed).
  • @ is the symbol for writing to the cbit.
    • Currently we only allow write-once, but in the future we may want to allow overwrite, xor, bit-and, sum, etc.
  • ^ is the symbol for reading from / executing conditionally upon a cbit.
  • X below is hard-coded in the test case, but will be the conditional operation applied.
  • Measurement keys that are not used in control operations will not have a line associated, to reduce clutter.

For example a circuit

cirq.Circuit(
    cirq.measure(q0, key='a')
    ControlOp(qubits=[q1], keys=['a'])
)

would have the following representation.

0: ───M───────
      ║
1: ───╫───X───
      ║   ║
a: ═══@═══^═══

See circuit_test for more examples

Parts 6 of https://tinyurl.com/cirq-feedforward.

@daxfohl daxfohl requested review from cduck, vtomole and a team as code owners November 4, 2021 19:26
@daxfohl daxfohl requested a review from mpharrigan November 4, 2021 19:26
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 4, 2021
@CirqBot CirqBot added the size: M 50< lines changed <250 label Nov 4, 2021
@daxfohl daxfohl marked this pull request as ready for review November 5, 2021 00:42
@daxfohl
Copy link
Contributor Author

daxfohl commented Nov 5, 2021

@95-martin-orion This is good to go. It's not an easy PR; if there's anyone that knows more about diagrams then their input may be useful.

There are also a number of variables still named qubits and qubit_map that now contain both qubits and cbits, and should probably now be called xbits or something. I intentionally left those alone so as not to distract from the meat of the PR. I'd recommend dealing with that in a later PR.

Also, duly noted we never did formally specify what these should look like. I provided some examples in circuit_test. Hopefully this is somewhat along the lines of what you were thinking.

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

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

Overall pretty happy with how this turned out. I agree that we should get input from someone familiar with the diagram-drawing tools, though - I'm adding @Strilanc to give this input.

cirq-core/cirq/circuits/circuit.py Show resolved Hide resolved
cirq-core/cirq/circuits/circuit.py Show resolved Hide resolved
cirq-core/cirq/protocols/circuit_diagram_info_protocol.py Outdated Show resolved Hide resolved
cirq-core/cirq/testing/circuit_compare.py Show resolved Hide resolved
@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 18, 2021
@CirqBot
Copy link
Collaborator

CirqBot commented Nov 18, 2021

Automerge cancelled: No approved review.

@CirqBot CirqBot removed the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 18, 2021
@95-martin-orion 95-martin-orion added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Nov 18, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Nov 18, 2021
@CirqBot CirqBot merged commit 80e8474 into quantumlib:master Nov 18, 2021
@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 Nov 18, 2021
@daxfohl daxfohl deleted the doublelines branch November 18, 2021 18:54
CirqBot pushed a commit that referenced this pull request Nov 22, 2021
Follow-up to #4627 that renames diagram lines from "qubits" to "labels", since they now contain control keys as well.
CirqBot pushed a commit that referenced this pull request Dec 8, 2021
Sits on top of #4627

Creates `ConditionalOperation` class and executes operations conditionally upon the classical bits. Most of this is done in commit 06883d5.

Reimplements quantum teleportation example based off this class.

Parts 8, 9, 10 of https://tinyurl.com/cirq-feedforward.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Adds double-line wires to diagrams between measurement gates and their associated control gates.

* Cbits are represented similarly as qubits with a double-line axis.
* The measurement key name is the label of the cbit (and the key label from `M` is removed).
* `@` is the symbol for writing to the cbit.
  * Currently we only allow write-once, but in the future we may want to allow overwrite, xor, bit-and, sum, etc.
* `^` is the symbol for reading from / executing conditionally upon a cbit.
* `X` below is hard-coded in the test case, but will be the conditional operation applied.
* Measurement keys that are not used in control operations will not have a line associated, to reduce clutter.

For example a circuit
```
cirq.Circuit(
    cirq.measure(q0, key='a')
    ControlOp(qubits=[q1], keys=['a'])
)
```
would have the following representation.

```
0: ───M───────
      ║
1: ───╫───X───
      ║   ║
a: ═══@═══^═══
```

See `circuit_test` for more examples

Parts 6 of https://tinyurl.com/cirq-feedforward.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Follow-up to quantumlib#4627 that renames diagram lines from "qubits" to "labels", since they now contain control keys as well.
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Sits on top of quantumlib#4627

Creates `ConditionalOperation` class and executes operations conditionally upon the classical bits. Most of this is done in commit quantumlib@06883d5.

Reimplements quantum teleportation example based off this class.

Parts 8, 9, 10 of https://tinyurl.com/cirq-feedforward.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Adds double-line wires to diagrams between measurement gates and their associated control gates.

* Cbits are represented similarly as qubits with a double-line axis.
* The measurement key name is the label of the cbit (and the key label from `M` is removed).
* `@` is the symbol for writing to the cbit.
  * Currently we only allow write-once, but in the future we may want to allow overwrite, xor, bit-and, sum, etc.
* `^` is the symbol for reading from / executing conditionally upon a cbit.
* `X` below is hard-coded in the test case, but will be the conditional operation applied.
* Measurement keys that are not used in control operations will not have a line associated, to reduce clutter.

For example a circuit
```
cirq.Circuit(
    cirq.measure(q0, key='a')
    ControlOp(qubits=[q1], keys=['a'])
)
```
would have the following representation.

```
0: ───M───────
      ║
1: ───╫───X───
      ║   ║
a: ═══@═══^═══
```

See `circuit_test` for more examples

Parts 6 of https://tinyurl.com/cirq-feedforward.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Follow-up to quantumlib#4627 that renames diagram lines from "qubits" to "labels", since they now contain control keys as well.
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Sits on top of quantumlib#4627

Creates `ConditionalOperation` class and executes operations conditionally upon the classical bits. Most of this is done in commit quantumlib@06883d5.

Reimplements quantum teleportation example based off this class.

Parts 8, 9, 10 of https://tinyurl.com/cirq-feedforward.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants