Skip to content

Commit 5a1d82c

Browse files
committed
add support for complex pauli
1 parent a7f1fe0 commit 5a1d82c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

pyblock2/driver/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ def get_pauli_hamiltonian(self):
13911391
assert SymmetryTypes.SGB in self.symm_type
13921392
GH = self.bw.bs.GeneralHamiltonian
13931393
super_self = self
1394+
is_cpx = SymmetryTypes.CPX in self.symm_type
13941395
import numpy as np
13951396

13961397
class PauliHamiltonian(GH):
@@ -1428,6 +1429,8 @@ def init_site_ops(self):
14281429
"Z": np.array([-1.0, 0.0, 0.0, 1.0]),
14291430
"N": np.array([0.0, 0.0, 0.0, 1.0]),
14301431
}
1432+
if is_cpx:
1433+
op_defs['Y'] = op_defs['Y'] * 1j
14311434
i_alloc = super_self.bw.b.IntVectorAllocator()
14321435
d_alloc = super_self.bw.b.DoubleVectorAllocator()
14331436
q = self.vacuum
@@ -4259,7 +4262,7 @@ def get_mpo_any_pauli(self, op_list, ecore=None, **kwargs):
42594262
.. highlight:: python3
42604263
42614264
Args:
4262-
op_list : list[tuple[str, float]]
4265+
op_list : list[tuple[str, float|complex]]
42634266
A list of Pauli strings and coefficients.
42644267
Characters in the string can be IXYZ. For example, ::
42654268
@@ -4281,9 +4284,12 @@ def get_mpo_any_pauli(self, op_list, ecore=None, **kwargs):
42814284
b = self.expr_builder()
42824285
idxs = np.arange(self.n_sites, dtype=int)
42834286
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)
42874293
if ecore is not None:
42884294
b.add_const(ecore)
42894295
return self.get_mpo(b.finalize(adjust_order=False), **kwargs)

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ version = "0.5.4"
1313
license = "GPL-3.0-only"
1414
license-files = ["LICENSE"]
1515
readme = "README.md"
16+
maintainers = [
17+
{ name = "Huanchen Zhai", email = "hczhai.ok@gmail.com" }
18+
]
1619
authors = [
17-
{ name = "Huanchen Zhai", email = "hczhai.ok@gmail.com" },
20+
{ name = "Huanchen Zhai" },
1821
{ name = "Henrik R. Larsson" },
1922
{ name = "Seunghoon Lee" },
2023
{ name = "Zhi-Hao Cui" },

0 commit comments

Comments
 (0)