-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 guide on operators and observables #3654
Conversation
Now ready for review. I learned that |
docs/operators_and_observables.ipynb
Outdated
}, | ||
"outputs": [], | ||
"source": [ | ||
"qbit = cirq.LineQubit(0)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated here and throughout.
docs/operators_and_observables.ipynb
Outdated
"outputs": [], | ||
"source": [ | ||
"qbit = cirq.LineQubit(0)\n", | ||
"unitary_operation = cirq.ops.X.on(qbit) # cirq.X can also be used for cirq.ops.X\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
docs/operators_and_observables.ipynb
Outdated
"id": "6771bf1c439a" | ||
}, | ||
"source": [ | ||
"Cirq makes a distinction between gates (independent of qubits) and operations (gates acting on qubits). Thus `cirq.X` is a gate where `cirq.X.on(qbit)` is an operation. See the [guide on gates](gates.ipynb) for more details and additional common unitaries defined in Cirq." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
docs/operators_and_observables.ipynb
Outdated
}, | ||
"outputs": [], | ||
"source": [ | ||
"measurement_operation = measurement.on(qbit)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
docs/operators_and_observables.ipynb
Outdated
"outputs": [], | ||
"source": [ | ||
"circuit = cirq.Circuit(\n", | ||
" cirq.H(qbit),\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
docs/operators_and_observables.ipynb
Outdated
"source": [ | ||
"circuit = cirq.Circuit(\n", | ||
" cirq.H(qbit),\n", | ||
" cirq.depolarize(p=0.01).on(qbit),\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
docs/operators_and_observables.ipynb
Outdated
"circuit = cirq.Circuit(\n", | ||
" cirq.H(qbit),\n", | ||
" cirq.depolarize(p=0.01).on(qbit),\n", | ||
" cirq.measure(qbit)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
docs/operators_and_observables.ipynb
Outdated
}, | ||
"outputs": [], | ||
"source": [ | ||
"qbit = cirq.LineQubit(0)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: change to qubit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, it's a great start, good to see a comprehensive overview on this topic! I added some initial comments.
I wonder if we want to talk about projectors (cirq.KET_IMAG.projector()
) here too?
docs/operators_and_observables.ipynb
Outdated
" <td rowspan=\"3\">Operators</td>\n", | ||
" <td>Unitary operators</td>\n", | ||
" <td>`cirq.X`</td>\n", | ||
" <td>[Gates](gates.ipynb) and [Custom gates](custom_gates.ipynb)</td>\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These links don't seem to work well, because you are mixing HTML with markdown. You could try creating tables with the table syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to markdown. (Only reason for html was rowspan which isn't supported by markdown, but this isn't needed with the new table as below.)
docs/operators_and_observables.ipynb
Outdated
"id": "7cabbfa3ba55" | ||
}, | ||
"source": [ | ||
"Quantum operations (or just *operators*) include unitary gates, measurements, and noisy channels. Every operator in Cirq is an instance of a `cirq.Operation` which supports the Kraus operator representation\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioning cirq.Operation
is confusing a bit, because gates don't inherit cirq.Operation
. It would be more precise to say quantum operators that are acting on a given set of qubits implement cirq.Operation
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used this wording here and throughout.
docs/operators_and_observables.ipynb
Outdated
" <td></td>\n", | ||
" </tr>\n", | ||
"</tbody>\n", | ||
"</table>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the Operators
vs Observables
split.
Item
is too generic, mainly because the category of the items is in the first column. We could break it out to two separate tables - that would save a column as well. Actually observables might not even need a table. Also cirq.PauliSum is a generic way to express any operator, hermitian, non-hermitian, anything, not just observables. I feel like we should capture that somehow.
How about something like this:
Operators:
Operator | Cirq representation | Guides | Examples |
---|---|---|---|
Unitary operators | any class implementing the _unitary_ protocol |
Protocols, Gates and operations, custom gates | cirq.Gate : cirq.X(qubit) , cirq.CNOT(q0, q1) , cirq.MatrixGate.on(qubit) , cirq.Circuit (if it only contains unitary operations) |
Measurement | cirq.measure and cirq.MeasurementGate |
Gates and operations | cirq.measure(cirq.LineQubit(0)) |
Quantum channels |
|
protocols | cirq.DepolarizingChannel(p=0.2)(q0) , cirq.X.with_probability(0.5) |
Cirq also supports Observables on qubits that can be used to calculate expectation values on a given state.
- You can use
cirq.PauliString
to express them - Or you can use
cirq.PauliSum
with real coefficients
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I like this and adopted it almost verbatim with just a few cosmetic changes.
Seems like a good idea - probably in the section on measurements? I'm thinking of a simple example showing measurements in a different basis, after describing prob_plus = np.trace(cirq.KET_PLUS.projector() @ rho).real where |
How did you fix KeyError: 'language_info' ? |
Just to document for posterity: Looks like this was unrelated to asyncio as it popped up in #3669, see also #3603 (comment). So here I'm not sure why the error went away. |
Hmm...I was just thinking about a separate section for Projector operators, which are also coming in form of I think this all is looking really good now. We can add the projectors as part of a separate issue, after we implemented the |
Sounds good! |
Fixes #3575. (Perhaps #1550 as well.)
As mentioned in the notebook, the intended audience for this guide is someone already familiar with these concepts, just not how they are defined/used in Cirq.
Let me know @balopat how close this is to what you had in mind! Comments and feedback of course welcome.