Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

U3 decomposition for matrices with determinant -1 #1230

Open
andrea-pasquale opened this issue Feb 27, 2024 · 12 comments
Open

U3 decomposition for matrices with determinant -1 #1230

andrea-pasquale opened this issue Feb 27, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@andrea-pasquale
Copy link
Contributor

The following u3_decompositions function

def u3_decomposition(unitary):
"""Decomposes arbitrary one-qubit gates to U3.
Args:
unitary (ndarray): Unitary :math:`2 \\times 2` matrix to be decomposed.
Returns:
(float, float, float): parameters of U3 gate.
"""
# https://github.com/Qiskit/qiskit-terra/blob/d2e3340adb79719f9154b665e8f6d8dc26b3e0aa/qiskit/quantum_info/synthesis/one_qubit_decompose.py#L221
su2 = unitary / np.sqrt(np.linalg.det(unitary))
theta = 2 * np.arctan2(abs(su2[1, 0]), abs(su2[0, 0]))
plus = np.angle(su2[1, 1])
minus = np.angle(su2[1, 0])
phi = plus + minus
lam = plus - minus
return theta, phi, lam

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
Copy link
Contributor

renatomello commented Feb 28, 2024

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}$:

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

@andrea-pasquale
Copy link
Contributor Author

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

@marekgluza
Copy link
Contributor

@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
Copy link

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
Copy link
Contributor

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
Copy link
Contributor

renatomello commented Mar 27, 2024

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.

@MatteoRobbiati MatteoRobbiati added this to the Qibo 0.2.9 milestone Jun 11, 2024
@scarrazza
Copy link
Member

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

@marekgluza
Copy link
Contributor

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
Copy link
Contributor

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

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

@marekgluza
Copy link
Contributor

@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
Copy link
Contributor

renatomello commented Jun 12, 2024

@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
Copy link
Contributor

move forward with adding a global phase and documenting it.

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

@scarrazza scarrazza modified the milestones: Qibo 0.2.9, Qibo 0.2.10 Jun 25, 2024
@scarrazza scarrazza removed this from the Qibo 0.2.10 milestone Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants