From 228dc69ae9470bb8d869c5c8de591c3553d6c3b3 Mon Sep 17 00:00:00 2001 From: Saumya Goyal Date: Thu, 13 Jan 2022 12:28:37 +0530 Subject: [PATCH] Add single body quantum operator classes --- tensornetwork/quantum/quantum.py | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tensornetwork/quantum/quantum.py b/tensornetwork/quantum/quantum.py index 1dc79814e..6f63c55d5 100644 --- a/tensornetwork/quantum/quantum.py +++ b/tensornetwork/quantum/quantum.py @@ -491,6 +491,62 @@ def eval(self, len(nodes))) return list(nodes)[0].tensor +class X(QuOperator): + """Represents the X operator""" + + def __init__(self): + x_node = tn.Node(np.array([[0,1],[1,0]])) + super().__init__(x_node[0], x_node[1], [], []) + +class Y(QuOperator): + """Represents the Y operator""" + + def __init__(self): + y_node = tn.Node(np.array([[0,-j],[j,0]])) + super().__init__(y_node[0], y_node[1], [], []) + +class Z(QuOperator): + """Represents the Z operator""" + + def __init__(self): + z_node = tn.Node(np.array([[1, 0],[0, -1]])) + super().__init__(z_node[0], z_node[1], [], []) + +class Sx(QuOperator): + """Represents the Spin x operator""" + + def __init__(self): + sx_node = tn.Node(np.array([[0,1/2],[1/2,0]])) + super().__init__(sx_node[0], sx_node[1], [], []) + +class Sy(QuOperator): + """Represents the Spin y operator""" + + def __init__(self): + sy_node = tn.Node(np.array([[0,1/(2j)],[-1/(2j),0]])) + super().__init__(sy_node[0], sy_node[1], [], []) + +class Sz(QuOperator): + """Represents the Spin z operator""" + + def __init__(self): + sz_node = tn.Node(np.array([[1/2, 0],[0, -1/2]])) + super().__init__(sz_node[0], sz_node[1], [], []) + +class T(QuOperator): + """Represents the T operator""" + + def __init__(self): + t_node = tn.Node(np.array([[1, 0],[0, (1+j)/np.sqrt(2)]])) + super().__init__(t_node[0], t_node[1], [], []) + +class H(QuOperator): + """Represents the H operator""" + + def __init__(self): + h_node = tn.Node(np.array([[1, 1],[1, -1]])*(1/np.sqrt(2))) + super().__init__(h_node[0], h_node[1], [], []) + class QuVector(QuOperator): """Represents a (column) vector via a tensor network."""