@@ -1119,6 +1119,18 @@ def PauliStringSum2Dense(
1119
1119
weight : Optional [Sequence [float ]] = None ,
1120
1120
numpy : bool = False ,
1121
1121
) -> Tensor :
1122
+ """
1123
+ Generate tensorflow dense matrix from Pauli string sum
1124
+
1125
+ :param ls: 2D Tensor, each row is for a Pauli string,
1126
+ e.g. [1, 0, 0, 3, 2] is for :math:`X_0Z_3Y_4`
1127
+ :type ls: Sequence[Sequence[int]]
1128
+ :param weight: 1D Tensor, each element corresponds the weight for each Pauli string
1129
+ defaults to None (all Pauli strings weight 1.0)
1130
+ :type weight: Optional[Sequence[float]], optional
1131
+ :return: the tensorflow dense matrix
1132
+ :rtype: Tensor
1133
+ """
1122
1134
sparsem = PauliStringSum2COO_numpy (ls , weight )
1123
1135
if numpy :
1124
1136
return sparsem .todense ()
@@ -1143,6 +1155,18 @@ def _numpy2tf_sparse(a: Tensor) -> Tensor:
1143
1155
def PauliStringSum2COO_numpy (
1144
1156
ls : Sequence [Sequence [int ]], weight : Optional [Sequence [float ]] = None
1145
1157
) -> Tensor :
1158
+ """
1159
+ Generate scipy sparse matrix from Pauli string sum
1160
+
1161
+ :param ls: 2D Tensor, each row is for a Pauli string,
1162
+ e.g. [1, 0, 0, 3, 2] is for :math:`X_0Z_3Y_4`
1163
+ :type ls: Sequence[Sequence[int]]
1164
+ :param weight: 1D Tensor, each element corresponds the weight for each Pauli string
1165
+ defaults to None (all Pauli strings weight 1.0)
1166
+ :type weight: Optional[Sequence[float]], optional
1167
+ :return: the scipy coo sparse matrix
1168
+ :rtype: Tensor
1169
+ """
1146
1170
# numpy version is 3* faster!
1147
1171
1148
1172
nterms = len (ls )
@@ -1165,6 +1189,18 @@ def PauliStringSum2COO_numpy(
1165
1189
def PauliStringSum2COO (
1166
1190
ls : Sequence [Sequence [int ]], weight : Optional [Sequence [float ]] = None
1167
1191
) -> Tensor :
1192
+ """
1193
+ Generate tensorflow sparse matrix from Pauli string sum
1194
+
1195
+ :param ls: 2D Tensor, each row is for a Pauli string,
1196
+ e.g. [1, 0, 0, 3, 2] is for :math:`X_0Z_3Y_4`
1197
+ :type ls: Sequence[Sequence[int]]
1198
+ :param weight: 1D Tensor, each element corresponds the weight for each Pauli string
1199
+ defaults to None (all Pauli strings weight 1.0)
1200
+ :type weight: Optional[Sequence[float]], optional
1201
+ :return: the tensorflow coo sparse matrix
1202
+ :rtype: Tensor
1203
+ """
1168
1204
nterms = len (ls )
1169
1205
n = len (ls [0 ])
1170
1206
s = 0b1 << n
@@ -1184,6 +1220,18 @@ def PauliStringSum2COO(
1184
1220
1185
1221
@compiled_jit
1186
1222
def PauliString2COO (l : Sequence [int ], weight : Optional [float ] = None ) -> Tensor :
1223
+ """
1224
+ Generate tensorflow sparse matrix from Pauli string sum
1225
+
1226
+ :param l: 1D Tensor representing for a Pauli string,
1227
+ e.g. [1, 0, 0, 3, 2] is for :math:`X_0Z_3Y_4`
1228
+ :type l: Sequence[int]
1229
+ :param weight: the weight for the Pauli string
1230
+ defaults to None (all Pauli strings weight 1.0)
1231
+ :type weight: Optional[float], optional
1232
+ :return: the tensorflow sparse matrix
1233
+ :rtype: Tensor
1234
+ """
1187
1235
n = len (l )
1188
1236
one = tf .constant (0b1 , dtype = tf .int64 )
1189
1237
idx_x = tf .constant (0b0 , dtype = tf .int64 )
0 commit comments