Skip to content

Commit

Permalink
Merge pull request #194 from ajrazander/master
Browse files Browse the repository at this point in the history
Added Ryy-like gate to the MS gate
  • Loading branch information
BoxiLi committed Mar 22, 2023
2 parents fa929ff + 124a728 commit 363eb9d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
8 changes: 4 additions & 4 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 & -ie^{-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})
-ie^{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 All @@ -895,7 +895,7 @@ def __init__(self, targets, arg_value, **kwargs):
self.latex_str = r"{\rm MS}"

def get_compact_qobj(self):
return molmer_sorensen(self.arg_value)
return molmer_sorensen(*self.arg_value)


class TOFFOLI(Gate):
Expand Down
23 changes: 18 additions & 5 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
6 changes: 3 additions & 3 deletions tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_single_qubit_rotation(self, gate, n_angles):
pytest.param(gates.swap, 0, id="swap"),
pytest.param(gates.iswap, 0, id="iswap"),
pytest.param(gates.sqrtswap, 0, id="sqrt(swap)"),
pytest.param(functools.partial(gates.molmer_sorensen, 0.5*np.pi), 0,
pytest.param(functools.partial(gates.molmer_sorensen, 0.5*np.pi, 0.), 0,
id="Molmer-Sorensen")
])
def test_two_qubit(self, gate, n_controls):
Expand Down 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 363eb9d

Please sign in to comment.