Skip to content

Commit

Permalink
Merge pull request #193 from BoxiLi/qrot
Browse files Browse the repository at this point in the history
Add QROT and MS gate
  • Loading branch information
BoxiLi committed Feb 22, 2023
2 parents 5790ddc + bda9f33 commit fd84732
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/source/qip-basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Gate name Description
"RX" Rotation around x axis
"RY" Rotation around y axis
"RZ" Rotation around z axis
"R" Arbitrary single qubit rotation
"X" Pauli-X gate
"Y" Pauli-Y gate
"Z" Pauli-Z gate
Expand All @@ -169,6 +170,7 @@ Gate name Description
"ISWAP" Swap gate with additional phase for 01 and 10 states
"SQRTSWAP" Square root of the SWAP gate
"SQRTISWAP" Square root of the ISWAP gate
"MS" Mølmer-Sørensen gate
"FREDKIN" Fredkin gate
"TOFFOLI" Toffoli gate
"GLOBALPHASE" Global phase
Expand Down
34 changes: 34 additions & 0 deletions src/qutip_qip/operations/gateclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
s_gate,
t_gate,
cs_gate,
qrot,
qasmu_gate,
ct_gate,
cphase,
Expand Down Expand Up @@ -62,6 +63,7 @@
"SQRTNOT",
"S",
"T",
"R",
"QASMU",
"SWAP",
"ISWAP",
Expand Down Expand Up @@ -317,6 +319,8 @@ def get_compact_qobj(self):
qobj = snot()
elif self.name == "PHASEGATE":
qobj = phasegate(self.arg_value)
elif self.name == "R":
qobj = qrot(*self.arg_value)
elif self.name == "QASMU":
qobj = qasmu_gate(self.arg_value)
elif self.name == "CRX":
Expand Down Expand Up @@ -634,6 +638,35 @@ def get_compact_qobj(self):
return t_gate()


class R(SingleQubitGate):
r"""
Arbitrary single-qubit rotation
.. math::
\begin{pmatrix}
\cos(\frac{\theta}{2}) & -ie^{-i\phi} \sin(\frac{\theta}{2}) \\
-ie^{i\phi} \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2})
\end{pmatrix}
Examples
--------
>>> from qutip_qip.operations import R
>>> R(0, (np.pi/2, np.pi/2)).get_compact_qobj().tidyup() # doctest: +NORMALIZE_WHITESPACE
Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False
Qobj data =
[[ 0.70711 -0.70711]
[ 0.70711 0.70711]]
"""

def __init__(self, targets, arg_value=None, **kwargs):
super().__init__(targets=targets, arg_value=arg_value, **kwargs)
self.latex_str = r"{\rm R}"

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


class QASMU(SingleQubitGate):
r"""
QASMU gate.
Expand Down Expand Up @@ -1140,6 +1173,7 @@ def get_compact_qobj(self):
"SQRTNOT": SQRTNOT,
"S": S,
"T": T,
"R": R,
"QASMU": QASMU,
"SWAP": SWAP,
"ISWAP": ISWAP,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from qutip_qip.operations import (
X, Y, Z, RX, RY, RZ, H, SQRTNOT, S, T, QASMU, CNOT, CPHASE, ISWAP, SWAP,
CZ, SQRTSWAP, SQRTISWAP, SWAPALPHA, SWAPALPHA, MS, TOFFOLI, FREDKIN,
BERKELEY, expand_operator)
BERKELEY, R, expand_operator)


def _permutation_id(permutation):
Expand Down Expand Up @@ -355,6 +355,7 @@ def test_gates_class():
circuit1.add_gate("SQRTNOT", 0)
circuit1.add_gate("S", 2)
circuit1.add_gate("T", 1)
circuit1.add_gate("R", 1, arg_value=(np.pi/4, np.pi/6))
circuit1.add_gate("QASMU", 0, arg_value=(np.pi/4, np.pi/4, np.pi/4))
circuit1.add_gate("CNOT", controls=0, targets=1)
circuit1.add_gate("CPHASE", controls=0, targets=1, arg_value=np.pi/4)
Expand All @@ -381,6 +382,7 @@ def test_gates_class():
circuit2.add_gate(SQRTNOT(0))
circuit2.add_gate(S(2))
circuit2.add_gate(T(1))
circuit2.add_gate(R(1, (np.pi/4, np.pi/6)))
circuit2.add_gate(QASMU(0, (np.pi/4, np.pi/4, np.pi/4)))
circuit2.add_gate(CNOT(0, 1))
circuit2.add_gate(CPHASE(0, 1, np.pi/4))
Expand Down

0 comments on commit fd84732

Please sign in to comment.