@@ -466,6 +466,41 @@ def phase_gate(theta: float = 0) -> Gate:
466
466
return Gate (unitary )
467
467
468
468
469
+ def u_gate (theta : float = 0 , phi : float = 0 , lbd : float = 0 ) -> Gate :
470
+ r"""
471
+ IBMQ U gate following the converntion of OpenQASM3.0.
472
+ See `OpenQASM doc <https://openqasm.com/language/gates.html#built-in-gates>`_
473
+
474
+ .. math::
475
+
476
+ \begin{split}U(\theta,\phi,\lambda) := \left(\begin{array}{cc}
477
+ \cos(\theta/2) & -e^{i\lambda}\sin(\theta/2) \\
478
+ e^{i\phi}\sin(\theta/2) & e^{i(\phi+\lambda)}\cos(\theta/2) \end{array}\right).\end{split}
479
+
480
+ :param theta: _description_, defaults to 0
481
+ :type theta: float, optional
482
+ :param phi: _description_, defaults to 0
483
+ :type phi: float, optional
484
+ :param lbd: _description_, defaults to 0
485
+ :type lbd: float, optional
486
+ :return: _description_
487
+ :rtype: Gate
488
+ """
489
+ i00 , i01 , i10 , i11 = array_to_tensor (
490
+ np .array ([[1 , 0 ], [0 , 0 ]]),
491
+ np .array ([[0 , 1 ], [0 , 0 ]]),
492
+ np .array ([[0 , 0 ], [1 , 0 ]]),
493
+ np .array ([[0 , 0 ], [0 , 1 ]]),
494
+ )
495
+ unitary = (
496
+ backend .cos (theta / 2 ) * i00
497
+ - backend .exp (1.0j * lbd ) * backend .sin (theta / 2 ) * i01
498
+ + backend .exp (1.0j * phi ) * backend .sin (theta / 2 ) * i10
499
+ + backend .exp (1.0j * (phi + lbd )) * backend .cos (theta / 2 ) * i11
500
+ )
501
+ return Gate (unitary )
502
+
503
+
469
504
def r_gate (theta : float = 0 , alpha : float = 0 , phi : float = 0 ) -> Gate :
470
505
r"""
471
506
General single qubit rotation gate
@@ -871,6 +906,7 @@ def mpo_gate(mpo: Operator, name: str = "mpo") -> Operator:
871
906
def meta_vgate () -> None :
872
907
for f in [
873
908
"r" ,
909
+ "u" ,
874
910
"rx" ,
875
911
"ry" ,
876
912
"rz" ,
@@ -886,7 +922,7 @@ def meta_vgate() -> None:
886
922
]:
887
923
for funcname in [f , f + "gate" , f + "_gate" ]:
888
924
setattr (thismodule , funcname , GateVF (getattr (thismodule , f + "_gate" ), f ))
889
- for f in ["crx" , "cry" , "crz" ]:
925
+ for f in ["cu" , " crx" , "cry" , "crz" ]:
890
926
for funcname in [f , f + "gate" , f + "_gate" ]:
891
927
setattr (thismodule , funcname , getattr (thismodule , f [1 :]).controlled ())
892
928
for f in ["ox" , "oy" , "oz" , "orx" , "ory" , "orz" ]:
0 commit comments