0
$\begingroup$

Why are the gates a and b in this code not the same?

a = UGate(0,0,0.9*np.pi).power(2)
b = UGate(0,0,0.9*np.pi).repeat(2)

I thought that unitary gates function like matrices and that having them repeated after each other means the same as having them to an exponent.

Turns out the power function is computationally much more expensive and returns very strange results as seen in this decomposed image of the two gates i constructed with this code:

qc = qk.QuantumCircuit(2)
qc.barrier(label="power")
qc.append(a, [0])
qc.barrier(label="repeat")
qc.append(b, [1])
display(qc.decompose().decompose().draw("mpl"))`

decomposed image of the two gates.

Why is there a y-component to gate a on qubit 0?

$\endgroup$

1 Answer 1

3
$\begingroup$

The method Gate.repeat() accepts positive integers only. While Gate.power() accepts real values. So, you can use it, for eaxmple, to apply the square root of a unitary:

a = UGate(0,0,0.9*np.pi).power(0.5)

To do that, power() method diagonalizes the gate unitary, raises the diagonal entries to the specified power, then reconstructs the resulting gate.

$\endgroup$
2
  • $\begingroup$ Ok, thanks, that makes sense.. So U(0,-pi/10,-pi/10) is the same as two times U(0,0,9pi/10)? The y rotation irritates me. $\endgroup$ Mar 2 at 16:08
  • 1
    $\begingroup$ Yes. And you can easily check that by getting the matrix representation for each gate using .to_matrix() and do the multiplication. $\endgroup$ Mar 2 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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