Skip to content

Commit

Permalink
Update python
Browse files Browse the repository at this point in the history
  • Loading branch information
prckent committed Feb 14, 2023
1 parent 8ba2aaf commit d4cf0ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
36 changes: 18 additions & 18 deletions utils/afqmctools/afqmctools/hamiltonian/kpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def write_hamil_kpoints(comm, scf_data, hamil_file, chol_cut,
verbose=True, cas=None, max_vecs=20,
ortho_ao=False, exxdiv='ewald', nelec=None,
phdf=False):
tstart = time.clock()
tstart = time.process_time()()

# Unpack pyscf data.
# 1. core (1-body) Hamiltonian.
Expand Down Expand Up @@ -78,16 +78,16 @@ def write_hamil_kpoints(comm, scf_data, hamil_file, chol_cut,
qk_to_k2, kminus, verbose=verbose, nelec=nelec)

if comm.rank == 0 and verbose:
print(" # Time to reach Cholesky: {:13.8e} s.".format(time.clock()-tstart))
print(" # Time to reach Cholesky: {:13.8e} s.".format(time.process_time()()-tstart))
sys.stdout.flush()
tstart = time.clock()
tstart = time.process_time()()

solver = KPCholesky(comm, cell, kpts, max_vecs, nmo_pk,
qk_to_k2, kminus, gtol_chol=chol_cut,
verbose=verbose)
solver.run(comm, X, h5file)
if comm.rank == 0 and verbose:
print(" # Time to perform Cholesky: {:13.8e} s.".format(time.clock()-tstart))
print(" # Time to perform Cholesky: {:13.8e} s.".format(time.process_time()()-tstart))
sys.stdout.flush()

comm.barrier()
Expand Down Expand Up @@ -121,7 +121,7 @@ def write_hamil_kpoints(comm, scf_data, hamil_file, chol_cut,
def write_rhoG_kpoints(comm, scf_data, hdf_file, Gcut,
verbose=True,
ortho_ao=False, phdf=False):
tstart = time.clock()
tstart = time.process_time()()

# Unpack pyscf data.
# 1. core (1-body) Hamiltonian.
Expand Down Expand Up @@ -302,7 +302,7 @@ def __init__(self, comm, cell, kpts, maxvecs, nmo_pk, QKToK2, kminus,
"Cholesky solver.")
sys.exit()
self.df = df.FFTDF(cell,kpts)
tstart = time.clock()
tstart = time.process_time()()

self.nmo_pk = nmo_pk
self.gtol_chol = gtol_chol
Expand Down Expand Up @@ -414,15 +414,15 @@ def run(self, comm, X, h5file):
"time_k3k4", "time_comp_cholv", "time_buff"]

for Q in range(nkpts):
t0 = time.clock()
t0 = time.process_time()()
if Q > self.kminus[Q]:
continue
if comm.rank == 0 and self.verbose:
print(" # Calculating factorization for momentum: {}".format(Q))
print(" # Generating orbital products")
sys.stdout.flush()

t1 = time.clock()
t1 = time.process_time()()

maxresidual[:] = 0
done[:,:,:] = 0
Expand All @@ -442,7 +442,7 @@ def run(self, comm, X, h5file):
k3, k4, i3, i4, vmax = self.find_k3k4(comm.size)
done[k3,i3,i4] = 1

tstart = time.clock()
tstart = time.process_time()()
if comm.rank == 0:
sys.stdout.flush()

Expand All @@ -452,7 +452,7 @@ def run(self, comm, X, h5file):
numv = 0
while more:

t0 = time.clock()
t0 = time.process_time()()
# stop condition
if comm.rank == 0 and self.verbose:
if numv == 0:
Expand Down Expand Up @@ -496,15 +496,15 @@ def run(self, comm, X, h5file):
# add new Cholesky vector
# 1. evaluate new column (ik|imax,kmax)

t1 = time.clock()
t1 = time.process_time()()
tadd = 0.0
for k in range(part.nkk):
k1 = k + part.kk0
k2 = QKToK2[Q][k1]
if part.ij0 > nmo_pk[k1]*nmo_pk[k2]:
continue
if numpy.sum(abs(kpts[k2]-kpts[k1]+kpts[k3]-kpts[k4])) > 1e-9:
t_ = time.clock()
t_ = time.process_time()()
q1 = kpts[k2]-kpts[k1]+kpts[k3]-kpts[k4]
ip = -1
for ii in range(27):
Expand All @@ -516,13 +516,13 @@ def run(self, comm, X, h5file):
sys.exit()
for ix in range(ngs):
Xkl[ix] = Xkl0[self.gmap[ip,ix]]
tadd += time.clock() - t_
tadd += time.process_time()() - t_
else:
Xkl[0:ngs] = Xkl0[0:ngs]
n_ = min(nmo_pk[k1]*nmo_pk[k2], part.ijN) - part.ij0
cholvecs[k,0:n_,numv] = numpy.dot(Xaoik[k,:,0:n_].T,
Xkl.conj())
t2 = time.clock()
t2 = time.process_time()()

# 2. substract projection along previous components
cholvecs[:,:,numv] -= numpy.dot(cholvecs[:,:,0:numv],
Expand Down Expand Up @@ -552,15 +552,15 @@ def run(self, comm, X, h5file):
i1max = (ij+part.ij0) // nmo_pk[k2]
i2max = (ij+part.ij0) % nmo_pk[k2]

t3 = time.clock()
t3 = time.process_time()()

# assemble full CV on head node
buff = numpy.array([k1max,k2max,i1max,i2max,maxv],
dtype=numpy.float64)
comm.Allgather(buff, self.maxres_buff)
k3, k4, i3, i4, vmax = self.find_k3k4(comm.size)

t4 = time.clock()
t4 = time.process_time()()

# only root keeps track of residual and I/O
if comm.rank == 0:
Expand All @@ -570,7 +570,7 @@ def run(self, comm, X, h5file):
output = [vmax, t4-t0, t3-t2, t2-t1, t1-t0]
if self.verbose:
print("{:17d} ".format(numv)+format_fixed_width_floats(output))
tstart = time.clock()
tstart = time.process_time()()

if numv%100 == 0:
sys.stdout.flush()
Expand All @@ -586,7 +586,7 @@ def run(self, comm, X, h5file):
sys.exit()
done[k3,i3,i4] = 1

t6 = time.clock()
t6 = time.process_time()()

comm.barrier()
num_cholvecs[Q] = numv
Expand Down
38 changes: 19 additions & 19 deletions utils/afqmctools/afqmctools/hamiltonian/supercell.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def write_hamil_supercell(comm, scf_data, hamil_file, chol_cut,
nproc = comm.size
rank = comm.rank

tstart = time.clock()
tstart = time.process_time()()

# Unpack pyscf data.
# 1. core (1-body) Hamiltonian.
Expand Down Expand Up @@ -63,9 +63,9 @@ def write_hamil_supercell(comm, scf_data, hamil_file, chol_cut,
numv = 0

if rank == 0 and verbose:
print(" # Time to reach cholesky: {:.2e} s".format(time.clock()-tstart))
print(" # Time to reach cholesky: {:.2e} s".format(time.process_time()()-tstart))
sys.stdout.flush()
tstart = time.clock()
tstart = time.process_time()()

# Setup parallel partition of work.
part = Partition(comm, maxvecs, nmo_tot, nmo_max, nkpts)
Expand All @@ -86,10 +86,10 @@ def write_hamil_supercell(comm, scf_data, hamil_file, chol_cut,
sys.stdout.flush()

# Left and right pair densities. Only left contains Coulomb kernel.
t0 = time.clock()
t0 = time.process_time()()
Xaoik, Xaolj = gen_orbital_products(cell, mydf, X, nmo_pk, ngs,
part, kpts, nmo_max)
t1 = time.clock()
t1 = time.process_time()()
if part.rank == 0 and verbose:
print(" # Time to generate orbital products: {:.2e} s".format(t1-t0))
sys.stdout.flush()
Expand Down Expand Up @@ -118,7 +118,7 @@ def write_rhoG_supercell(comm, scf_data, hdf_file, Gcut,
nproc = comm.size
rank = comm.rank

tstart = time.clock()
tstart = time.process_time()()

# Unpack pyscf data.
# 1. Rotation matrix to orthogonalised basis.
Expand Down Expand Up @@ -475,7 +475,7 @@ def gen_orbital_products(cell, mydf, X, nmo_pk, ngs, part, kpts, nmo_max):
Xaolj[k,:,:] = Xaoik[k,:,:]
coulG = tools.get_coulG(cell, kpts[k2]-kpts[k1], mesh=mydf.mesh)
Xaoik[k,:,:] *= (coulG*cell.vol/ngs**2).reshape(-1,1)
t1 = time.clock()
t1 = time.process_time()()
return Xaoik, Xaolj


Expand Down Expand Up @@ -536,11 +536,11 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
# Setup residual matrix.
ngs = Xaoik.shape[1]
nkpts = len(kpts)
t0 = time.clock()
t0 = time.process_time()()
residual, k1max, k2max, i1max, i2max, maxv = (
self.generate_diagonal(Xaoik, Xaolj, part, nmo_pk)
)
t1 = time.clock()
t1 = time.process_time()()
if part.rank == 0 and self.verbose:
print(" # Time to generate diagonal (initial residual):"
" {:.2e}".format(t1-t0))
Expand All @@ -562,7 +562,7 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
"Cholesky solver.")
done[k3,k4,i3,i4] = 1

tstart = time.clock()
tstart = time.process_time()()
if comm.rank == 0:
sys.stdout.flush()

Expand All @@ -574,7 +574,7 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
if self.verbose:
print(format_fixed_width_strings(header))
while more:
t0 = time.clock()
t0 = time.process_time()()
# stop condition
if numv >= part.maxvecs:
print(" Too many vectors needed to converge. Increase maximum "
Expand Down Expand Up @@ -612,7 +612,7 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
# add new Cholesky vector
# 1. evaluate new column (ik|imax,kmax)

t1 = time.clock()
t1 = time.process_time()()
tadd = 0.0

for k in range(part.nkk):
Expand All @@ -621,7 +621,7 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
if k3 == self.kconserv[k1,k2,k4]:
q1 = kpts[k2] - kpts[k1] + kpts[k3] - kpts[k4]
if numpy.sum(abs(q1)) > 1e-9:
t_ = time.clock()
t_ = time.process_time()()
ip = -1
for ii in range(27):
if numpy.sum(numpy.linalg.norm(q1-Qi[ii,:])) < 1e-12:
Expand All @@ -632,14 +632,14 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
sys.exit()
for ix in range(ngs):
Xkl[ix] = Xkl0[gmap[ip,ix]]
tadd += time.clock() - t_
tadd += time.process_time()() - t_
else:
Xkl[0:ngs] = Xkl0[0:ngs]
n_ = min(nmo_pk[k1]*nmo_pk[k2], part.ijN) - part.ij0
cholvecs[k,0:n_,numv] = numpy.dot(Xaoik[k,:,0:n_].T,
Xkl.conj())

t2 = time.clock()
t2 = time.process_time()()

# 2. subtract projection along previous components
cholvecs[:,:,numv] -= numpy.dot(cholvecs[:,:,0:numv],
Expand All @@ -663,14 +663,14 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
i1max = (ij+part.ij0) // nmo_pk[k2]
i2max = (ij+part.ij0) % nmo_pk[k2]

t3 = time.clock()
t3 = time.process_time()()

# assemble full CV on head node
comm.Allgather(numpy.array([k1max,k2max,i1max,i2max,maxv],
dtype=numpy.float64), self.maxres_buff)
k3, k4, i3, i4, vmax = self.find_k3k4(comm.size)

t4 = time.clock()
t4 = time.process_time()()

# only root keeps track of residual and I/O
if part.rank == 0:
Expand All @@ -682,7 +682,7 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
if self.verbose:
print("{:17d} ".format(numv)+format_fixed_width_floats(output))
# print("{:8d} {:13.8e}".format(numv, vmax))
tstart = time.clock()
tstart = time.process_time()()

if numv%100 == 0:
sys.stdout.flush()
Expand All @@ -697,7 +697,7 @@ def run(self, comm, Xaoik, Xaolj, part, kpts, nmo_pk, nmo_max, Qi, gmap):
sys.exit()
done[k3,k4,i3,i4]=1

t6 = time.clock()
t6 = time.process_time()()
return cholvecs[:,:,:numv]

def write_h1(h5grp, intgs, npk, ik2n, gtol=1e-6):
Expand Down

0 comments on commit d4cf0ad

Please sign in to comment.