@@ -1391,6 +1391,7 @@ def get_pauli_hamiltonian(self):
1391
1391
assert SymmetryTypes .SGB in self .symm_type
1392
1392
GH = self .bw .bs .GeneralHamiltonian
1393
1393
super_self = self
1394
+ is_cpx = SymmetryTypes .CPX in self .symm_type
1394
1395
import numpy as np
1395
1396
1396
1397
class PauliHamiltonian (GH ):
@@ -1428,6 +1429,8 @@ def init_site_ops(self):
1428
1429
"Z" : np .array ([- 1.0 , 0.0 , 0.0 , 1.0 ]),
1429
1430
"N" : np .array ([0.0 , 0.0 , 0.0 , 1.0 ]),
1430
1431
}
1432
+ if is_cpx :
1433
+ op_defs ['Y' ] = op_defs ['Y' ] * 1j
1431
1434
i_alloc = super_self .bw .b .IntVectorAllocator ()
1432
1435
d_alloc = super_self .bw .b .DoubleVectorAllocator ()
1433
1436
q = self .vacuum
@@ -4259,7 +4262,7 @@ def get_mpo_any_pauli(self, op_list, ecore=None, **kwargs):
4259
4262
.. highlight:: python3
4260
4263
4261
4264
Args:
4262
- op_list : list[tuple[str, float]]
4265
+ op_list : list[tuple[str, float|complex ]]
4263
4266
A list of Pauli strings and coefficients.
4264
4267
Characters in the string can be IXYZ. For example, ::
4265
4268
@@ -4281,9 +4284,12 @@ def get_mpo_any_pauli(self, op_list, ecore=None, **kwargs):
4281
4284
b = self .expr_builder ()
4282
4285
idxs = np .arange (self .n_sites , dtype = int )
4283
4286
for ops , val in op_list :
4284
- num_y = ops .count ("Y" )
4285
- assert num_y % 2 == 0
4286
- b .add_term (ops , idxs , val .real * (1 - num_y % 4 ))
4287
+ if SymmetryTypes .CPX not in self .symm_type :
4288
+ num_y = ops .count ("Y" )
4289
+ assert num_y % 2 == 0
4290
+ b .add_term (ops , idxs , val .real * (1 - num_y % 4 ))
4291
+ else :
4292
+ b .add_term (ops , idxs , val )
4287
4293
if ecore is not None :
4288
4294
b .add_const (ecore )
4289
4295
return self .get_mpo (b .finalize (adjust_order = False ), ** kwargs )
0 commit comments