qiboteam / qibo

A framework for quantum computing
https://qibo.science
Apache License 2.0
277 stars 56 forks source link

U3 decomposition for matrices with determinant -1 #1230

Open andrea-pasquale opened 4 months ago

andrea-pasquale commented 4 months ago

The following u3_decompositions function https://github.com/qiboteam/qibo/blob/19368f211c29d0831e5de2ed0b349cf51d235f12/src/qibo/transpiler/unitary_decompositions.py#L18-L35 holds only for matrices with determinant +1, however when executing on hardware we might want to execute gates, such as X, Y and Z with determinant -1. We need to find a way to generalize the previous formula to accommodate matrices with -1 determinant. I know that we already discussed about this but I decided to open the issue so that we don't forget.

renatomello commented 4 months ago

I know you want a more general solution, but at least with respect to the Paulis one can still get them using the regular $U_{3}$ decomposition. Of course, this is up to global phase, which is not a problem if the goal is hardware implementation or simulations of measurements / expectation values.

Using qibo's definition of $U_{3}$:

andrea-pasquale commented 4 months ago

Thanks @renatomello, indeed this is the fix that we already implemented in qibocal when performing RB https://github.com/qiboteam/qibocal/pull/730. The parameters are different but the difference is still a global phase so it should not matter.

marekgluza commented 4 months ago

@jeongrak-son do you have some suggestions?

I think this is an interesting question when trying to compile controlled-unitary operations. Here is an example where the phase matters:

For a single qubit we would have $\Lambda(U)=|0\rangle\langle 0\otimes id +|1\rangle\langle1\otimes U$ vs $\Lambda(i U)|0\rangle\langle 0\otimes id +|1\rangle\langle1\otimes iU$ which applied to $|+\rangle \otimes 0\rangle$ for $U=X$ is $(|0\rangle \otimes 0\rangle+|1\rangle \otimes 1\rangle)/\sqrt{2}$ and $(|0\rangle \otimes 0\rangle+i|1\rangle \otimes 1\rangle)/\sqrt{2}$ which are not the same state because the overlap amplitude is $|1+i|/2=\sqrt{2}/2< 1$.

I'm guessing in general if you compile the controlled-unitary operation using the u_3_decomposition on the working qubit obtaining either $U$ and $iU$ you will have a similar drop of amplitude for $\Lambda(U)$ and $\Lambda(iU)$?

Does anyone know how this is solved for the surface code logical gates?

jeongrak-son commented 4 months ago

I do not believe that such function $\Lambda(\cdot)$ can be implemented (see Araújo et al. (2014) for example) and thus $\Lambda(U)$ and $\Lambda(iU)$ must be separately compiled.

marekgluza commented 4 months ago

One triviality: we already agreed that using the Sylvester's formula e.g. $iX$ can be implemented. Taking tensor power $4$, we get $(iX)^{\otimes 4}=X^{\otimes 4}$ which is related to the centre of the Clifford group $\langle i \id \rangle$ https://kups.ub.uni-koeln.de/50465/1/dissertation_heinrich.pdf#equation.2.0.9 If we implement this on the state $|+\rangle^{\otimes 3}\otimes |\psi\rangle$ and discard the first 3 registers we get $X|\psi\rangle$

@jeongrak-son can we implement $X$ (not $iX$) using something like $\tr_1[e^{isZ\otimes Z} \rho\otimes \sigma e^{-sZ\otimes Z}]$?

To summarize all examples, $det(Z)=-1$ but $\det(Z\otimes Z)=1$ so once we work with 2 'copies' of $Z$ we get back to the $+$ part of the unitary group. Can one create $\id\otimes Z$ without the $i$ when there's a 'catalysing` register?

In general, I'd be thankful for some explanation related to 'connectivity to the identity' of the unitary group and how this behaves if we add registers or not. If we work with only one qubit then we make continuous maps of the form $e^{itH}$ so 'on the continuous map the determinant sign stays constant' so it need to be the same as the sign of $\det \id = 1$. However if we realize $G\subset SU(D)$ so for example can we get $U(2)\subset SU(4)$? I.e. 2 qubit universal control individually $SU(2)$ not $U(2)$ and does it give us $U(2)$ on each of the qubit when realized as part of a larger system? I think that would be weird because then we have the same drift but more control unitaries on each single qubit and would end up having $U(4)$ controllability as opposed to $SU(4)$?

renatomello commented 3 months ago

I know you want a more general solution, but at least with respect to the Paulis one can still get them using the regular U3 decomposition. Of course, this is up to global phase, which is not a problem if the goal is hardware implementation or simulations of measurements / expectation values.

Using qibo's definition of U3:

* U3(−π,−π,0)=iX

* U3(−π,−π,π)=−iY

* U3(0,−π,0)=iZ

I think a simple general solution is to remember that $\textup{det}(AB) = \textup{det}(A) \textup{det}(B)$ and implement one of the Paulis before or after the regular decomposition of an $U_{3}$. That gives a general matrix with determinant equals to $-1$ up to global phase. In terms of hardware, if the gateset is limited to gates that are represented by matrices that have determinant $-1$, than it will be impossible to create the unitary without a global phase.

scarrazza commented 4 weeks ago

@marekgluza @renatomello do you agree with the suggested solution?

marekgluza commented 3 weeks ago

Not sure

implement one of the Paulis before or after the regular decomposition of an U3 if adding a gate will not cause frustration to others.

E.g. adding a Z before a Z measurement is fine. But what if someone changes the basis?

For a $2\times 2$ unitary $U$ with det -1 you can consider the unitary $V=iU$ which has det +1. The decomposition of $V=ABCD...$ will implement $U$ up to a global phase.

Isn't it better to check if det = +1 and otherwise proceed with $U\mapsto 1j U$?

renatomello commented 3 weeks ago

@marekgluza @renatomello do you agree with the suggested solution?

I don't think I'm seeing the suggested solution

marekgluza commented 3 weeks ago

@renatomello what you said here as a 'solution'

Using qibo's definition of

  • $U_{3}(-\pi, -\pi, 0) = iX$
  • $U_{3}(-\pi, -\pi, \pi) = -iY$
  • $U_{3}(0, -\pi, 0) = iZ$

makes sense and can be generalized to any 2x2 matrix with determinant -1

The only problem is if one will do controlled-unitary operations as discussed above then there are pitfalls about forgetting the phase in the decomposition (but this cannot be circumvented easily and there is little urgency in having that feature)

renatomello commented 3 weeks ago

@renatomello what you said here as a 'solution'

Using qibo's definition of

* U3(−π,−π,0)=iX

* U3(−π,−π,π)=−iY

* U3(0,−π,0)=iZ

makes sense and can be generalized to any 2x2 matrix with determinant -1

The only problem is if one will do controlled-unitary operations as discussed above then there are pitfalls about forgetting the phase in the decomposition (but this cannot be circumvented easily and there is little urgency in having that feature)

I agree that controlled operations should be treated differently, but there are ways to handle those, e.g. here and here and many others. However, that becomes more of a transpiler issue. I'd just move forward with adding a global phase and documenting it.

marekgluza commented 3 weeks ago

move forward with adding a global phase and documenting it.

@scarrazza sounds good to me, thanks @renatomello for the references