1
$\begingroup$

I am looking for a way to decompose any given operator U into ZYZ rotations. And then plug the values back into ei∗α∗Rz(θ0)∗Ry(θ1)∗Rz(θ2), to 'recompose' the gate and check if the gate decomposed correctly. Can anyone help me with the Julia codes for this? If not, then Python codes are also welcome

$\endgroup$
3

1 Answer 1

1
$\begingroup$

welcome to QCSE.

I have understood your question, but next time make sure that you use MathJax notation for math equations, it is much cleaner and understoodable.

I don't know about Julia, but I have wrote the following code in Python-Qiskit and I think that's what you are looking for:

import numpy as np
import math

from qiskit import QuantumCircuit, quantum_info
from qiskit.visualization import array_to_latex

#U = np.array([[1/math.sqrt(2),1/math.sqrt(2)],[1/math.sqrt(2),-1/math.sqrt(2)]])
U = np.array([[0,1],[1,0]])
display(array_to_latex(U, prefix = "U = "))

decomposer = quantum_info.OneQubitEulerDecomposer(basis = "ZYZ")
data = decomposer.angles_and_phase(U)
theta = data[0]
phi = data[1]
lamda = data[2]
phase = data[3]

print("\033[1m ZYZ decomposition of U: \033[0m")
print(" theta = {0}, phi = {1}, lambda = {2}, phase = {3}".format(theta,phi,lamda,phase))

qc = QuantumCircuit(1)
qc.rz(lamda, 0)
qc.ry(theta, 0)
qc.rz(phi, 0)
display(qc.draw())

phase_exp = math.e ** (1j * phase)
U_recomposed = np.array(phase_exp * quantum_info.Operator(qc))
display(array_to_latex(U_recomposed, prefix = "U recomposed = "))

And the output is:

enter image description here

I have used built-in class of qiskit quantum_info.OneQubitEulerDecomposer and its methods in order to easily compute the angles and phase of the ZYZ decomposition. Take a look at the documentation of the OneQubitEulerDecomposer class and its method angles_and_phase() Note that I gave identical names to the angles just as in the documentation, to avoid confusions.

Finally, I have used the qunatum_info.Operator class to obtain the unitary matrix for the circuit created, and after multiplying the result by the complex exponent of the phase we have got the original U operator.

$\endgroup$
1
  • $\begingroup$ Alright, thanks so much for this $\endgroup$
    – Hamzah
    Aug 12, 2022 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.