# Measuring in rotated basis for mult-qubit circuits

In a previous question (and others), someone asked about measuring on a basis other than the computational one, but for one qubit circuit. Here it was asked for a specific basis.

Suppose I have a two-qubit circuit and have to measure the expectation value of an operator formed by the sum of Kroeneker products of Pauli Matrices (X, Y, Z, and I), such as

$$\hat O= aX\otimes X + bX\otimes Y + cY\otimes Z + d Z\otimes I.$$

To me seems clear that measuring $$X\otimes X$$ is just to put Hadarmad gates on both qubits and measure them. What about the "crossed" products such as $$X\otimes Y$$ or $$Z\otimes I$$?

It also seems that we can measure simultaneously products that commute such as $$X\otimes I$$ and $$I \otimes X$$. How the gates used to perform the measurements on one or another product can be handled to properly perform the simultaneous measurement?

The logic here is very similar to the single qubit case. We need to apply single qubit operators on all qubits to transform the crossed product into $$Z_1Z_2$$. For example, for $$X_1Y_2$$, it means to apply $$H_1H_2S^\dagger_2$$, since

$$HXH = Z$$ and $$HS^\dagger Y S H = HXH=Z.$$

As for products of the type $$X_1I_2$$ etc., you can simply transform only the non-idenitity qubit, and either measure this qubit, or if due to technical reasons you must measure all qubits, calculate the marginal average by summing over the measurement results of the qubit for which you're "measuring the identity".

Hope this helps!

I suggest the easiest thing to do is measure what you need all in one go instead of breaking it down into separate terms. Find the unitary $$U$$ such that $$U\hat OU^\dagger$$ is diagonal. This is just the same as computing the normalized eigenvectors $$|\lambda_1\rangle,|\lambda_2\rangle,|\lambda_3\rangle,|\lambda_4\rangle$$ and writing out the $$4\times 4$$ matrix $$U=\left(\begin{array}{c} \langle\lambda_1| \\ \langle\lambda_2| \\ \langle\lambda_3| \\ \langle\lambda_4| \end{array}\right).$$ If you implement the circuit for $$U$$ and then measure in the standard basis, you will find the probabilities $$p_1$$ to $$p_4$$ corresponding to the 4 measurement outcomes. Your expectation value is $$\langle\hat O\rangle=\sum_ip_i\lambda_i.$$

Note that if $$\hat O$$ has some degeneracy of eigenvalues, there is some freedom in choosing $$U$$ that you can use to make it as simple as possible to implement.

Why does this work? Measuring $$\langle\hat O\rangle$$ is the same as evaluating $$\sum_i|\langle\lambda_i|\psi\rangle|^2\lambda_i$$ for an initial state $$|\psi\rangle$$. We want to measure the values $$|\langle\lambda_i|\psi\rangle|^2$$, which we write as $$|\langle i|U|\psi\rangle|^2$$, and is hence equivalent to measuring in the standard basis $$\{|i\rangle\}$$ on a state $$U|\psi\rangle$$.

• Thanks @DaftWullie. I agree this is the simplest solution at all. However, the point is that I'm trying to use the Quantum Computer with the Variational Quantum Eigensolver to implement a 'quantum' solution. Diagonalizing the operator does not let to a "general" procedure to be employed in a quantum circuit, since it relies on a "classic" diagonalization step. I don't know if my point is clear... Feb 16 at 10:47
• Ah, OK. I didn't get that from your question. Did you consider implementing a unitary of the form $U=e^{i\hat O t}$, e.g. via Hamiltonian simulation techniques, and performing phase estimation? Perhaps overkill for two qubits, but generalises. Feb 16 at 11:07
• Yes, I did. However, for the purposes of my simulation, I'd like to stay with VQE, since it is a primary step (though to be 'easier") followed by a phase estimation step (the expensive one). Feb 16 at 11:12

If you take $$\sigma_i\otimes\sigma_j$$ as bases, with $$i,j=0,1,2,3$$ stands for identity matrix and Pauli matrices, starting from $$\sigma_1\otimes\sigma_1$$, you can transfer it into $$\sum_{ij}a_{ij}\sigma_i\otimes\sigma_j$$(except $$\sigma_0\otimes\sigma_0)$$ as long as $$\sum_{ij}a_{ij}^2=1$$ under unitary operation, i.e. $$U\sigma_1\otimes\sigma_1U^\dagger$$. Obviously $$\sigma_1\otimes\sigma_2$$ and $$\sigma_3\otimes\sigma_0$$(In your notation is $$X\otimes Y$$ and $$Z\otimes I$$) are special cases. The proof of the statement can be found in this link.

As for the second problem(btw, a post better focus on one problem :), there's a result states that if two hermitian observables commute, they have the same set eigenvectors, and they are complete. In your case, $$I\otimes X$$ and $$X\otimes I$$ have eigenvectors $$|++\rangle,|+-\rangle,|-+\rangle|--\rangle$$ where $$|+\rangle$$ and $$|-\rangle$$ are eigenvectors of $$X$$ with eigenvalues $$1$$ and $$-1$$ respectively. So measure in this base, but attain different values to the measurement result, we have actually measure them simultaneously!

• I'm sorry @narip, but I didn't get to your point. I do understand that the unitary transformation doesn't change the eigenvalues. However, how I can use this fact to solve my issue. About the commutative operators, could you indicate to me a reference of how to properly attain different values to the measurement results? Feb 16 at 14:52
• Let's take $I\otimes X$ and $X\otimes I$ as an example. To measure in $|++\rangle,|+-\rangle,|-+\rangle|--\rangle$ bases, if the result are $|+-\rangle$ state, we attain this result with values (1,1) for $X\otimes I$ while record (1,-1) for $I \otimes X$. Feb 17 at 0:15
• Measure observable $X$ merely attain value 1 for result $|+\rangle$ and attain value -1 for result $|-\rangle$. Feb 17 at 0:16
• Got it! Thanks. Feb 18 at 1:42