# One wire with multi-observables

**URL:** <https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032>\
**Category:** PennyLane Help\
**Created:** [May 10, 2021, 6:38am UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032 "2021-05-10T06:38:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![qhc](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/qhc/32/761_2.png) [@qhc](https://discuss.pennylane.ai/u/qhc)\
**Post date:** [May 10, 2021, 6:38am UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/1 "2021-05-10T06:38:21Z")

</div>

in the quantum-classical hybird neural network, to avoid time consuming, I can not give the qubit a great value.  
when I put 3 observables on one wire and put measurement process on, I get some error as below:

 ![03](https://canada1.discourse-cdn.com/flex012/uploads/pennylane/original/1X/775f516d22ac977e105eb551349aaec69152e8d8.png)  
it says **Only observables that are qubit-wise commuting Pauli words can be returned on the same wire.**  
when I take the middle observable as **qml.Identity** , same error happens.  
are there some proper qubit-wise commuting observables in pennylane?  
or some other methods broaden the output dimension beyond nqubits?

---

<div class="post-metadata">

**Author:** ![Maria\_Schuld](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/maria_schuld/32/166_2.png) [@Maria\_Schuld](https://discuss.pennylane.ai/u/Maria_Schuld)\
**Post date:** [May 10, 2021, 1:15pm UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/2 "2021-05-10T13:15:26Z")

</div>

Hey @qhc and welcome to the forum!

Hmm, could you post a fully running code example that reproduces your error? And do you have the latest PL version installed?

For example, running this code with PL 0.15.1 works with no problems:

```auto
import pennylane as qml

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

@qml.qnode(dev)
def circuit():
    qml.Hadamard(wires=0)
    return qml.expval(qml.Identity(0)), qml.expval(qml.Identity(0))

print(circuit()) # [1., 1.]

```

---

<div class="post-metadata">

**Author:** ![qhc](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/qhc/32/761_2.png) [@qhc](https://discuss.pennylane.ai/u/qhc)\
**Post date:** [May 11, 2021, 1:58am UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/4 "2021-05-11T01:58:27Z")

</div>

thanks for your reply, my PL version is 0.15.1, my code:

```
import numpy as np
import pennylane as qml
from pennylane.devices.default_qubit_tf import DefaultQubitTF

dev2 = DefaultQubitTF(wires=8)
@qml.qnode(dev2, diff_method='backprop', interface='tf')
def circuit(inputs, enc_1):
    for i in range(8):
        qml.Hadamard(wires=i)
    # ====================================================
    # ======================== enc_1 =====================
    for i in range(8):
        qml.RZ(enc_1[i]*inputs[i], wires=(i))
        # qml.RY(enc_1[2*i+1]*inputs[2*i+1], wires=(2*i+1))
    # ====================================================
    # ======================== output =====================
    output = []
    for ind in range(8):
        output.append(qml.expval(qml.PauliX(ind)))
        output.append(qml.expval(qml.Identity(ind)))
        output.append(qml.expval(qml.PauliZ(ind)))
    return output

inputs = np.float64(np.random.randn(24))
enc_1 = np.float64(np.random.randn(8))
print(circuit(inputs=inputs, enc_1=enc_1))

```

output: **QuantumFunctionError** : Only observables that are qubit-wise commuting Pauli words can be returned on the same wire

---

<div class="post-metadata">

**Author:** ![Maria\_Schuld](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/maria_schuld/32/166_2.png) [@Maria\_Schuld](https://discuss.pennylane.ai/u/Maria_Schuld)\
**Post date:** [May 11, 2021, 12:09pm UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/5 "2021-05-11T12:09:42Z")

</div>

Thanks for the details!

The error message actually says it all here: PennyLane allows for multiple measurements on the same wire in a simulation as long as the observables are Pauli words (i.e. Pauli operators, identities or tensor products thereof) **and commute**. Your measurements are unfortunately non-commuting.

One reason for this restriction is that internally, PL decomposes measurements into a pre-measurement circuit and a simple measurement. But if two measurements don’t commute, their pre-measurement circuits are not the same. However, this may be up for a refactor.

If you would like to champion the idea that PL allows non-commuting measurements on the same wires on simulators, you could open an [issue](https://github.com/PennyLaneAI/pennylane/issues) with your feature request - the more users need something, the more likely it gets implemented soon 🙂

---

<div class="post-metadata">

**Author:** ![qhc](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/qhc/32/761_2.png) [@qhc](https://discuss.pennylane.ai/u/qhc)\
**Post date:** [May 11, 2021, 12:35pm UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/6 "2021-05-11T12:35:16Z")

</div>

does there exist some commuting Pauli words observables in PL?

---

<div class="post-metadata">

**Author:** ![sjahangiri](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/sjahangiri/32/1443_2.png) [@sjahangiri](https://discuss.pennylane.ai/u/sjahangiri)\
**Post date:** [May 11, 2021, 8:29pm UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/7 "2021-05-11T20:29:41Z")

</div>

Hi @qhc. If I understand your question correctly, yes PennyLane supports multiple measurements of such commuting observables performed on the same wire. For instance, the error in your code can be fixed by removing one of the `PauliX` or `PauliZ` measurements while keeping the `Identity` one such as:

```
for ind in range(8):
    output.append(qml.expval(qml.PauliX(ind)))
    output.append(qml.expval(qml.Identity(ind)))
return output

```

PennyLane also supports measurements of tensor product of observables as explained [here](https://pennylane.readthedocs.io/en/stable/introduction/measurements.html#tensor-observables). Please let us know if you have any other question.

---

<div class="post-metadata">

**Author:** ![qhc](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/qhc/32/761_2.png) [@qhc](https://discuss.pennylane.ai/u/qhc)\
**Post date:** [May 12, 2021, 3:28am UTC](https://discuss.pennylane.ai/t/one-wire-with-multi-observables/1032/8 "2021-05-12T03:28:50Z")

</div>

thanks, you all help me a lot  
😀
