Skip to content

Commit

Permalink
Merge pull request #80 from zapatacomputing/add-native-ionq-gates
Browse files Browse the repository at this point in the history
feat(_builtin_gates): add native ionq gates
  • Loading branch information
Athena Caesura authored Jan 25, 2023
2 parents abd8ac6 + 865751a commit 3b873d0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/orquestra/quantum/circuits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
CPHASE,
CZ,
ISWAP,
MS,
PHASE,
RH,
RX,
Expand All @@ -160,6 +161,8 @@
ZZ,
Delay,
GatePrototype,
GPi,
GPi2,
H,
I,
S,
Expand Down
3 changes: 3 additions & 0 deletions src/orquestra/quantum/circuits/_builtin_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def builtin_gate_by_name(name) -> GateRef:
RH = make_parametric_gate_prototype("RH", _matrices.rh_matrix, 1)
PHASE = make_parametric_gate_prototype("PHASE", _matrices.phase_matrix, 1)
U3 = make_parametric_gate_prototype("U3", _matrices.u3_matrix, 1)
GPi = make_parametric_gate_prototype("GPi", _matrices.gpi_matrix, 1, is_hermitian=True)
GPi2 = make_parametric_gate_prototype("GPi2", _matrices.gpi2_matrix, 1)


# --- non-parametric, two qubit gates ---
Expand All @@ -71,6 +73,7 @@ def builtin_gate_by_name(name) -> GateRef:
YY = make_parametric_gate_prototype("YY", _matrices.yy_matrix, 2)
ZZ = make_parametric_gate_prototype("ZZ", _matrices.zz_matrix, 2)
XY = make_parametric_gate_prototype("XY", _matrices.xy_matrix, 2)
MS = make_parametric_gate_prototype("MS", _matrices.ms_matrix, 2)


# --- misc ----
Expand Down
32 changes: 32 additions & 0 deletions src/orquestra/quantum/circuits/_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ def u3_matrix(theta, phi, lambda_):
)


def gpi_matrix(theta):
"""Based on https://ionq.com/docs/getting-started-with-native-gates"""
return sympy.Matrix(
[
[0, sympy.exp(-1j * theta)],
[sympy.exp(1j * theta), 0],
]
)


def gpi2_matrix(theta):
"""Based on https://ionq.com/docs/getting-started-with-native-gates"""
return (2 ** (-0.5)) * sympy.Matrix(
[
[1, -1j * sympy.exp(-1j * theta)],
[-1j * sympy.exp(1j * theta), 1],
]
)


# --- non-parametric two qubit gates ---


Expand Down Expand Up @@ -221,6 +241,18 @@ def xy_matrix(angle):
)


def ms_matrix(phi_0, phi_1):
"""Based on https://ionq.com/docs/getting-started-with-native-gates"""
return (2 ** (-0.5)) * sympy.Matrix(
[
[1, 0, 0, -1j * sympy.exp(-1j * (phi_0 + phi_1))],
[0, 1, -1j * sympy.exp(-1j * (phi_0 - phi_1)), 0],
[0, -1j * sympy.exp(1j * (phi_0 - phi_1)), 1, 0],
[-1j * sympy.exp(1j * (phi_0 + phi_1)), 0, 0, 1],
]
)


def delay_matrix(_duration):
# Note that _duration parameter is not used when constructing the
# matrix, because Delay always acts as identity.
Expand Down
3 changes: 3 additions & 0 deletions tests/orquestra/quantum/circuits/_builtin_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class TestBuiltinGatesProperties:
_builtin_gates.ZZ(0.3),
_builtin_gates.PHASE(1),
_builtin_gates.CPHASE(0.1),
_builtin_gates.GPi(0.1),
_builtin_gates.GPi2(0.1),
_builtin_gates.MS(0.1, 0.2),
_builtin_gates.Delay(0.5),
],
)
Expand Down
3 changes: 3 additions & 0 deletions tests/orquestra/quantum/circuits/_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
_builtin_gates.RZ(0),
_builtin_gates.PHASE(sympy.pi / 5),
_builtin_gates.U3(np.pi, sympy.pi / 2, sympy.Symbol("x")),
_builtin_gates.GPi(sympy.Symbol("theta")),
_builtin_gates.GPi2(sympy.Symbol("theta")),
_builtin_gates.CZ,
_builtin_gates.CNOT,
_builtin_gates.SWAP,
Expand All @@ -36,6 +38,7 @@
_builtin_gates.YY(sympy.pi),
_builtin_gates.ZZ(sympy.Symbol("x") + sympy.Symbol("y")),
_builtin_gates.CPHASE(1.5),
_builtin_gates.MS(sympy.Symbol("theta"), np.pi / 2),
]

POWER_GATE_EXPONENTS = [-2.0, 0, 0.5, 1.0]
Expand Down

0 comments on commit 3b873d0

Please sign in to comment.