# Combined measurement results and error on numpy

**URL:** <https://discuss.pennylane.ai/t/combined-measurement-results-and-error-on-numpy/595>\
**Category:** PennyLane Help\
**Created:** [September 27, 2020, 11:48am UTC](https://discuss.pennylane.ai/t/combined-measurement-results-and-error-on-numpy/595 "2020-09-27T11:48:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanspace](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/alanspace/32/320_2.png) [@alanspace](https://discuss.pennylane.ai/u/alanspace)\
**Post date:** [September 27, 2020, 11:48am UTC](https://discuss.pennylane.ai/t/combined-measurement-results-and-error-on-numpy/595/1 "2020-09-27T11:48:57Z")

</div>

I want to make combined measurement on the bell state, actually I don’t know if I implement the measurement correctly.

```
import pennylane as qml
from pennylane import numpy as np

dev = qml.device('default.qubit', wires = ['wire1', 'wire2'], shots = 1000)

@qml.qnode(dev, interface='autograd')
def circuit(params):
    qml.RX(params[0], wires = 'wire1') # Rx is applied with the 1st parameter, on the first qubit
    qml.RY(params[1], wires = 'wire1') # Ry is applied with the 2nd parameter, on the first qubit
    qml.CNOT(wires = ['wire1', 'wire2']) # CNOT is applied on the first and second qubit
    #my_circuit(wires = (1,0))
    return qml.sample(qml.PauliZ('wire1')), qml.sample(qml.PauliZ('wire2'))

```

Then I want to see if it is maximally entangled. I follow [the tutorial](https://pennylane.readthedocs.io/en/stable/introduction/measurements.html) for finding if the two qubits are maximally entangled and type the below codes:

```
result = circuit(params) 
result.shape
np.all(result['wire1'] == result['wire2'])

```

It returns the error:

`only integers, slices (`:`), ellipsis (`…`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices`

Can I keep the naming of the wires as string ?  
Also, can I measure .sample(), expval(), var(), probs(wires) at the same time?

Thank you!

---

<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:** [September 28, 2020, 2:02pm UTC](https://discuss.pennylane.ai/t/combined-measurement-results-and-error-on-numpy/595/2 "2020-09-28T14:02:05Z")

</div>

Hey @alanspace,

The following should work without an error:

```python
result = circuit(params) 
result.shape
np.all(result[0] == result[1])

```

The `result` object returned by the `circuit()`is a NumPy array where the first axis corresponds to the quantities added to the `return ... ` line, i.e., so that `result[0]` is the samples from the first wire. The way you were trying would be more suited to if `result` is a dictionary, but that is a bit harder to support with respect to all the differentiation frameworks.

> Also, can I measure .sample(), expval(), var(), probs(wires) at the same time?

You can combine different measurement types as long as you do not measure a wire more than once. If you want to measure multiple quantities on a single wire, you can use the [QNodeCollection](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.QNodeCollection.html) class.

Also, regarding the problem you’re considering of maximally entangled Bell states - showing that something is entangled typically requires measurements in multiple bases. The code you shared measures in just the `PauliZ` computational basis. In that basis, even the unentangled |00\> state will have the same set of samples from both qubits, i.e., `np.all(result['wire1'] == result['wire2'])`.

The code block below shows how you can use a [QNodeCollection](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.QNodeCollection.html) to investigate entanglement:

```python
import pennylane as qml
from pennylane import numpy as np

dev = qml.device('default.qubit', wires = ['wire1', 'wire2'])

def circuit(param, **kwargs):
    qml.RY(param, wires="wire1")
    qml.CNOT(wires = ['wire1', 'wire2'])

obs = [qml.PauliX('wire1') @ qml.PauliX('wire2'),
       qml.PauliY('wire1') @ qml.PauliY('wire2'),
       qml.PauliZ('wire1') @ qml.PauliZ('wire2')]
qnodes = qml.map(circuit, obs, dev)

print(type(qnodes))
print(qnode(0.0))
print(qnode(np.pi / 2))

```

Here we switch from using samples (which are not differentiable in PennyLane) to expectation values. We return three numbers giving the expectation values of joint measurements of XX, YY, ZZ. The GHZ state is entangled and our measurements should show a correlation in all bases: [1, -1, 1].
