# Some questions about mid-measurement

**URL:** <https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028>\
**Category:** PennyLane Help\
**Created:** [February 5, 2024, 6:12pm UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028 "2024-02-05T18:12:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![q36111095](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@q36111095](https://discuss.pennylane.ai/u/q36111095)\
**Post date:** [February 5, 2024, 6:12pm UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/1 "2024-02-05T18:12:05Z")

</div>

Hello, attached code is an example code from qml.measure().

If I plot the function by the attached code, I will get a figure without mid-measurement of wires=1.  
However, if I comment (add #) qml.qnode(dev), I will get a figure with mid-measurement correctly.

My questions are listed below:

(1) I wonder whether qml.measure support lightning.qubit.  
Since I delete qml.cond(), the returned probability changes.  
Then, it validates that the qml.cond() indeed works.

```auto
import pennylane as qml
import os

dev = qml.device("lightning.qubit", wires=2)

qml.qnode(dev)
def func(x, y):
    qml.Hadamard(0)
    qml.CNOT(wires=[0, 1])

    m_0 = qml.measure(1)
    qml.cond(m_0, qml.RY)(y, wires=0)
    
    return qml.probs(wires=[0])

x = 1
y = 0.3
fig, ax = qml.draw_mpl(func)(x, y)
fig.savefig(os.path.join(os.getcwd(), "QNN_ex.jpg"))

```

(2)The note from qml.cond states that:

```auto
If the first argument of cond is a measurement value (e.g., m_0 in qml.cond(m_0, qml.RY)), then m_0 == 1 is considered internally.

```

Can I say that qml.cond implements qml.RY no matter what the mid-measurement value is?  
Then, what does the mid-measurement operation affect wires=0?

\*\*\*The environment I used:

```auto
Name: PennyLane
Version: 0.33.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /home/ihcl10f/anaconda3/envs/GJ_0122/lib/python3.8/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning

Platform info: Linux-6.5.0-14-generic-x86_64-with-glibc2.17
Python version: 3.8.18
Numpy version: 1.24.4
Scipy version: 1.10.1
Installed devices:
- default.gaussian (PennyLane-0.33.1)
- default.mixed (PennyLane-0.33.1)
- default.qubit (PennyLane-0.33.1)
- default.qubit.autograd (PennyLane-0.33.1)
- default.qubit.jax (PennyLane-0.33.1)
- default.qubit.legacy (PennyLane-0.33.1)
- default.qubit.tf (PennyLane-0.33.1)
- default.qubit.torch (PennyLane-0.33.1)
- default.qutrit (PennyLane-0.33.1)
- null.qubit (PennyLane-0.33.1)
- lightning.qubit (PennyLane-Lightning-0.33.1)
None

```

Thanks for replying in advance!

---

<div class="post-metadata">

**Author:** ![isaacdevlugt](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/isaacdevlugt/32/1159_2.png) [@isaacdevlugt](https://discuss.pennylane.ai/u/isaacdevlugt)\
**Post date:** [February 6, 2024, 10:39pm UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/2 "2024-02-06T22:39:41Z")

</div>

Hey @q36111095! Welcome to the forum 🙂

Indeed, mid-circuit measurements aren’t supported on lightning at the moment. Here’s a list of supported operations: [Lightning Qubit device — Lightning 0.34.0 documentation](https://docs.pennylane.ai/projects/lightning/en/stable/lightning_qubit/device.html)

> Can I say that qml.cond implements qml.RY no matter what the mid-measurement value is?

Nope! It implements `RY` when the measurement is `1`.

---

<div class="post-metadata">

**Author:** ![q36111095](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@q36111095](https://discuss.pennylane.ai/u/q36111095)\
**Post date:** [February 7, 2024, 4:18am UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/3 "2024-02-07T04:18:47Z")

</div>

Okay, I got it!  
I have tried to use default.qubit:

```auto
import pennylane as qml
import os

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def func(x, y):
    qml.Hadamard(0)
    qml.CNOT(wires=[0, 1])

    m_0 = qml.measure(1)
    qml.cond(m_0, qml.RY)(y, wires=0)
    
    return qml.probs(wires=[0])

x = 1
y = 0.3
fig, ax = qml.draw_mpl(func)(x, y)
fig.savefig(os.path.join(os.getcwd(), "QNN_ex.jpg"))

print(func(x, y))

```

The func(x, y) returns [0.51116588 0.48883412].  
It verifies that the qml.cond() works.

However, the figure still lacks of the midmeasure operation.  
 ![QNN_ex.jpg](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/3/364d92763166fcd5ef92c4b04c8d33a1a732e681.png)

Perhaps there are something wrong that I don’t notice.  
I will search for the figure problem first.

---

<div class="post-metadata">

**Author:** ![Tom\_Bromley](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/tom_bromley/32/129_2.png) [@Tom\_Bromley](https://discuss.pennylane.ai/u/Tom_Bromley)\
**Post date:** [February 7, 2024, 1:41pm UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/4 "2024-02-07T13:41:44Z")

</div>

Hi @q36111095, what version of PennyLane are you using? With the latest v0.34, I get the following drawing:  
 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/e/e129c2908fa55a1d8330a164d1bebfb505798d24.png)

If you would like to upgrade your PennyLane version, you can do:

```auto
pip install -u pennylane

```

---

<div class="post-metadata">

**Author:** ![q36111095](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@q36111095](https://discuss.pennylane.ai/u/q36111095)\
**Post date:** [February 7, 2024, 2:40pm UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/5 "2024-02-07T14:40:35Z")

</div>

The version of pennylane I use is 0.33.1, and the matplotlib version is 3.6.1.

I have tried to upgrade pennylane version to 0.34.0; however, it returns some error about incompatibility with other libraries.  
It seems that it is just the plot problem.  
Thanks for your replying!

---

<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:** [February 13, 2024, 8:06pm UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/6 "2024-02-13T20:06:58Z")

</div>

Hi @q36111095,

What is the incompatibility you’re seeing?

You could potentially try using [qml.draw()](https://docs.pennylane.ai/en/stable/code/api/pennylane.draw.html) instead.

---

<div class="post-metadata">

**Author:** ![q36111095](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@q36111095](https://discuss.pennylane.ai/u/q36111095)\
**Post date:** [February 15, 2024, 6:07am UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/7 "2024-02-15T06:07:26Z")

</div>

Hi, @CatalinaAlbornoz , sorry for my late replying.  
The error message of incompatibility is listed below:  
(pennylane=0.34.0, pennylane-lightning=0.34.0)

import pennylane as qml File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/ **init**.py”, line 33, in import pennylane.templates File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/templates/ **init**.py”, line 21, in from .embeddings import \* File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/templates/embeddings/ **init**.py”, line 20, in from .angle import AngleEmbedding File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/templates/embeddings/angle.py”, line 19, in from pennylane.ops import RX, RY, RZ File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/ops/ **init**.py”, line 25, in from .op\_math import \* File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/ops/op\_math/ **init**.py”, line 93, in from .adjoint import Adjoint, adjoint File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/ops/op\_math/adjoint.py”, line 24, in from pennylane.compiler import compiler File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/compiler/ **init**.py”, line 241, in from .compiler import available\_compilers, available, active\_compiler, active File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/compiler/compiler.py”, line 109, in \_refresh\_compilers() File “/home/user/anaconda3/envs/ENV/lib/python3.8/site-packages/pennylane/compiler/compiler.py”, line 91, in \_refresh\_compilers else metadata.entry\_points(group=“pennylane.compilers”) TypeError: entry\_points() got an unexpected keyword argument ‘group’

In addition, I try to use qml.draw() with pennylane-0.33.1 pennylane-lightning-0.34.0,  
and the function returns:  
 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/5/585a40fa0ddd9ac4287a496317bd68fdd7d9f880.png)

---

<div class="post-metadata">

**Author:** ![q36111095](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@q36111095](https://discuss.pennylane.ai/u/q36111095)\
**Post date:** [February 15, 2024, 9:08am UTC](https://discuss.pennylane.ai/t/some-questions-about-mid-measurement/4028/8 "2024-02-15T09:08:00Z")

</div>

Hello, @CatalinaAlbornoz.  
I recreate a new virtual envirionment, and reinstall pennylane=0.34.0.  
I successfully plot a figure below.

 ![image](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/2X/5/51b9a30eaadb997415ef761799e1b76c03dc531e.png)

I think the reason is that the version of some dependency libraries should be renewed when changing pennylane version.  
Thanks for your help!!!
