Skip to content

Commit

Permalink
add comments and utility function for sign fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangtong1000 committed Sep 13, 2023
1 parent 1cfa0ec commit 4a4d944
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions renormalizer/mps/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ def get_ham_direct(
return ham


def sign_fix(c, nroots):
if nroots > 1:
if isinstance(c, list):
return [ci / np.sign(np.max(np.abs(ci))) for ci in c]
else:
return c / np.sign(np.max(c, axis=0))
else:
return c / np.sign(np.max(c))

def eigh_direct(
mps: Mps,
qn_mask: np.ndarray,
Expand All @@ -383,11 +392,11 @@ def eigh_direct(
nroots = mps.optimize_config.nroots
if nroots == 1:
e = w[0]
c = v[:, 0] / np.sign(np.max(v[:, 0]))
c = v[:, 0]
else:
e = w[:nroots]
c = [v[:, iroot] / np.sign(np.max(v[:, iroot])) for iroot in range(min(nroots, v.shape[1]))]
return e, c
c = [v[:, iroot] for iroot in range(min(nroots, v.shape[1]))]
return e, sign_fix(c, nroots)


def get_ham_iterative(
Expand Down Expand Up @@ -556,7 +565,4 @@ def hop(x):
else:
assert False
logger.debug(f"use {algo}, HC hops: {count}")
if nroots == 1:
return e, c/np.sign(np.max(c))
else:
return e, c/np.sign(np.max(c, axis=0))
return e, sign_fix(c, nroots)
2 changes: 1 addition & 1 deletion renormalizer/mps/mpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def intersite(cls, model: HolsteinModel, e_opera: dict, ph_opera: dict, scale:

@classmethod
def finiteT_cv(cls, model, nexciton, m_max, spectratype, percent=1.0):
np.random.seed(0)
# np.random.seed(0)

X = cls()
X.model = model
Expand Down
1 change: 1 addition & 0 deletions renormalizer/mps/symbolic_mpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def construct_symbolic_mpo(table, factor, algo="Hopcroft-Karp"):
# unique operators with DoF names taken into consideration
# The inclusion of DoF names is necessary for multi-dof basis.
unique_op = OrderedDict.fromkeys(table.ravel())
# Convert Set(table.ravel()) to List will change the Op order in list, OrderedDict made reproducible
unique_op = list(unique_op.keys())
# check the index of different operators could be represented with np.uint16
assert len(unique_op) < max_uint16
Expand Down

0 comments on commit 4a4d944

Please sign in to comment.