@@ -217,8 +217,12 @@ class RotationGate(NativeGate, ParametrizedGate, SimpleClassReprABC):
217217 target: Index referring to the qubits on which the gate will be applied.
218218 """
219219
220- def __init__ (self , theta : Expr | float , target : list [int ] | int ):
221- self .parameters = [theta ]
220+ def __init__ (
221+ self , theta : list [Expr | float ] | Expr | float , target : list [int ] | int
222+ ):
223+ if not isinstance (theta , list ):
224+ theta = [theta ]
225+ self .parameters = theta
222226 definition = UnitaryMatrix (self .to_canonical_matrix ())
223227 if isinstance (target , int ):
224228 target = [target ]
@@ -1351,6 +1355,122 @@ def to_canonical_matrix(self):
13511355 )
13521356
13531357
1358+ class PRX (RotationGate , SingleQubitGate ):
1359+ r"""Parametrized rotated-X gate.
1360+
1361+ PRX(θ, φ) = Rz(φ) Rx(θ) Rz(-φ)
1362+
1363+ Equivalent to a rotation of angle θ around
1364+ the axis (cos φ, sin φ, 0) in the XY plane.
1365+
1366+ Args:
1367+ theta: Rotation angle.
1368+ phi: Axis angle in XY plane.
1369+ target: Target qubit.
1370+
1371+ Matrix form:
1372+ Rz(φ) Rx(θ) Rz(-φ)
1373+ """
1374+
1375+ qlm_aqasm_keyword = "PRX"
1376+ qiskit_string = "prx"
1377+
1378+ @classproperty
1379+ def braket_gate (cls ):
1380+ from braket .circuits import gates
1381+
1382+ return gates .PRx
1383+
1384+ @classproperty
1385+ def qiskit_gate (cls ):
1386+ from qiskit .circuit .library import UGate
1387+
1388+ return UGate
1389+
1390+ @classproperty
1391+ def cirq_gate (cls ):
1392+ from cirq .ops .phased_x_gate import PhasedXPowGate
1393+
1394+ return PhasedXPowGate
1395+
1396+ def __init__ (self , theta : Expr | float , phi : Expr | float , target : int ):
1397+ super ().__init__ ([theta , phi ], target )
1398+
1399+ def to_canonical_matrix (self ):
1400+ theta , phi = self .parameters
1401+
1402+ c = np .cos (theta / 2 )
1403+ s = np .sin (theta / 2 )
1404+
1405+ e_minus = np .exp (- 1j * phi )
1406+ e_plus = np .exp (1j * phi )
1407+
1408+ return np .array (
1409+ [
1410+ [c , - 1j * e_minus * s ],
1411+ [- 1j * e_plus * s , c ],
1412+ ],
1413+ dtype = complex ,
1414+ )
1415+
1416+ def to_other_language (
1417+ self ,
1418+ language : Language = Language .QISKIT ,
1419+ qiskit_parameters : Optional [set ["Parameter" ]] = None ,
1420+ ):
1421+
1422+ theta , phi = self .parameters
1423+ try :
1424+ theta = float (theta )
1425+ except :
1426+ pass
1427+ try :
1428+ phi = float (phi )
1429+ except :
1430+ pass
1431+
1432+ if language == Language .QISKIT :
1433+ if qiskit_parameters is None :
1434+ qiskit_parameters = set ()
1435+ return self .qiskit_gate (
1436+ _qiskit_parameter_adder (theta , qiskit_parameters ),
1437+ _qiskit_parameter_adder (phi , qiskit_parameters ),
1438+ _qiskit_parameter_adder (- phi , qiskit_parameters ),
1439+ )
1440+ elif language == Language .BRAKET :
1441+ from braket .circuits import Instruction
1442+
1443+ connection = self .targets
1444+ if isinstance (self , ControlledGate ):
1445+ connection += self .controls
1446+ return Instruction (
1447+ operator = self .braket_gate (
1448+ _sympy_to_braket_param (theta ), _sympy_to_braket_param (phi )
1449+ ),
1450+ target = connection ,
1451+ )
1452+ elif language == Language .CIRQ :
1453+ return self .cirq_gate (theta , phi )
1454+ if language == Language .QASM2 :
1455+ from mpqp .qasm .mpqp_to_qasm import float_to_qasm_str
1456+
1457+ instruction_str = self .qasm2_gate
1458+ instruction_str += (
1459+ "("
1460+ + "," .join (float_to_qasm_str (float (param )) for param in self .parameters )
1461+ + ")"
1462+ )
1463+
1464+ qubits = ""
1465+ if isinstance (self , ControlledGate ):
1466+ qubits = "," .join ([f"q[{ j } ]" for j in self .controls ]) + ","
1467+ qubits += "," .join ([f"q[{ j } ]" for j in self .targets ])
1468+
1469+ return instruction_str + " " + qubits + ";"
1470+ else :
1471+ raise NotImplementedError (f"Error: { language } is not supported" )
1472+
1473+
13541474class Rk (RotationGate , SingleQubitGate ):
13551475 r"""One qubit Phase gate of angle `\frac{2i\pi}{2^k}`.
13561476
0 commit comments