# Mid-circuit measurement with qml.state()

**URL:** <https://discuss.pennylane.ai/t/mid-circuit-measurement-with-qml-state/7491>\
**Category:** PennyLane Help\
**Created:** [November 5, 2024, 12:06pm UTC](https://discuss.pennylane.ai/t/mid-circuit-measurement-with-qml-state/7491 "2024-11-05T12:06:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jarrett\_smalley](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jarrett_smalley/32/1876_2.png) [@jarrett\_smalley](https://discuss.pennylane.ai/u/jarrett_smalley)\
**Post date:** [November 5, 2024, 12:06pm UTC](https://discuss.pennylane.ai/t/mid-circuit-measurement-with-qml-state/7491/1 "2024-11-05T12:06:10Z")

</div>

I am looking for a way to do mid-circuit resets with the state vector, though at the moment there is an error message that the state is not supported.

```auto
@qml.qnode(qml.device("default.qubit", wires=1))
def f():
    qml.measure(0, reset=True)
    return qml.state()
f()

```

The returned error being:

```auto
ValueError: Cannot use StateMP as a measurement when using qml.defer_measurements. Deferred measurements can occur automatically when using mid-circuit measurements on a device that does not support them.

```

For some uses, this can be worked around by defining a custom projection op, but this comes with its own specificities

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [November 6, 2024, 10:54pm UTC](https://discuss.pennylane.ai/t/mid-circuit-measurement-with-qml-state/7491/2 "2024-11-06T22:54:42Z")

</div>

Hi @jarrett_smalley,

The issue here isn’t with reset, it’s with returning qml.state().

Currently, [`counts()`](https://docs.pennylane.ai/en/stable/code/api/pennylane.counts.html), [`expval()`](https://docs.pennylane.ai/en/stable/code/api/pennylane.expval.html), [`probs()`](https://docs.pennylane.ai/en/stable/code/api/pennylane.probs.html), [`sample()`](https://docs.pennylane.ai/en/stable/code/api/pennylane.sample.html), and [`var()`](https://docs.pennylane.ai/en/stable/code/api/pennylane.var.html) are supported. Are you able to use one of these instead?

You can learn more about using mid-circuit measurements in PennyLane [here](https://docs.pennylane.ai/en/stable/introduction/dynamic_quantum_circuits.html) in the docs.

Let me know if you have any further questions!

---

<div class="post-metadata">

**Author:** ![jarrett\_smalley](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jarrett_smalley/32/1876_2.png) [@jarrett\_smalley](https://discuss.pennylane.ai/u/jarrett_smalley)\
**Post date:** [November 7, 2024, 1:39pm UTC](https://discuss.pennylane.ai/t/mid-circuit-measurement-with-qml-state/7491/3 "2024-11-07T13:39:51Z")

</div>

I am trying for atleast a temporary workaround to return qml.state(), but I have not been able to follow the way in which reset is implemented in pennylane/measurements/mid\_measure.py and then in pennylane/transforms/defer\_measurement.py .

Can you provide any clarity on how the reset itself is implemented (as I am otherwise not directly looking to use the output of the measurement)?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [November 7, 2024, 10:49pm UTC](https://discuss.pennylane.ai/t/mid-circuit-measurement-with-qml-state/7491/4 "2024-11-07T22:49:31Z")

</div>

Hi @jarrett_smalley,

Unfortunately resetting qubits is only available via mid-circuit measurements, and this is not compatible with returning qml.state().

You can see all occurances of “reset” in the PennyLane repo [here](https://github.com/search?q=repo%3APennyLaneAI%2Fpennylane%20reset&type=code). However I’m not sure that you’ll find what you’re looking for.

I hope this can help you though.
