# Help me to understand the quantum circuit

Hi, I have a conceptual doubt and don’t know where to ask so i tried to ask my doubt here.

The above is the quantum circuit and my doubt is how the matrix multiplication would be done after the Ry of second qubit , I mean to say that we know that CNOT is 4x4 matrix and if i start from the
[ 1 0 ] matrix of the second qubit and then evaluate the hadarmard gate matrix and then Ry matrix .So finally before the CNOT gate matrix for second qubit I will get the 1x2 matrix after the multiplication of Ry matrix in second qubit then the question is how should i proceed further to understand the matrix multiplicaion with CNOT gate matrix.

I want to know the final matrix of each qubit 1 and qubit 2.

What you’re observing here is exactly the phenomenon of entanglement. When we only apply local gates to each qubit, we can represent each qubit’s state with just a 2-dimensional vector. However, as soon as we use a non-local gate (like the CNOT), this picture no longer works!

Instead, we have to consider the joint system (q[0], q[1]), which is represented by a 4-dimensional vector (one dimension for each possible computational basis state of the joint system (00, 01, 10, 11) ). Then multiplying by a CNOT (which is represented by a 4x4 matrix) makes sense.

This is exactly the phenomenon of entanglement. We can no longer describe the joint system using the individual subsystems.

1 Like

qml.expval(qml.PauliZ(1))

What is the meaning of the above line?
what I understand is that the pauliZ gate is applied at the final i.e after CNOT gate to the second qubit and then calculating the expectation value of the second qubit.

My question is that now if they are in entangled state then how expectation value of individual qubit can be calculated like here the expectation value of second qubit is calculating?

qml.expval(qml.PauliZ(1))


in PennyLane translates to computing \langle \psi(\boldsymbol{\theta})\mid I\otimes Z\mid\psi(\boldsymbol \theta)\rangle. That is, we are computing the expectation value of the two qubit observable I_0\otimes Z_1 on the output state.

In PennyLane, the identity on the first qubit does not need to be explicitly provided — it is implicitly assumed if not present.

what I understand is that the pauliZ gate is applied at the final

Not quite — we are measuring the expectation value of the Pauli-Z observable, not applying a final Pauli-Z gate. To measure the expectation value of an observable experimentally, we perform the following process:

1. Evolve the circuit to the final state.

2. Apply additional gates to rotate the measured qubits into the measurement basis, if required. In the case of measuring in the Pauli-Z, no rotations are needed, so no additional gates are applied.

3. Sample from the measured qubits, and take the mean value.

if they are in entangled state then how expectation value of individual qubit can be calculated like here the expectation value of second qubit is calculating?

You can think of this in two ways — the approach above (taking the expectation value of I\otimes Z) or by tracing out the first subsystem to determine the reduced density matrix of the second subsystem. We can then take the expectation value of Z with respect to the reduced density matrix:

\langle \psi(\boldsymbol{\theta})\mid I\otimes Z\mid\psi(\boldsymbol \theta)\rangle = \text{Tr}(|\psi\rangle\langle\psi|I\otimes Z) = \text{Tr}(\rho_1 Z)

where \rho_1 = \text{Tr}_0(|\psi\rangle\langle\psi|).