Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add phaserx gate #250

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
31 changes: 31 additions & 0 deletions src/braket/default_simulator/gate_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,36 @@ def _base_matrix(self) -> np.ndarray:
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):
"""
Expand Down Expand Up @@ -1035,6 +1065,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
Loading