distance between two $\mathrm{SU}(2)$ matrices?

517 Views Asked by At

I want to compute the rotation distance between two $\mathrm{SU}(2)$ matrices. I tried to adapt this and I thought it was working, but then I discovered that numerical roundoff error can cause two matrices which should be approximately 0 degrees apart to be measured as 180 degrees apart.

import numpy as np
import numpy.linalg as la

phase = la.det(a) ** (-1.0 / 2.0)
a = phase * a
phase = la.det(b) ** (-1.0 / 2.0)
b = phase * b

ab = np.matmul(np.transpose(u1.conj()), b)
angle = np.rad2deg(np.absolute(np.arccos((np.trace(ab) - 0) / 2)))

While it looks like I could reimplement this using quaternions (I haven't tried yet), I'm wondering if this approach is mostly correct but has a bug or if this will never work. The issue seems to be something like this la.det(a) ** (-1.0 / 2.0) is producing different roots of unity or something like that. I don't have a test program to distribute, but I could prepare one if that would help.

1

There are 1 best solutions below

16
On BEST ANSWER

In short, I recommend two changes:

  1. adjust the phase of the product ab rather than handling a and b separately,
  2. take the absolute value of the argument of arccos.

Also, we can make things slightly faster by noting that $\det(A^*B)$ has magnitude $1$, which means that $\det(A^*B)^{-1/2} = \overline{\det(A^*B)^{1/2}}$, where $\bar z$ dentoes the complex conjugate of $z$.

Here are the distances from $I$ for some common gates, as measured by the metric defined below:

  • $X,Y,Z,H$: $\pi/2$
  • $S: \pi/4$

Here's a derivation/interpretation of the resulting "distance" (metric over $U(2)/U(1)$).

Let $A,B$ denote our unitary matrices, and let $A^*$ denote the conjugate transpose of $A$. If we consider $A^*B$ to be our "difference rotation", it suffices to define the distance of $A^*B$ from the identity matrix $I$.

Note that $A^*B$ has eigenvalues $e^{i\theta_1},e^{i \theta_2}$ for some angles $\theta_1,\theta_2$, and we have $\theta_1 = \theta_2$ if and only if $A^*B$ is a multiple of the identity matrix. With that in mind, $|\theta_1 - \theta_2|$ gives us an angle corresponding to the "distance" of $A^*B$ from the identity. We further stipulate for this derivation that $\theta_1, \theta_2$ are such that $|\theta_1 - \theta_2| < 180^\circ$.

If we multiply $A^*B$ by one of the values of $\det(A^*B)^{-1/2}$ to get $M = \frac{A^*B}{\det(A^*B)^{1/2}}$, we shift these angles to either $0^\circ \pm \theta$ or $180^\circ \pm \theta$, where $\theta = \frac{|\theta_1 - \theta_2|}{2}$. In the first case, the trace of $M$ is positive. In the second, the trace is negative. In either case, the trace of $M$ is real.

In the first case, we find that $$ \operatorname{tr}(M) = e^{i \theta} + e^{-i \theta} = 2 \cos \theta = 2 \cos \frac{|\theta_1 - \theta_2|}{2}. $$ In this case, we could take our distance to be $\arccos(\frac 12\operatorname{tr}(M)) = \frac 12 |\theta_1 - \theta_2|$.

In the second case, we find that $$ \operatorname{tr}(M) = e^{i(\pi +\theta)} + e^{i (\pi - \theta)} = -[e^{i \theta} + e^{-i \theta}] = -2 \cos \theta = -2 \cos \frac{|\theta_1 - \theta_2|}{2}. $$ In this case, we could take our distance to be $\arccos(-\frac 12 \operatorname{tr}(M)) = \frac 12 |\theta_1 - \theta_2|$.

Putting everything together, we find that $$ d(A,B) = \arccos\left(\left|\frac{\operatorname{tr}(A^*B)}{2 \det(A^*B)^{1/2}}\right| \right) $$ (where $|x|$ denotes the absolute value of $x$) gives us a measure of the difference between two elements of $SU(2)$, up to a constant phase, which can be interpreted as an angle (from $0^\circ$ to $90^\circ$).