Skip to content

Commit

Permalink
Intermediate commit:
Browse files Browse the repository at this point in the history
python API: bugfixes and added interface for set_hgeneral.
All python functions should be completely lowercase
  • Loading branch information
lcrippa committed Sep 8, 2024
1 parent 13417d6 commit 313846f
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
3 changes: 2 additions & 1 deletion python/edi2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def setter(self, new_value):
#bath
import func_bath
global_env.get_bath_dimension = types.MethodType(func_bath.get_bath_dimension, global_env)
global_env.set_Hreplica = types.MethodType(func_bath.set_Hreplica, global_env)
global_env.set_hreplica = types.MethodType(func_bath.set_hreplica, global_env)
global_env.set_hgeneral = types.MethodType(func_bath.set_hgeneral, global_env)
global_env.break_symmetry_bath = types.MethodType(func_bath.break_symmetry_bath, global_env)
global_env.spin_symmetrize_bath = types.MethodType(func_bath.spin_symmetrize_bath, global_env)
global_env.orb_symmetrize_bath = types.MethodType(func_bath.orb_symmetrize_bath, global_env)
Expand Down
60 changes: 57 additions & 3 deletions python/func_bath.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def get_bath_dimension(self):
return get_bath_dimension_wrap()

#init_hreplica

def set_Hreplica(self,hvec,lambdavec):
def set_hreplica(self,hvec,lambdavec):
init_hreplica_symmetries_d5 = self.library.init_Hreplica_symmetries_d5
init_hreplica_symmetries_d5.argtypes =[np.ctypeslib.ndpointer(dtype=complex,ndim=5, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS'),
Expand Down Expand Up @@ -58,14 +57,69 @@ def set_Hreplica(self,hvec,lambdavec):
elif(len(dim_hvec) == 5):
if(len(dim_lambdavec)==2):
init_hreplica_symmetries_d5(hvec,dim_hvec,lambdavec,dim_lambdavec)
elif(len(Ddim_lambdavec)==3):
elif(len(dim_lambdavec)==3):
init_hreplica_symmetries_lattice_d5(hvec,dim_hvec,lambdavec,dim_lambdavec)
else:
raise ValueError('Shape(lambdavec) != 2 or 3 in set_Hreplica')
else:
raise ValueError('Shape(Hvec) != 3 or 5 in set_Hreplica')
return ;

#init_hgeneral
def set_hgeneral(self,hvec,lambdavec):
init_hgeneral_symmetries_d5 = self.library.init_Hgeneral_symmetries_d5
init_hgeneral_symmetries_d5.argtypes =[np.ctypeslib.ndpointer(dtype=complex,ndim=5, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=float,ndim=2, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS')]
init_hgeneral_symmetries_d5.restype = None

init_hgeneral_symmetries_d3 = self.library.init_Hgeneral_symmetries_d3
init_hgeneral_symmetries_d3.argtypes =[np.ctypeslib.ndpointer(dtype=complex,ndim=3, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=float,ndim=2, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS')]
init_hgeneral_symmetries_d3.restype = None

init_hgeneral_symmetries_lattice_d5 = self.library.init_Hgeneral_symmetries_lattice_d5
init_hgeneral_symmetries_lattice_d5.argtypes =[np.ctypeslib.ndpointer(dtype=complex,ndim=5, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=float,ndim=3, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS')]
init_hgeneral_symmetries_lattice_d5.restype = None

init_hgeneral_symmetries_lattice_d3 = self.library.init_Hgeneral_symmetries_lattice_d3
init_hgeneral_symmetries_lattice_d3.argtypes =[np.ctypeslib.ndpointer(dtype=complex,ndim=3, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=float,ndim=3, flags='F_CONTIGUOUS'),
np.ctypeslib.ndpointer(dtype=np.int64,ndim=1, flags='F_CONTIGUOUS')]
init_hgeneral_symmetries_lattice_d3.restype = None


aux_norb=c_int.in_dll(self.library, "Norb").value
aux_nspin=c_int.in_dll(self.library, "Nspin").value
dim_hvec = np.asarray(np.shape(hvec),dtype=np.int64,order="F")
dim_lambdavec = np.asarray(np.shape(lambdavec),dtype=np.int64,order="F")


if(len(dim_hvec) == 3):
if(len(dim_lambdavec)==2):
init_hgeneral_symmetries_d3(hvec,dim_hvec,lambdavec,dim_lambdavec)
elif(len(Ddim_lambdavec)==3):
init_hgeneral_symmetries_lattice_d3(hvec,dim_hvec,lambdavec,dim_lambdavec)
else:
raise ValueError('Shape(lambdavec) != 2 or 3 in set_Hgeneral')
elif(len(dim_hvec) == 5):
if(len(dim_lambdavec)==2):
init_hgeneral_symmetries_d5(hvec,dim_hvec,lambdavec,dim_lambdavec)
elif(len(dim_lambdavec)==3):
init_hgeneral_symmetries_lattice_d5(hvec,dim_hvec,lambdavec,dim_lambdavec)
else:
raise ValueError('Shape(lambdavec) != 2 or 3 in set_Hgeneral')
else:
raise ValueError('Shape(Hvec) != 3 or 5 in set_Hgeneral')
return ;

#break_symmetry_bath
def break_symmetry_bath(self, bath, field, sign, save=True):
break_symmetry_bath_site = self.library.break_symmetry_bath_site
Expand Down
30 changes: 30 additions & 0 deletions src/edi2py/edi2py_bath.f90
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ subroutine init_Hreplica_symmetries_lattice_d3_c(Hvec,d_hvec,lambdavec,d_lambdav
end subroutine init_Hreplica_symmetries_lattice_d3_c


!H_general SETUP
subroutine init_Hgeneral_symmetries_d5_c(Hvec,d_hvec,lambdavec,d_lambdavec) bind(c, name='init_Hgeneral_symmetries_d5')
integer(c_int64_t) :: d_hvec(5), d_lambdavec(2)
complex(c_double_complex),dimension(d_hvec(1),d_hvec(2),d_hvec(3),d_hvec(4),d_hvec(5)) :: Hvec
real(c_double),dimension(d_lambdavec(1),d_lambdavec(2)) :: lambdavec
call ed_set_Hgeneral(Hvec,lambdavec)
end subroutine init_Hgeneral_symmetries_d5_c

subroutine init_Hgeneral_symmetries_d3_c(Hvec,d_hvec,lambdavec,d_lambdavec) bind(c, name='init_Hgeneral_symmetries_d3')
integer(c_int64_t) :: d_hvec(3), d_lambdavec(2)
complex(c_double_complex),dimension(d_hvec(1),d_hvec(2),d_hvec(3)) :: Hvec
real(c_double),dimension(d_lambdavec(1),d_lambdavec(2)) :: lambdavec
call ed_set_Hgeneral(Hvec,lambdavec)
end subroutine init_Hgeneral_symmetries_d3_c

subroutine init_Hgeneral_symmetries_lattice_d5_c(Hvec,d_hvec,lambdavec,d_lambdavec) bind(c, name='init_Hgeneral_symmetries_lattice_d5')
integer(c_int64_t) :: d_hvec(5), d_lambdavec(3)
complex(c_double_complex),dimension(d_hvec(1),d_hvec(2),d_hvec(3),d_hvec(4),d_hvec(5)) :: Hvec
real(c_double),dimension(d_lambdavec(1),d_lambdavec(2),d_lambdavec(3)) :: lambdavec
call ed_set_Hgeneral(Hvec,lambdavec)
end subroutine init_Hgeneral_symmetries_lattice_d5_c

subroutine init_Hgeneral_symmetries_lattice_d3_c(Hvec,d_hvec,lambdavec,d_lambdavec) bind(c, name='init_Hgeneral_symmetries_lattice_d3')
integer(c_int64_t) :: d_hvec(3), d_lambdavec(3)
complex(c_double_complex),dimension(d_hvec(1),d_hvec(2),d_hvec(3)) :: Hvec
real(c_double),dimension(d_lambdavec(1),d_lambdavec(2),d_lambdavec(3)) :: lambdavec
call ed_set_Hgeneral(Hvec,lambdavec)
end subroutine init_Hgeneral_symmetries_lattice_d3_c



!BREAK_SYMMETRY_BATH
subroutine break_symmetry_bath_site_c(bath,dim_bath,field,sgn,sav) bind(c, name='break_symmetry_bath_site')
Expand Down

0 comments on commit 313846f

Please sign in to comment.