Skip to content

Commit 850bd62

Browse files
committed
Renew the summation routine according to the changes in patch dynamics routines
1 parent 046d1e5 commit 850bd62

File tree

1 file changed

+29
-15
lines changed
  • src/libra_py/workflows/nbra

1 file changed

+29
-15
lines changed

src/libra_py/workflows/nbra/rpi.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,9 @@ def process_batch(args):
341341
* **rpi_sum_params["nstates"]** ( int ): The number of electronic states.
342342
343343
* **rpi_sum_params["path_to_save_patch"]** ( string ): The path of the precomputed patch dynamics
344-
344+
345+
* **rpi_sum_params["prefix_patch"]** ( string ): The prefix of patch dynamics directories
346+
345347
* **rpi_sum_params["prefix"]** ( string ): The prefix for the population dynamics output
346348
347349
Return:
@@ -351,13 +353,15 @@ def process_batch(args):
351353
ibatch, rpi_sum_params = args
352354

353355
critical_params = ["path_to_save_patch"]
354-
default_params = {"nprocs": 1, "nsteps": 1, "dt": 1.0*units.fs2au, "istate": 0, "nbatches": 1, "npatches": 1, "nstates": 2, "prefix": 'out'}
356+
default_params = {"nprocs": 1, "nsteps": 1, "dt": 1.0*units.fs2au, "istate": 0, "nbatches": 1, "npatches": 1, "nstates": 2,
357+
"prefix_patch": 'out_', "prefix": 'POP_NPATCH_'}
355358

356359
comn.check_input(rpi_sum_params, default_params, critical_params)
357360

358361
nsteps, dt, istate = rpi_sum_params["nsteps"], rpi_sum_params["dt"], rpi_sum_params["istate"]
359-
npatches, nstates = rpi_sum_params["npatches"], rpi_sum_params["nstates"]
360-
path_to_save_patch = rpi_sum_params["path_to_save_patch"]
362+
nbatches, npatches, nstates = rpi_sum_params["nbatches"], rpi_sum_params["npatches"], rpi_sum_params["nstates"]
363+
path_to_save_patch, prefix_patch = rpi_sum_params["path_to_save_patch"], rpi_sum_params["prefix_patch"]
364+
prefix = rpi_sum_params["prefix"]
361365

362366
nstep_patch = int(nsteps / npatches)
363367
pops = np.zeros((npatches * nstep_patch + 1, nstates))
@@ -372,7 +376,8 @@ def process_batch(args):
372376
# Compute the transition probability from a patch dynamics
373377
T = np.zeros((nstep_patch, nstates, nstates)) # (timestep in a patch, init, dest)
374378
for ist in range(nstates):
375-
with h5py.File(F"{path_to_save_patch}/job_{ibatch}_{ipatch}_{ist}/out/mem_data.hdf", 'r') as f:
379+
with h5py.File(F"{path_to_save_patch}/{prefix_patch}" +
380+
F"n{nbatches}_ibatch{ibatch}_n{npatches}_ipatch{ipatch}_n{nstates}_istate{ist}/mem_data.hdf", 'r') as f:
376381
pop_adi_data = np.array(f["se_pop_adi/data"])
377382
T[:, ist, :] = pop_adi_data[1:,:]
378383
T[:, ist, ist] = 0.0 # zero diagonal explicitly
@@ -389,11 +394,11 @@ def process_batch(args):
389394
# Per-batch output
390395
time = np.array([x for x in range(npatches * nstep_patch + 1)]) * dt
391396
print(F"Print the population from ibatch")
392-
print_pop(rpi_params["prefix"] + F"_ibatch{ibatch}.dat", time, pops)
397+
print_pop(prefix + F"{npatches}_ibatch{ibatch}.dat", time, pops)
393398

394399
return pops
395400

396-
def run_sum_rpi(rpi_sum_params):
401+
def run_sum(rpi_sum_params):
397402
"""
398403
This function conducts the RPI patch summation to yield the population dynamics in the whole time domain.
399404
@@ -418,21 +423,25 @@ def run_sum_rpi(rpi_sum_params):
418423
* **rpi_sum_params["nstates"]** ( int ): The number of electronic states.
419424
420425
* **rpi_sum_params["path_to_save_patch"]** ( string ): The path of the precomputed patch dynamics
426+
427+
* **rpi_sum_params["prefix_patch"]** ( string ): The prefix of patch dynamics directories
421428
422429
* **rpi_sum_params["prefix"]** ( string ): The prefix for the population dynamics output
423430
424431
Return:
425432
None: but performs the action
426433
"""
427434
critical_params = ["path_to_save_patch"]
428-
default_params = {"nprocs": 1, "nsteps": 1, "dt": 1.0*units.fs2au, "istate": 0, "nbatches": 1, "npatches": 1, "nstates": 2, "prefix": 'out'}
435+
default_params = {"nprocs": 1, "nsteps": 1, "dt": 1.0*units.fs2au, "istate": 0, "nbatches": 1, "npatches": 1, "nstates": 2,
436+
"prefix_patch": 'out_', "prefix": 'POP_NPATCH_'}
429437

430438
comn.check_input(rpi_sum_params, default_params, critical_params)
431439

432440
nprocs = rpi_sum_params["nprocs"]
433441

434442
nsteps, dt = rpi_sum_params["nsteps"], rpi_sum_params["dt"]
435443
nbatches, npatches, nstates = rpi_sum_params["nbatches"], rpi_sum_params["npatches"], rpi_sum_params["nstates"]
444+
prefix = rpi_sum_params["prefix"]
436445

437446
nstep_patch = int(nsteps / npatches)
438447
time = np.array([x for x in range(npatches * nstep_patch + 1)]) * dt
@@ -447,10 +456,10 @@ def run_sum_rpi(rpi_sum_params):
447456
pops_avg /= nbatches
448457

449458
print("Print the final population from all batches")
450-
print_pop(rpi_sum_params["prefix"] + "_all.dat", time, pops_avg)
459+
print_pop(prefix + F"{npatches}_all.dat", time, pops_avg)
451460

452461

453-
def run_sum_rpi_crude(rpi_sum_params):
462+
def run_sum_crude(rpi_sum_params):
454463
"""
455464
This function conducts the RPI patch summation to yield the population dynamics in the whole time domain.
456465
@@ -475,21 +484,25 @@ def run_sum_rpi_crude(rpi_sum_params):
475484
* **rpi_sum_params["nstates"]** ( int ): The number of electronic states.
476485
477486
* **rpi_sum_params["path_to_save_patch"]** ( string ): The path of the precomputed patch dynamics
487+
488+
* **rpi_sum_params["prefix_patch"]** ( string ): The prefix of patch dynamics directories
478489
479490
* **rpi_sum_params["prefix"]** ( string ): The prefix for the population dynamics output
480491
481492
Return:
482493
None: but performs the action
483494
"""
484495
critical_params = ["path_to_save_patch"]
485-
default_params = {"nprocs": 1, "nsteps": 1, "dt": 1.0*units.fs2au, "istate": 0, "nbatches": 1, "npatches": 1, "nstates": 2, "prefix": 'out'}
496+
default_params = {"nprocs": 1, "nsteps": 1, "dt": 1.0*units.fs2au, "istate": 0, "nbatches": 1, "npatches": 1, "nstates": 2,
497+
"prefix_patch": 'out_', "prefix": 'POP_NPATCH_'}
486498

487499
comn.check_input(rpi_sum_params, default_params, critical_params)
488500

489501
nsteps, dt, istate = rpi_sum_params["nsteps"], rpi_sum_params["dt"], rpi_sum_params["istate"]
490502

491503
nbatches, npatches, nstates = rpi_sum_params["nbatches"], rpi_sum_params["npatches"], rpi_sum_params["nstates"]
492-
path_to_save_patch = rpi_sum_params["path_to_save_patch"]
504+
path_to_save_patch, prefix_patch = rpi_sum_params["path_to_save_patch"], rpi_sum_params["prefix_patch"]
505+
prefix = rpi_sum_params["prefix"]
493506

494507
nstep_patch = int(nsteps / npatches)
495508

@@ -513,7 +526,8 @@ def run_sum_rpi_crude(rpi_sum_params):
513526
pop_patch.fill(0.0)
514527
T.fill(0.0)
515528
for ist in range(nstates):
516-
with h5py.File(F"{path_to_save_patch}/job_{ibatch}_{ipatch}_{ist}/out/mem_data.hdf", 'r') as f:
529+
with h5py.File(F"{path_to_save_patch}/{prefix_patch}" +
530+
F"n{nbatches}_ibatch{ibatch}_n{npatches}_ipatch{ipatch}_n{nstates}_istate{ist}/mem_data.hdf", 'r') as f:
517531
pop_adi_data = np.array(f["se_pop_adi/data"])
518532

519533
for istep in range(nstep_patch):
@@ -539,10 +553,10 @@ def run_sum_rpi_crude(rpi_sum_params):
539553
pops_avg += pops
540554

541555
print(F"Print the population from ibatch, ibatch = {ibatch}")
542-
print_pop(rpi_sum_params["prefix"] + F"_ibatch{ibatch}.dat", time, pops)
556+
print_pop(prefix + F"{npatches}_ibatch{ibatch}.dat", time, pops)
543557

544558
pops_avg /= nbatches
545559

546560
print("Print the final population from all batches")
547-
print_pop(rpi_sum_params["prefix"] + "_all.dat", time, pops_avg)
561+
print_pop(prefix + F"{npatches}_all.dat", time, pops_avg)
548562

0 commit comments

Comments
 (0)