Skip to content

Commit

Permalink
feat: add phaserx gate (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
math411 committed Apr 19, 2024
1 parent ad2262e commit 4328fdb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/braket/default_simulator/density_matrix_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def properties(self) -> GateModelSimulatorDeviceCapabilities:
"ms",
"pswap",
"phaseshift",
"prx",
"rx",
"ry",
"rz",
Expand Down
33 changes: 33 additions & 0 deletions src/braket/default_simulator/gate_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,38 @@ def _cswap(instruction) -> CSwap:
return CSwap([instruction.control, *instruction.targets])


class PRx(GateOperation):
"""
PhaseRx gate.
"""

def __init__(self, targets, angle_1, angle_2, ctrl_modifiers=(), power=1):
super().__init__(
targets=targets,
ctrl_modifiers=ctrl_modifiers,
power=power,
)
self._angle_1 = angle_1
self._angle_2 = angle_2

@property
def _base_matrix(self) -> np.ndarray:
theta = self._angle_1
phi = self._angle_2
return np.array(
[
[
np.cos(theta / 2),
-1j * np.exp(-1j * phi) * np.sin(theta / 2),
],
[
-1j * np.exp(1j * phi) * np.sin(theta / 2),
np.cos(theta / 2),
],
]
)


class GPi(GateOperation):
"""
IonQ GPi gate.
Expand Down Expand Up @@ -1035,6 +1067,7 @@ def _base_matrix(self) -> np.ndarray:
"zz": ZZ,
"ccnot": CCNot,
"cswap": CSwap,
"prx": PRx,
"gpi": GPi,
"gpi2": GPi2,
"ms": MS,
Expand Down
1 change: 1 addition & 0 deletions src/braket/default_simulator/state_vector_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def properties(self) -> GateModelSimulatorDeviceCapabilities:
"ms",
"pswap",
"phaseshift",
"prx",
"rx",
"ry",
"rz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
PauliY,
PauliZ,
PhaseShift,
PRx,
PSwap,
RotX,
RotY,
Expand Down Expand Up @@ -92,6 +93,7 @@
("zz", ZZ, 2, (2,)),
("ccnot", CCNot, 3, ()),
("cswap", CSwap, 3, ()),
("prx", PRx, 1, (2, 3)),
("gpi", GPi, 1, (2,)),
("gpi2", GPi2, 1, (2,)),
("ms", MS, 2, (2, 3, 1.4)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_properties():
"ms",
"pswap",
"phaseshift",
"prx",
"rx",
"ry",
"rz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def test_properties():
"ms",
"pswap",
"phaseshift",
"prx",
"rx",
"ry",
"rz",
Expand Down

0 comments on commit 4328fdb

Please sign in to comment.