-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
extend the documentation for qiskit.circuit.QuantumCircuit.measure #9698
Changes from 9 commits
452027a
f6ec66f
99fe422
5139c47
865cc4e
c0d513b
631bef5
307b428
52ef5b9
8aaa3b3
6082824
7af99a0
673e649
daaed65
e3bc46a
1a474f6
7bc4849
da035a9
464d805
81d7032
365fd9a
22ca37d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2265,17 +2265,96 @@ def reset(self, qubit: QubitSpecifier) -> InstructionSet: | |
return self.append(Reset(), [qubit], []) | ||
|
||
def measure(self, qubit: QubitSpecifier, cbit: ClbitSpecifier) -> InstructionSet: | ||
"""Measure quantum bit into classical bit (tuples). | ||
"""Measure quantum bit (qubit) into classical bit (cbit). | ||
|
||
Args: | ||
qubit: qubit to measure. | ||
cbit: classical bit to place the measurement in. | ||
When a qubit is measured, its state collapses to a classical bit and copied to a | ||
classical wire. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't strictly physically correct, and it's missing a bit of information. I don't know how you want to present it to less informed users, but for knowledgable ones, we should mention that It feels a bit off to say a quantum state "collapses to a classical bit" - the global wavefunction collapses such that the measured qubit(s) are in an eigenstate of the projective measurement. In a general entangled state, it's also not super precise to imply that a single qubit can have a state independent of the others ("its state" - it isn't guaranteed to be separable before the measurement). I think I'd avoid talking about the quantum state too much here - if a user doesn't already know what a "projective measurement" is, they'll be better served by an intro to QC rather than us trying to fit a miniature version into API documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about the explanation in e3bc46a . It would be great to keep it simple while technically correct. |
||
|
||
Returns: | ||
qiskit.circuit.InstructionSet: handle to the added instructions. | ||
In this example, a qubit is measured and the result of that measurement is stored in the | ||
classical bit (usually expressed in diagrams as a double line): | ||
|
||
Raises: | ||
CircuitError: if arguments have bad format. | ||
.. code-block:: | ||
|
||
from qiskit import QuantumCircuit | ||
circuit = QuantumCircuit(1,1) | ||
circuit.h(0) | ||
HuangJunye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
circuit.measure(0, 0) | ||
circuit.draw() | ||
|
||
|
||
.. parsed-literal:: | ||
|
||
┌───┐┌─┐ | ||
q: ┤ H ├┤M├ | ||
└───┘└╥┘ | ||
c: 1/══════╩═ | ||
0 | ||
|
||
It is possible to call ``measure`` with lists of qubits and cbits of the same size: | ||
|
||
.. code-block:: | ||
|
||
circuit = QuantumCircuit(2,2) | ||
circuit.measure([0,1], [0,1]) # same as "circuit.measure(0,0); circuit.measure(1,1);" | ||
|
||
|
||
.. parsed-literal:: | ||
|
||
┌─┐ | ||
q_0: ┤M├─── | ||
└╥┘┌─┐ | ||
q_1: ─╫─┤M├ | ||
║ └╥┘ | ||
c: 2/═╩══╩═ | ||
0 1 | ||
|
||
It is also possible to do a one-to-many readout: | ||
|
||
.. code-block:: | ||
|
||
circuit = QuantumCircuit(2,2) | ||
circuit.measure(0, [0,1]) # same as "circuit.measure(0,0); circuit.measure(0,1);" | ||
|
||
|
||
.. parsed-literal:: | ||
|
||
┌─┐┌─┐ | ||
q_0: ┤M├┤M├ | ||
└╥┘└╥┘ | ||
q_1: ─╫──╫─ | ||
║ ║ | ||
c: 2/═╩══╩═ | ||
0 1 | ||
|
||
Instead of lists, you can use :class:`~qiskit.circuit.QuantumRegister` and | ||
:class:`~qiskit.circuit.ClassicalRegister` under the same logic. | ||
|
||
.. code-block:: | ||
|
||
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister | ||
qreg = QuantumRegister(1, "qreg") | ||
creg = ClassicalRegister(2, "creg") | ||
circuit = QuantumCircuit(qreg, creg) | ||
circuit.measure(qreg, creg) | ||
|
||
|
||
.. parsed-literal:: | ||
|
||
┌─┐┌─┐ | ||
qreg: ┤M├┤M├ | ||
└╥┘└╥┘ | ||
creg: 2/═╩══╩═ | ||
0 1 | ||
|
||
HuangJunye marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Args: | ||
qubit: qubit/s to measure. | ||
cbit: classical bit/s to place the measurement in. | ||
|
||
Returns: | ||
qiskit.circuit.InstructionSet: handle to the added instructions. | ||
|
||
Raises: | ||
CircuitError: if arguments have bad format. | ||
1ucian0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
return self.append(Measure(), [qubit], [cbit]) | ||
|
||
|
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.
(or "measure a quantum bit into a classical bit", depending on whether you want to stress the broadcasting or not)
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 went for the singular option in daaed65