# Any thought on I11.4

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

@qml.qnode(dev)
def circuit_1(theta):
“”"Implement the circuit and measure Z I and I Z.

``````Args:
theta (float): a rotation angle.

Returns:
float, float: The expectation values of the observables Z I, and I Z
"""
##################
##################
qml.RX(2*theta,wires=0)
qml.RY(4*theta,wires=1)
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))
``````

@qml.qnode(dev)
def circuit_2(theta):
“”"Implement the circuit and measure Z Z.

``````Args:
theta (float): a rotation angle.

Returns:
float: The expectation value of the observable Z Z
"""

##################
##################
qml.RX(2*theta,wires=0)
qml.RY(4*theta,wires=1)

return qml.expval(qml.PauliZ(0)@qml.PauliZ(1))
``````

def zi_iz_combination(ZI_results, IZ_results):
“”"Implement a function that acts on the ZI and IZ results to
produce the ZZ results. How do you think they should combine?

``````Args:
ZI_results (array[float]): Results from the expectation value of
ZI in circuit_1.
IZ_results (array[float]): Results from the expectation value of
IZ in circuit_2.

Returns:
array[float]: A combination of ZI_results and IZ_results that
produces results equivalent to measuring ZZ.
"""

combined_results=np.zeros(len(ZI_results))

##################
##################

b=np.array(ZI_results)
c=np.array(IZ_results)

Z=np.kron(b,c)
combined_results.append(Z)

return combined_results
``````

theta = np.linspace(0, 2 * np.pi, 100)

# Run circuit 1, and process the results

circuit_1_results = np.array([circuit_1(t) for t in theta])

ZI_results = circuit_1_results[:, 0]
IZ_results = circuit_1_results[:, 1]
combined_results = zi_iz_combination(ZI_results, IZ_results)

# Run circuit 2

ZZ_results = np.array([circuit_2(t) for t in theta])

plot = plotter(theta, ZI_results, IZ_results, ZZ_results, combined_results)

if I increases Len by 2 it doesn’t work to accommodate the tensor product combined_results=np.zeros(2*len(ZI_results))

Hi @Vedant_Dwivedi, thanks for your question! You’re on the right track, but let’s take a closer look at the data types in the `zi_iz_combination` function.

``````def zi_iz_combination(ZI_results, IZ_results):
"”"Implement a function that acts on the ZI and IZ results to
produce the ZZ results. How do you think they should combine?

Args:
ZI_results (array[float]): Results from the expectation value of
ZI in circuit_1.
IZ_results (array[float]): Results from the expectation value of
IZ in circuit_2.

Returns:
array[float]: A combination of ZI_results and IZ_results that
produces results equivalent to measuring ZZ.
"""
``````

[EDIT: While it’s true that the observables `ZI` and `IZ` need to be tensored together to produce the observable `ZZ`] The expectation values being input to this function are just lists (arrays) of floats, and this function must return an array of floats of the same shape of the two inputs arrays. In the code snippet you posted, the two arrays are being tensored together using `np.kron`:

``````b=np.array(ZI_results)
c=np.array(IZ_results)
Z=np.kron(b,c)
``````

Is the shape of `Z` the same as `ZI_results` and `IZ_results`? (It might be helpful to try a small test example locally to see what happens here). What else might you do with the two arrays?

Hope that helps, please let us know if you have any further questions!

hoped I understood correctly but still no correct answer.

combined_results=np.zeros(2*len(ZI_results))

``````##################
##################
b=np.array(ZI_results)
c=np.array(IZ_results)
combined_results=np.kron(b,c)``````

The aim here is, given `ZI_results` and `IZ_results`, to combine them (mathematically) to create an array of the same length that represents the `ZZ` results. What the function returns must have the same dimension as the input;

``````combined_results=np.zeros(2*len(ZI_results))
``````

will give a result with twice the length of the inputs (and using `kron` will similarly give something with twice the length).

[BTW I have made an error in my earlier post, which I have edited; ZI and IZ do not tensor together to create ZZ, but rather they simply multiply. I’ve amended the original post.]

Got it Thanks @glassnotes

@Vedant_Dwivedi awesome, glad to hear it!