Skip to content

Commit

Permalink
fix random initialization in uhfk; initial_mode introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
aoymt committed Nov 29, 2023
1 parent 42222c5 commit dbd57b0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/hwave/qlmsio/read_input_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def __init__(self, info_inputfile, solver_type="UHFk"):
logger.info("QLMSkInput: read initial_uhf from {}".format(file_name))
self.green["initial_uhf"] = self._read_data(file_name, "complex")

#- how to set initial green function when file is not given
if "initial_mode" in info_inputfile:
self.green["initial_mode"] = info_inputfile["initial_mode"]

#- geometry.dat is required to handle data in coordinate space
if "geometry_uhf" in info_inputfile:
file_name = os.path.join(input_file_dir, info_inputfile["geometry_uhf"])
Expand Down
55 changes: 49 additions & 6 deletions src/hwave/solver/uhfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,14 +624,57 @@ def _initial_green(self, green_info):
exit(1)
logger.info("load initial green function in coord space from file")
_data = self._initial_green_uhf(green_info["initial_uhf"], green_info["geometry_uhf"])

if _data is None:
elif "initial_mode" in green_info:
if green_info["initial_mode"] == "zero":
logger.info("initialize green function with zeros")
_data = self._initial_green_zero()
elif green_info["initial_mode"] in ["one", "unity"]:
logger.info("initialize green function with identity")
_data = self._initial_green_one()
elif green_info["initial_mode"] == "conventional_random":
logger.info("initialize green function with random numbers (conventional)")
_data = self._initial_green_random_conv()
#_data = self._initial_green_random_conv_reshape()
elif green_info["initial_mode"] == "random":
pass # default

if _data is None: # default
logger.info("initialize green function with random numbers")
_data = self._initial_green_random()
# _data = self._initial_green_random_reshape()
_data = self._initial_green_random_simple()
return _data

def _initial_green_random_reshape(self):
def _initial_green_zero(self):
nvol = self.nvol
norb = self.norb
ns = self.ns
nd = ns * norb

green = np.zeros((nvol,ns,norb,ns,norb), dtype=np.complex128)
return green

def _initial_green_one(self):
nvol = self.nvol
norb = self.norb
ns = self.ns
nd = ns * norb

green = np.zeros((nvol,ns,norb,ns,norb), dtype=np.complex128)
green[0] = np.einsum('ab,st->satb', np.identity(norb), np.identity(ns))
return green

def _initial_green_random_simple(self):
nvol = self.nvol
norb = self.norb
ns = self.ns
nd = ns * norb

np.random.seed(self.param_mod["RndSeed"])
rand = np.random.rand(nvol * nd * nd).reshape(nvol,ns,norb,ns,norb)
green = 0.01 * (rand - 0.5)

return green

def _initial_green_random_conv_reshape(self):
lx,ly,lz = self.cellshape
lvol = self.cellvol
norb = self.norb_orig if self.has_sublattice else self.norb
Expand All @@ -654,7 +697,7 @@ def _initial_green_random_reshape(self):
else:
return green

def _initial_green_random(self):
def _initial_green_random_conv(self):
nvol = self.nvol
norb = self.norb
ns = self.ns
Expand Down

0 comments on commit dbd57b0

Please sign in to comment.