Document store directive#5129
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
…d-store-directive
…d-store-directive
|
One or more of the following people are relevant to this code:
|
abbycross
left a comment
There was a problem hiding this comment.
I did a copyedit scan. Does anyone need to look with a technical eye? I know Becky's already been working closely with the SMEs on this
I'll share it with some experts! |
| "```python\n", | ||
| "# Store the negation in temporary variable\n", | ||
| "qc.store(temp, expr.bit_not(creg))\n", | ||
| "\n", | ||
| "# Now compute parity using the stored result\n", | ||
| "parity = expr.bit_xor(\n", | ||
| " expr.bit_xor(temp[0], temp[1]), temp[2]\n", | ||
| ")\n", | ||
| "```" |
There was a problem hiding this comment.
I would rather add this to a code cell type instead of within the markdown?
and I would put a more complete example like:
from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.circuit.classical import expr, types
qregs = QuantumRegister(4, "q")
creg = ClassicalRegister(3, "c")
qc = QuantumCircuit(qregs, creg)
# Declare temp as a Uint(3) variable to hold the negation of creg
temp = qc.add_var("temp", expr.lift(0, types.Uint(3)))
qc.h([0, 1, 2])
qc.measure([0, 1, 2], creg)
# Store bit-NOT of the full 3-bit register in a single parallel step
qc.store(temp, expr.bit_not(creg))
# Compute parity of the stored result using bit-indexed XOR
parity = expr.bit_xor(
expr.bit_xor(expr.index(temp, 0), expr.index(temp, 1)),
expr.index(temp, 2),
)
# Flip q3 if parity of ~creg is 1
with qc.if_test(parity):
qc.x(3)
qc.measure([0, 1, 2], creg)
qc.draw("mpl")There was a problem hiding this comment.
Adding code from our external discussion.
| "id": "56f98db3-99b3-49d4-b7a9-3d9fd8278890", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## `Store`\n", | ||
| "\n", | ||
| "With `qiskit-ibm-runtime` v0.47.0 or later, you can use the [`store`](/docs/api/qiskit/circuit#store) instruction to save the result of a classical expression, if that expression will be used repeatedly. Operations are automatically parallelized, making your code significantly more efficient at runtime.\n", | ||
| "\n", | ||
| "For example, it is more natural and performant to write $B[0]^B[1]^B[2]...,$ where $B = ~A$, than $(~A[0])^(~A[1])^(~A[2])....$ The former can be written in Qiskit as the following:\n", | ||
| "\n", | ||
| "```python\n", | ||
| "# Store the negation in temporary variable\n", | ||
| "qc.store(temp, expr.bit_not(creg))\n", | ||
| "\n", | ||
| "# Now compute parity using the stored result\n", | ||
| "parity = expr.bit_xor(\n", | ||
| " expr.bit_xor(temp[0], temp[1]), temp[2]\n", | ||
| ")\n", | ||
| "```" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "0de5ec21-2b09-4692-82d3-58a469b249e4", |
There was a problem hiding this comment.
This was not mentioned in the pages to review in the description of the PR, so maybe was introduced by mistake, but this is not the right place to add this content as Store is circuit-building related and not execution.
(in addition to maintenance debt introducing by duplicating the content)
There was a problem hiding this comment.
@francabrera - Jessie had me move some of the information here because the first section is Qiskit only and this page is for Qiskit Runtime. I can cut down the information here, but I think it would be good to mention it here.
| "\n", | ||
| " Other notes:\n", | ||
| " - Gate twirling can be applied to dynamic circuits, but only to gates not inside conditional blocks. Measurement twirling can only be applied to terminal measurements.\n", | ||
| " - Gate twirling can be applied to dynamic circuits, but only to gates not inside conditional blocks.\n", |
There was a problem hiding this comment.
this file is not rendering in the preview
Co-authored-by: Fran Cabrera <francabrera@users.noreply.github.com>
…ntation into bd-store-directive
Pages to review:
https://qiskit.github.io/documentation/pr-5129/docs/guides/classical-feedforward-and-control-flow
https://qiskit.github.io/documentation/pr-5129/docs/guides/execute-dynamic-circuits
https://qiskit.github.io/documentation/pr-5129/docs/guides/executor-options#feature-compatibility
https://qiskit.github.io/documentation/pr-5129/docs/guides/estimator-options#feature-compatibility