Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poisson-dev and support for BTD and Overlap Matrix in NEGF #105

Open
wants to merge 203 commits into
base: main
Choose a base branch
from

Conversation

AsymmetryChou
Copy link
Collaborator

try to merge poisson-dev to main



class Bloch(object):
def __init__(self,bloch_factor) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this factor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是用Bloch定理展开k点的倍数,比如可以设为[3,3,1],则将一个k点展开为了9个。具体见新增的docstring

self.hd, self.sd, _, _, _, _ = self.hamiltonian.get_hs_device(kpoint, self.V, block_tridiagonal)
self.kpoint = torch.tensor(kpoint)

self.oldV = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块判断old_V 的逻辑其实有点冗余,初始化的时候设置一个self.V,然后每次和输入的V做对比看看要不要更新就行了



if not self.useBloch:
if not hasattr(self, "HL") or abs(self.voltage_old-self.voltage)>1e-6 or max(abs(self.kpoint-torch.tensor(kpoint)))>1e-6:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

voltage_old 同理 old_V

@@ -45,6 +45,8 @@ def __init__(
self.node_field = node_field
self.out_field = out_field

self.atom_norbs = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个OrbitalMapper里有的

stru_options:dict,
unit: str,
results_path:Optional[str]=None,
torch_device: Union[str, torch.device]=torch.device('cpu')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个字段名改成device吧

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那这个字段会和NEGF器件区域的device相互冲突的。这里是有意改为torch_device。

edge_field=AtomicDataDict.EDGE_FEATURES_KEY,
node_field=AtomicDataDict.NODE_FEATURES_KEY,
out_field=AtomicDataDict.HAMILTONIAN_KEY,
dtype= model.dtype,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好奇如果这边model是32的,生成出来的哈密顿量是不是后面还要align一下dtype

alldata = AtomicData.to_AtomicDataDict(alldata.to(self.torch_device))
self.alldata = self.model.idp(alldata)
self.alldata[AtomicDataDict.KPOINT_KEY] = \
torch.nested.as_nested_tensor([torch.as_tensor(HS_device["kpoints"], dtype=self.model.dtype, device=self.torch_device)])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在可以不用nested了


structure_leads = {}
structure_device = self.structase[self.device_id[0]:self.device_id[1]]
structure_device.pbc = self.pbc_negf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块会不会有可能出现pbc_negf设错的情况


l_start = int(np.sum(self.h2k.atom_norbs[:lead_id[0]]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个用OrbitalMapper里的atom_norbs替换掉吧

subblocks = [0]+subblocks


for ik in range(HK.shape[0]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面的时候或许需要把k axis cat到一块,方便RGF直接vmap GPU并行,现在可以不管

counted = 0
for i in range(len(hd_k)): # TODO: this part may have probelms when V!=0
l_slice = slice(counted, counted+hd_k[i].shape[0])
hd_k[i] = hd_k[i] - V[l_slice,l_slice]@sd_k[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V会是一个dense的matrix嘛?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是的,V是一个对角矩阵

@@ -251,8 +624,262 @@ def device_norbs(self):
"""
return the number of atoms in the device Hamiltonian
"""
return self.atom_norbs[self.device_id[0]:self.device_id[1]]
return self.h2k.atom_norbs[self.device_id[0]:self.device_id[1]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,可以用OrbitalMapper的替换


class Grid(object):
# define the grid in 3D space
def __init__(self,xg,yg,zg,xa,ya,za):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grid都是方形的嘛?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对的,目前只支持方形

for q in range(num_of_matrices - 2, -1, -1): # Recursive algorithm
grl[q] = grd[q + 1] @ mat_l_list[q] @ gr_left[q] # (B5) We get the off-diagonal blocks for free.
gru[q] = gr_left[q] @ mat_u_list[q] @ grd[q + 1] # (B6) because we need .Tthem.T for the next calc:
grd[q] = gr_left[q] + gr_left[q] @ mat_u_list[q] @ grl[q] # (B4) I suppose I could also use the lower.
g_trans = gr_left[q] @ mat_u_list[q] @ g_trans

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是啥

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last column of Gr. Used for spectral function corresponding to the right electrode A_R in block-tridiagonal case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants