Skip to content

Commit f3c22fb

Browse files
Doran RaccahDoran Raccah
authored andcommitted
MesoHOPS v1.3.1
This update provides a number of quality-of-life improvements (e.g. a larger variety of ways to define the noise trajectory) in the code base and fixes one problem with memory scaling introduced by CPU efficient (but linear scaling memory) algorithm for indexing auxiliary wave functions. The code is also more robust against some errors that were arising in edge-cases. Behind the scenes, a number of code updates have provided a more consistent set of naming conventions.
1 parent b332d02 commit f3c22fb

35 files changed

+1950
-884
lines changed

mesohops/dynamics/basis_functions_adaptive.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def error_flux_up(Φ, n_state, n_hier, n_hmodes, list_w, K2_aux_bymode,
196196

197197
else:
198198
E2_error = 0
199-
raise UnsupportedRequest(type, f"in error_flux_up received type {type}")
199+
raise UnsupportedRequest("type {}".format(type), "error_flux_up")
200200

201201
return E2_error
202202

@@ -288,7 +288,7 @@ def error_flux_down(Φ, n_state, n_hier, n_hmodes, list_g, list_w, M2_mode_from_
288288
)
289289
else:
290290
E2_flux_down_error = 0
291-
raise UnsupportedRequest(type, f"in error_flux_down received type {type}")
291+
raise UnsupportedRequest("type {}".format(type), "error_flux_down")
292292

293293
return E2_flux_down_error
294294

mesohops/dynamics/bath_corr_functions.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,59 @@ def bcf_convert_sdl_to_exp(lambda_sdl, gamma_sdl, omega_sdl, temp):
7272

7373
return (g_exp, w_exp)
7474

75+
def bcf_convert_dl_ud_to_exp(lambda_dl, gamma_dl, omega_dl, temp):
76+
"""
77+
Converts underdamped Drude-Lorentz spectral density parameters to the exponential
78+
equivalent. Assumes that omega_dl (the underdamped frequency) is larger than
79+
gamma_dl (the reorganization timescale). Does not account for Matsubara modes.
80+
81+
Parameters
82+
----------
83+
1. lambda_sdl : float [unit: cm^-1]
84+
Reorganization energy.
85+
86+
2. gamma_sdl : float [unit: cm^-1]
87+
Reorganization time scale.
88+
89+
3. omega_sdl : float [unit: cm^-1]
90+
Vibrational frequency.
91+
92+
4. temp : float [unit: K]
93+
Temperature.
94+
95+
Returns
96+
-------
97+
1. list_modes: list(complex)
98+
List of the exponential modes that comprise the correlation
99+
function, alternating gs and ws (complex, [cm^-2] and [cm^-1],
100+
representing the constant prefactor and exponential decay rate,
101+
respectively)
102+
"""
103+
beta = 1 / (kB * temp)
104+
xi = np.sqrt(omega_dl**2 - gamma_dl**2)
105+
prefactor_base = (lambda_dl * omega_dl**2)/(2 * xi)
106+
w_1 = xi + 1j*gamma_dl
107+
w_2 = -1*xi + 1j*gamma_dl
108+
g_1 = prefactor_base
109+
g_2 = -prefactor_base
110+
coth_w_1 = 1 / np.tanh(w_1*beta/2)
111+
coth_w_2 = 1 / np.tanh(w_2*beta/2)
112+
g_1 += (coth_w_1 - np.conj(coth_w_2)) * prefactor_base
113+
g_2 += (-coth_w_2 + np.conj(coth_w_1)) * prefactor_base
114+
115+
# # Test to prove that this expression is the same as the high-temperature
116+
# # approximation of equation S52 from Bennet et al., Supplementary Information:
117+
# # Mechanistic regimes of vibronic transport in a heterodimer and the design
118+
# # principle of incoherent vibronic transport in phycobiliproteins, J. Phys. Chem.
119+
# # Lett., 2018, https://doi.org/10.1021/acs.jpclett.8b00844:
120+
# t_axis = np.arange(0, 0.21, 0.01)
121+
# exp_form = g_1*np.exp(1j*w_1*t_axis) + g_2*np.exp(1j*w_2*t_axis)
122+
# analytic_form = (lambda_dl*(gamma_dl**2 + xi**2)/xi) * np.exp(-1*gamma_dl*t_axis)\
123+
# * (2*(np.sin(beta*gamma_dl)*np.sin(xi*t_axis) + np.sinh(
124+
# beta*xi)*np.cos(xi*t_axis))/(np.cosh(beta*xi)-np.cos(beta*gamma_dl)) +
125+
# 1j*np.sin(xi*t_axis))
126+
return [g_1, -1j*w_1, g_2, -1j*w_2]
127+
75128

76129
def bcf_convert_dl_to_exp_with_Matsubara(lambda_dl, gamma_dl, temp, k_matsubara):
77130
"""
@@ -189,4 +242,4 @@ def E_tilde_k(w):
189242
w_exp_conj = np.conj(w_exp)
190243

191244
return [g_exp - 1j*g_exp_im, w_exp, g_exp_conj - 1j*g_exp_im_conj, w_exp_conj] + \
192-
list_mats_modes
245+
list_mats_modes

mesohops/dynamics/eom_functions.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def operator_expectation(oper, vec, flag_gcorr = False):
1111
"""
12-
Calculates the expectation value of a sparse operator
12+
Calculates the expectation value of a sparse operator.
1313
1414
Parameters
1515
----------
@@ -63,10 +63,10 @@ def compress_zmem(z_mem, list_index_L2_by_mode, list_absindex_mode):
6363
return dz_hat
6464

6565

66-
def calc_delta_zmem(z_mem, list_avg_L2, list_g, list_w, list_index_L2_by_mode,
67-
list_absindex_mode, list_index_L2_active):
66+
def calc_delta_zmem(z_mem, list_avg_L2, list_g, list_w, list_absindex_L2_by_mode,
67+
list_absindex_mode, list_absindex_L2_active):
6868
"""
69-
This updates the memory term. The form of the equation depends on expanding the
69+
Updates the memory term. The form of the equation depends on expanding the
7070
memory integral assuming an exponential expansion.
7171
7272
NOTE: THIS ASSUMES THE NOISE HAS EXPONENTIAL FORM.
@@ -77,9 +77,9 @@ def calc_delta_zmem(z_mem, list_avg_L2, list_g, list_w, list_index_L2_by_mode,
7777
list_avg_L2 : relative
7878
list_g : absolute
7979
list_w : absolute
80-
list_index_L2_by_mode : relative
80+
list_absindex_L2_by_mode : absolute
8181
list_absindex_mode : mapping from relative-->absolute
82-
list_index_L2_active : relative
82+
list_absindex_L2_active : absolute
8383
8484
Parameters
8585
----------
@@ -90,23 +90,24 @@ def calc_delta_zmem(z_mem, list_avg_L2, list_g, list_w, list_index_L2_by_mode,
9090
Relative list of the expectation values of the L operators.
9191
9292
3. list_g : list(complex)
93-
List of pre exponential factors for bath correlation functions [
94-
absolute].
93+
List of pre exponential factors for bath correlation functions [unit:
94+
cm^-2].
9595
9696
4. list_w : list(complex)
97-
List of exponents for bath correlation functions (w = γ+iΩ) [absolute].
97+
List of exponents for bath correlation functions (w = γ+iΩ) [unit:
98+
cm^-1].
9899
99-
5. list_index_L2_by_mode : list(int)
100-
List of length equal to the number of 'modes' in the
101-
current hierarchy basis and each entry is an index for
102-
the absolute list_L2.
100+
5. list_absindex_L2_by_mode : list(int)
101+
List of indices for the absolute list of L-operators
102+
to match L-operators to the associated absolute mode
103+
index.
103104
104105
6. list_absindex_mode : list(int)
105106
List of the absolute indices of the modes in current basis.
106107
107-
7. list_index_L2_active : list(int)
108-
List of relative indices of L-operators that have any
109-
non-zero values.
108+
7. list_absindex_L2_active : list(int)
109+
List of absolute indices of L-operators that have any
110+
non-zero values.
110111
111112
Returns
112113
-------
@@ -121,11 +122,12 @@ def calc_delta_zmem(z_mem, list_avg_L2, list_g, list_w, list_index_L2_by_mode,
121122
)
122123

123124
# Loop over modes in the current basis
124-
for (relindex_mode, absindex_mode) in enumerate(list_absindex_mode):
125-
index_L2 = list_index_L2_by_mode[relindex_mode]
126-
if index_L2 in list_index_L2_active:
127-
l_avg = list_avg_L2[list_index_L2_active.index(index_L2)]
128-
else:
125+
for absindex_mode in list_absindex_mode:
126+
absindex_L2 = list_absindex_L2_by_mode[absindex_mode]
127+
try:
128+
relindex_L2 = list(list_absindex_L2_active).index(absindex_L2)
129+
l_avg = list_avg_L2[relindex_L2]
130+
except:
129131
l_avg = 0
130132
delta_z_mem[absindex_mode] = (
131133
l_avg * np.conj(list_g[absindex_mode])
@@ -286,4 +288,4 @@ def calc_LT_corr_linear(
286288
the low-temperature correction self-derivative term
287289
"""
288290
return -1*np.sum(np.array([(list_LT_coeff[n])*list_L2[n]@list_L2[n] for n in
289-
range(len(list_LT_coeff))]),axis=0)
291+
range(len(list_LT_coeff))]),axis=0)

mesohops/dynamics/eom_hops_ksuper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,12 @@ def _add_crossterms_stable_K(
284284
for l_mode_abs in list_new_mode:
285285
#For each new mode, we look through our dictionary of mode connections between stable auxiliaries and add the corresponding entry to K
286286
#super operators.
287-
if(len(hierarchy.stable_aux_hash_conn_by_mode[l_mode_abs]) > 0):
288-
list_hashes, list_aux_conn_hash_and_value = list(zip(*hierarchy.stable_aux_hash_conn_by_mode[
287+
if(len(hierarchy.stable_aux_id_conn_by_mode[l_mode_abs]) > 0):
288+
list_ids, list_aux_conn_id_and_value = list(zip(*hierarchy.stable_aux_id_conn_by_mode[
289289
l_mode_abs].items()))
290-
list_aux_indices = [hierarchy._aux_index(hierarchy._aux_by_hash[hash_]) for hash_ in list_hashes]
291-
list_hashes_p1, list_aux_mode_values = list(zip(*list_aux_conn_hash_and_value))
292-
list_aux_indices_p1 = [hierarchy._aux_index(hierarchy._aux_by_hash[hash_]) for hash_ in list_hashes_p1]
290+
list_aux_indices = [hierarchy._aux_index(hierarchy.dict_aux_by_id[id_]) for id_ in list_ids]
291+
list_ids_p1, list_aux_mode_values = list(zip(*list_aux_conn_id_and_value))
292+
list_aux_indices_p1 = [hierarchy._aux_index(hierarchy.dict_aux_by_id[id_]) for id_ in list_ids_p1]
293293
l_mod = list(mode.list_absindex_mode).index(l_mode_abs)
294294
i_lop = mode.list_index_L2_by_hmode[l_mod]
295295
Kp1_data.extend(

0 commit comments

Comments
 (0)