Mid-circuit measurement with qml.state()

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.

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

The returned error being:

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

Hi @jarrett_smalley,

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

Currently, counts(), expval(), probs(), sample(), and var() are supported. Are you able to use one of these instead?

You can learn more about using mid-circuit measurements in PennyLane here in the docs.

Let me know if you have any further questions!

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)?

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. However I’m not sure that you’ll find what you’re looking for.

I hope this can help you though.