From c2738dd3adcaaa436a68e48068988edeec865102 Mon Sep 17 00:00:00 2001 From: Rebecca Dimock Date: Mon, 6 Oct 2025 14:42:26 -0500 Subject: [PATCH 1/5] document mid-circuit measurements --- docs/guides/measure-qubits.ipynb | 39 ++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/guides/measure-qubits.ipynb b/docs/guides/measure-qubits.ipynb index a952c5fa9f2..100d29ebec9 100644 --- a/docs/guides/measure-qubits.ipynb +++ b/docs/guides/measure-qubits.ipynb @@ -43,7 +43,7 @@ " \\end{cases}\n", "$$\n", "\n", - "## Apply a measurement to a circuit\n", + "## Apply a measurement to the end of a circuit\n", "\n", "There are several ways to apply measurements to a circuit:\n", "\n", @@ -191,6 +191,34 @@ "qc.measure_active() # Measure qubits that are not idle, i.e., qubits 0 and 2." ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Apply a mid-circuit measurement to a circuit\n", + "\n", + "Use `MidCircuitMeasure` (**NEED LINK**) to apply a mid-circuit measurement. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from qiskit import QuantumCircuit\n", + "from qiskit_ibm_runtime.circuit import MidCircuitMeasure\n", + "from qiskit.circuit import Measure\n", + "\n", + "circ = QuantumCircuit(2, 2)\n", + "circ.x(0)\n", + "circ.append(MidCircuitMeasure(), [0], [0])\n", + "circ.append(MidCircuitMeasure(\"measure_3\"), [0], [1])\n", + "circ.measure([0], [0])\n", + "circ.measure_all()\n", + "print(circ.draw())" + ] + }, { "cell_type": "markdown", "id": "242ffc90-8db9-4e09-98d8-adb74b57afac", @@ -201,8 +229,15 @@ "* Circuits that contain operations _after_ a measurement are called dynamic circuits. Not all QPUs support these.\n", "* There must be at least one classical register in order to use measurements.\n", "* The Sampler primitive requires circuit measurements. You can add circuit measurements with the Estimator primitive, but they are ignored.\n", + "* **QUESTION**: Can you use a mid-circuit measurement with a regular end-of-circuit measurement?\n", "\n", - "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "\n", "## Next steps\n", "\n", From 376a420c8231f707d1897bcb3763c834fa94a092 Mon Sep 17 00:00:00 2001 From: Rebecca Dimock Date: Mon, 6 Oct 2025 14:49:43 -0500 Subject: [PATCH 2/5] notebooks always break. Always. --- docs/guides/classical-feedforward-and-control-flow.ipynb | 2 +- docs/guides/measure-qubits.ipynb | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/guides/classical-feedforward-and-control-flow.ipynb b/docs/guides/classical-feedforward-and-control-flow.ipynb index 9407e8abb53..a950119ce85 100644 --- a/docs/guides/classical-feedforward-and-control-flow.ipynb +++ b/docs/guides/classical-feedforward-and-control-flow.ipynb @@ -38,7 +38,7 @@ "The new version of dynamic circuits is now available to all users on all backends. You can now run dynamic circuits at utility scale. See [the announcement](/announcements/product-updates/2025-09-25-new-dynamic-circuits) for more details.\n", "\n", "\n", - "Dynamic circuits are powerful tools with which your can measure qubits in the middle of a quantum circuit execution and then perform classical logic operations within the circuit, based on the outcome of those mid-circuit measurements. This process is also known as _classical feedforward_. While these are early days of understanding how best to take advantage of dynamic circuits, the quantum research community has already identified a number of use cases, such as the following:\n", + "Dynamic circuits are powerful tools with which you can measure qubits in the middle of a quantum circuit execution and then perform classical logic operations within the circuit, based on the outcome of those mid-circuit measurements. This process is also known as _classical feedforward_. While these are early days of understanding how best to take advantage of dynamic circuits, the quantum research community has already identified a number of use cases, such as the following:\n", "\n", "* Efficient quantum state preparation, such as [GHZ state,](https://journals.aps.org/prxquantum/abstract/10.1103/PRXQuantum.5.030339) [W-state,](https://arxiv.org/abs/2403.07604) (for more information about W-state, also refer to [\"State preparation by shallow circuits using feed forward\"](https://arxiv.org/abs/2307.14840)) and a broad class of [matrix product states](https://arxiv.org/abs/2404.16083)\n", "* [Efficient long-range entanglement](https://journals.aps.org/prxquantum/abstract/10.1103/PRXQuantum.5.030339) between qubits on the same chip by using shallow circuits\n", diff --git a/docs/guides/measure-qubits.ipynb b/docs/guides/measure-qubits.ipynb index 100d29ebec9..0a96d62aab5 100644 --- a/docs/guides/measure-qubits.ipynb +++ b/docs/guides/measure-qubits.ipynb @@ -193,16 +193,18 @@ }, { "cell_type": "markdown", + "id": "b1c5f875-6dfb-48e9-83f4-b25ba516af83", "metadata": {}, "source": [ "## Apply a mid-circuit measurement to a circuit\n", "\n", - "Use `MidCircuitMeasure` (**NEED LINK**) to apply a mid-circuit measurement. " + "Use `MidCircuitMeasure` (**NEED LINK**) to apply a mid-circuit measurement." ] }, { "cell_type": "code", "execution_count": null, + "id": "86b25b9d-403c-40bd-b028-e65bb71b4ea4", "metadata": {}, "outputs": [], "source": [ @@ -231,14 +233,14 @@ "* The Sampler primitive requires circuit measurements. You can add circuit measurements with the Estimator primitive, but they are ignored.\n", "* **QUESTION**: Can you use a mid-circuit measurement with a regular end-of-circuit measurement?\n", "\n", - "\n" + "" ] }, { "cell_type": "markdown", + "id": "f6c0eeae-9850-4761-beac-1a70c31a7bc7", "metadata": {}, "source": [ - "\n", "## Next steps\n", "\n", "\n", From 9920d9fb5064bf0c276ffd21aac2cbc455f904da Mon Sep 17 00:00:00 2001 From: Rebecca Dimock Date: Mon, 6 Oct 2025 15:51:26 -0500 Subject: [PATCH 3/5] Clarify when you'd use it --- docs/guides/measure-qubits.ipynb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/guides/measure-qubits.ipynb b/docs/guides/measure-qubits.ipynb index 0a96d62aab5..af8b19b05c1 100644 --- a/docs/guides/measure-qubits.ipynb +++ b/docs/guides/measure-qubits.ipynb @@ -43,7 +43,7 @@ " \\end{cases}\n", "$$\n", "\n", - "## Apply a measurement to the end of a circuit\n", + "## Apply a measurement to a circuit\n", "\n", "There are several ways to apply measurements to a circuit:\n", "\n", @@ -196,9 +196,9 @@ "id": "b1c5f875-6dfb-48e9-83f4-b25ba516af83", "metadata": {}, "source": [ - "## Apply a mid-circuit measurement to a circuit\n", + "### `MidCircuitMeasure` method\n", "\n", - "Use `MidCircuitMeasure` (**NEED LINK**) to apply a mid-circuit measurement." + "Use `MidCircuitMeasure` (**NEED LINK**) to apply a mid-circuit measurement. While you can use `QuantumCircuit.measure` for a mid-circuit measurement, `MidCircuitMeasure` is designed specifically for mid-circuit measurements, and is therefore typically a better choice. For example, it adds less overhead to your circuit than when using QuantumCircuit.measure`." ] }, { @@ -231,7 +231,6 @@ "* Circuits that contain operations _after_ a measurement are called dynamic circuits. Not all QPUs support these.\n", "* There must be at least one classical register in order to use measurements.\n", "* The Sampler primitive requires circuit measurements. You can add circuit measurements with the Estimator primitive, but they are ignored.\n", - "* **QUESTION**: Can you use a mid-circuit measurement with a regular end-of-circuit measurement?\n", "\n", "" ] From 7f5c26a231e7fa9fe08581ca3a1a0ad9415888f6 Mon Sep 17 00:00:00 2001 From: Rebecca Dimock Date: Tue, 7 Oct 2025 10:30:25 -0500 Subject: [PATCH 4/5] intro from jessie --- docs/guides/measure-qubits.ipynb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/guides/measure-qubits.ipynb b/docs/guides/measure-qubits.ipynb index af8b19b05c1..5aa1110f661 100644 --- a/docs/guides/measure-qubits.ipynb +++ b/docs/guides/measure-qubits.ipynb @@ -43,6 +43,13 @@ " \\end{cases}\n", "$$\n", "\n", + "## Mid-circuit measurements\n", + "\n", + "Mid-circuit measurements are a key component of dynamic circuits. Prior to `qiskit-ibm-runtime` v0.43.0, `measure` was the only measurement instruction in Qiskit. Mid-circuit measurements, however, have different tuning requirements than _terminal_ measurements (measurements that happen at the end of a circuit). For example, you need to consider the instruction duration when tuning a mid-circuit measurement because longer instructions cause noisier circuits. You don't need to consider instuction duration for terminal measurements because there are no instructions after terminal measurements.\n", + "\n", + "\n", + "In `qiskit-ibm-runtime` v0.43.0, the `MidCircuitMeasure` (**link to API**) instruction was introduced. As the name suggests, it is a new measurement instruction that is optimized for mid-circuit on IBM QPUs.\n", + "\n", "## Apply a measurement to a circuit\n", "\n", "There are several ways to apply measurements to a circuit:\n", @@ -198,6 +205,8 @@ "source": [ "### `MidCircuitMeasure` method\n", "\n", + "\n", + "\n", "Use `MidCircuitMeasure` (**NEED LINK**) to apply a mid-circuit measurement. While you can use `QuantumCircuit.measure` for a mid-circuit measurement, `MidCircuitMeasure` is designed specifically for mid-circuit measurements, and is therefore typically a better choice. For example, it adds less overhead to your circuit than when using QuantumCircuit.measure`." ] }, From e98d4d3cea76bc3c91cf9c9ab48a03dbf1baa4e4 Mon Sep 17 00:00:00 2001 From: Rebecca Dimock Date: Tue, 7 Oct 2025 10:37:11 -0500 Subject: [PATCH 5/5] typo --- docs/guides/measure-qubits.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guides/measure-qubits.ipynb b/docs/guides/measure-qubits.ipynb index 5aa1110f661..70716d8f58d 100644 --- a/docs/guides/measure-qubits.ipynb +++ b/docs/guides/measure-qubits.ipynb @@ -45,7 +45,7 @@ "\n", "## Mid-circuit measurements\n", "\n", - "Mid-circuit measurements are a key component of dynamic circuits. Prior to `qiskit-ibm-runtime` v0.43.0, `measure` was the only measurement instruction in Qiskit. Mid-circuit measurements, however, have different tuning requirements than _terminal_ measurements (measurements that happen at the end of a circuit). For example, you need to consider the instruction duration when tuning a mid-circuit measurement because longer instructions cause noisier circuits. You don't need to consider instuction duration for terminal measurements because there are no instructions after terminal measurements.\n", + "Mid-circuit measurements are a key component of dynamic circuits. Prior to `qiskit-ibm-runtime` v0.43.0, `measure` was the only measurement instruction in Qiskit. Mid-circuit measurements, however, have different tuning requirements than _terminal_ measurements (measurements that happen at the end of a circuit). For example, you need to consider the instruction duration when tuning a mid-circuit measurement because longer instructions cause noisier circuits. You don't need to consider instruction duration for terminal measurements because there are no instructions after terminal measurements.\n", "\n", "\n", "In `qiskit-ibm-runtime` v0.43.0, the `MidCircuitMeasure` (**link to API**) instruction was introduced. As the name suggests, it is a new measurement instruction that is optimized for mid-circuit on IBM QPUs.\n",