Skip to content

Commit

Permalink
Updated Molmer Sorensen to do Rxx and Ryy
Browse files Browse the repository at this point in the history
Added phase term to allow for MS gate
  • Loading branch information
ajrazander committed Mar 9, 2023
1 parent fd84732 commit 0b53044
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/qutip_qip/operations/gateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,16 @@ class MS(TwoQubitGate):
.. math::
\begin{pmatrix}
\cos(\frac{\theta}{2}) & 0 & 0 & -i\sin(\frac{\theta}{2}) \\
\cos(\frac{\theta}{2}) & 0 & 0 & -i\exp^{-i2\phi}\sin(\frac{\theta}{2}) \\
0 & \cos(\frac{\theta}{2}) & -i\sin(\frac{\theta}{2}) & 0 \\
0 & -i\sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) & 0 \\
-i\sin(\frac{\theta}{2}) & 0 & 0 & \cos(\frac{\theta}{2})
-i\exp^{i2\phi}\sin(\frac{\theta}{2}) & 0 & 0 & \cos(\frac{\theta}{2})
\end{pmatrix}
Examples
--------
>>> from qutip_qip.operations import MS
>>> MS([0, 1], np.pi/2).get_compact_qobj() # doctest: +NORMALIZE_WHITESPACE
>>> MS([0, 1], (np.pi/2, 0)).get_compact_qobj() # doctest: +NORMALIZE_WHITESPACE
Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False
Qobj data =
[[0.70711+0.j 0. +0.j 0. +0.j 0. -0.70711j]
Expand Down
25 changes: 19 additions & 6 deletions src/qutip_qip/operations/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,16 @@ def sqrtiswap(N=None, targets=[0, 1]):
)


def molmer_sorensen(theta, N=None, targets=[0, 1]):
def molmer_sorensen(theta, phi=0.0, N=None, targets=[0, 1]):
"""
Quantum object of a Mølmer–Sørensen gate.
Parameters
----------
theta: float
The duration of the interaction pulse.
phi: float
Rotation axis. phi = 0 for XX; phi=pi for YY
N: int
Number of qubits in the system.
target: int
Expand All @@ -801,12 +803,23 @@ def molmer_sorensen(theta, N=None, targets=[0, 1]):
return expand_operator(
molmer_sorensen(theta), dims=[2] * N, targets=targets
)

return Qobj(
[
[np.cos(theta / 2.0), 0, 0, -1.0j * np.sin(theta / 2.0)],
[0, np.cos(theta / 2.0), -1.0j * np.sin(theta / 2.0), 0],
[0, -1.0j * np.sin(theta / 2.0), np.cos(theta / 2.0), 0],
[-1.0j * np.sin(theta / 2.0), 0, 0, np.cos(theta / 2.0)],
[
[
np.cos(theta / 2),
0,
0,
-1j * np.exp(-1j * 2 * phi) * np.sin(theta / 2),
],
[0, np.cos(theta / 2), -1j * np.sin(theta / 2), 0],
[0, -1j * np.sin(theta / 2), np.cos(theta / 2), 0],
[
-1j * np.exp(1j * 2 * phi) * np.sin(theta / 2),
0,
0,
np.cos(theta / 2),
],
],
dims=[[2, 2], [2, 2]],
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_gates_class():
circuit1.add_gate("SQRTSWAP", [2, 0])
circuit1.add_gate("SQRTISWAP", [0, 1])
circuit1.add_gate("SWAPALPHA", [1, 2], arg_value=np.pi/4)
circuit1.add_gate("MS", [1, 0], arg_value=np.pi/4)
circuit1.add_gate("MS", [1, 0], arg_value=(np.pi/4, np.pi/7))
circuit1.add_gate("TOFFOLI", [2, 0, 1])
circuit1.add_gate("FREDKIN", [0, 1, 2])
circuit1.add_gate("BERKELEY", [1, 0])
Expand All @@ -392,7 +392,7 @@ def test_gates_class():
circuit2.add_gate(SQRTSWAP([2, 0]))
circuit2.add_gate(SQRTISWAP([0, 1]))
circuit2.add_gate(SWAPALPHA([1, 2], np.pi/4))
circuit2.add_gate(MS([1, 0], np.pi/4))
circuit2.add_gate(MS([1, 0], (np.pi/4, np.pi/7)))
circuit2.add_gate(TOFFOLI([2, 0, 1]))
circuit2.add_gate(FREDKIN([0, 1, 2]))
circuit2.add_gate(BERKELEY([1, 0]))
Expand Down

0 comments on commit 0b53044

Please sign in to comment.