Skip to content

Commit b332d02

Browse files
committed
MesoHops v1.3
This commit is a major update over the previous version of MesoHOPS including: 1. The implementation of an adaptive algorithm that works for arbitrary diagonal L-operators. In practice, this means the adHOPS can now be used for multi-particle dynamics! 2. A substantial speed improvement (3-8x faster for large systems) 3. A modest further improvement in memory when managing a large number of auxiliary wave functions 4. Some behind the scenes simplifications in the code design that will allow enable future generalizations 5. The noise class has been condensed and now has some additional options for how the uncorrelated noise is initially generated Starting with this commit, we are implementing levels of testing. For most purposes, pytest -level 1 is sufficient to ensure the code is behaving as expected. pytest -level 2 invokes a much slower set of tests that ensures the random number generators are performing within expected tolerances.
1 parent f765646 commit b332d02

33 files changed

+3887
-1390
lines changed

mesohops/dynamics/basis_functions_adaptive.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def error_flux_up(Φ, n_state, n_hier, n_hmodes, list_w, K2_aux_bymode,
181181
if (type == "H"):
182182
# \sum_s |L_m[s,s] \psi_k[s]|^2 = \sum_s |M2[m,s] * \psi_k[s]|^2
183183
# \sum_s |M2[m,s]|^2 * |\psi_k[s]|^2
184-
P2_pop_modes = (np.abs(M2_mode_from_state)**2 @ (np.abs(C2_phi) ** 2))
184+
P2_pop_modes = (np.abs(M2_mode_from_state).power(2) @ (np.abs(C2_phi) ** 2))
185185
E2_error = np.abs(W2_bymode) ** 2 * (1 + K2_aux_bymode) ** 2 * P2_pop_modes / hbar ** 2
186186
if F2_filter is not None:
187187
E2_error = F2_filter*E2_error
@@ -191,7 +191,7 @@ def error_flux_up(Φ, n_state, n_hier, n_hmodes, list_w, K2_aux_bymode,
191191
E2_error = np.abs(np.abs(W2_bymode) * (1 + K2_aux_bymode)) ** 2
192192
if F2_filter is not None:
193193
E2_error *= F2_filter
194-
E2_error = np.transpose(M2_mode_from_state) @ E2_error
194+
E2_error = np.transpose(M2_mode_from_state.power(2)) @ E2_error
195195
E2_error = P2_pop_state * E2_error / hbar ** 2
196196

197197
else:
@@ -263,7 +263,7 @@ def error_flux_down(Φ, n_state, n_hier, n_hmodes, list_g, list_w, M2_mode_from_
263263
# Hierarchy Type Downward Flux
264264
# ============================
265265
D2_mode_from_state = np.zeros([n_hmodes,n_state])
266-
D2_mode_from_state[:,:] = M2_mode_from_state - E1_Lm.reshape([len(E1_Lm),1])
266+
D2_mode_from_state[:,:] = M2_mode_from_state.toarray() - E1_Lm.reshape([len(E1_Lm),1])
267267
E2_flux_down_error = (
268268
np.real(
269269
(np.abs(G2_bymode / W2_bymode) ** 2)
@@ -278,7 +278,7 @@ def error_flux_down(Φ, n_state, n_hier, n_hmodes, list_g, list_w, M2_mode_from_
278278
# State Type Downward Flux
279279
# ========================
280280
D2_state_from_mode = np.zeros([n_state,n_hmodes])
281-
D2_state_from_mode[:,:] = np.transpose(M2_mode_from_state) - E1_Lm
281+
D2_state_from_mode[:,:] = np.transpose(M2_mode_from_state).toarray() - E1_Lm
282282
E2_flux_down_error = np.abs(G2_bymode / W2_bymode)**2
283283
if F2_filter is not None:
284284
E2_flux_down_error *= F2_filter

mesohops/dynamics/eom_functions.py

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
__title__ = "EOM Functions"
6-
__author__ = "D. I. G. Bennett"
6+
__author__ = "D. I. G. Bennett, J. K. Lynd"
77
__version__ = "1.2"
88

99

@@ -191,3 +191,99 @@ def calc_norm_corr(
191191
delta += (np.conj(phi_0) @ phi_1) * list_avg_L2[l_ind]
192192

193193
return np.real(delta)
194+
195+
def calc_LT_corr(
196+
list_LT_coeff, list_L2, list_avg_L2, physical = False
197+
):
198+
"""
199+
This function computes the low-temperature correction factor associated with each
200+
member of the hierarchy in the nonlinear equation of motion. The factor is given by
201+
the sum over the low-temperature correction coefficients and associated
202+
L-operators c_n and L_n:
203+
\sum_n (2<L_n>Re[c_n] - L_nc_n)L_n
204+
Where c_n is the nth low-temperature correction factor, and L_n is the nth
205+
L-operator associated with that factor.
206+
207+
PARAMETERS
208+
----------
209+
1. list_LT_coeff : list
210+
relative list of low-temperature coefficients
211+
2. list_L2 : list
212+
relative list of active L operators
213+
3. list_avg_L2 : list
214+
relative list of the expectation values of the active L operators
215+
4. physical : boolean
216+
Determines if this correction is to be applied to the physical
217+
wavefunction or elsewhere
218+
RETURNS
219+
-------
220+
1. C2_corr : np.array
221+
the low-temperature correction self-derivative term
222+
"""
223+
# Adds the terminated flux from above to the physical wavefunction
224+
if physical:
225+
return np.sum(np.array([(list_LT_coeff[n]*list_avg_L2[n]*np.eye(
226+
list_L2[n].shape[0]) - list_LT_coeff[n]*list_L2[n])@list_L2[n] for n in
227+
range(len(list_LT_coeff))]), axis=0)
228+
# Adds the delta-approximated noise memory drift to all members of the hierarchy
229+
else:
230+
return np.sum(np.array([(np.conj(list_LT_coeff[n])*list_avg_L2[n]*np.eye(
231+
list_L2[n].shape[0]))@list_L2[n] for n in range(len(list_LT_coeff))]), axis=0)
232+
233+
def calc_LT_corr_to_norm_corr(
234+
list_LT_coeff, list_avg_L2, list_avg_L2_sq
235+
):
236+
"""
237+
This function computes the low-temperature correction to the normalization factor in
238+
the normalized nonlinear equation of motion. The correction is given by the sum
239+
over the low-temperature correction coefficients and associated L-operators c_n
240+
and L_n:
241+
\sum_n Re[c_n](2<L_n>^2 - <L_n^2>)
242+
Where c_n is the nth low-temperature correction factor, and L_n is the nth
243+
L-operator associated with that factor.
244+
245+
PARAMETERS
246+
----------
247+
1. list_LT_coeff : list
248+
relative list of low-temperature coefficients
249+
2. list_avg_L2 : list
250+
relative list of the expectation values of the L operators
251+
3. list_avg_L2_sq : list
252+
relative list of the expectation values of the squared L
253+
operators
254+
RETURNS
255+
-------
256+
1. delta_corr : float
257+
the low-temperature correction to the normalization correction
258+
factor
259+
"""
260+
return np.sum(np.array([
261+
np.real(list_LT_coeff[j])*(2*list_avg_L2[j]**2 - list_avg_L2_sq[j])
262+
for j in range(len(list_LT_coeff))]))
263+
264+
def calc_LT_corr_linear(
265+
list_LT_coeff, list_L2
266+
):
267+
"""
268+
This function computes the low-temperature correction factor associated with each
269+
member of the hierarchy in the linear equation of motion. The factor is given by
270+
the sum over the low-temperature correction coefficients and associated
271+
L-operators c_n and L_n:
272+
-\sum_n c_nL_n^2
273+
Where c_n is the nth low-temperature correction factor, and L_n is the nth
274+
L-operator associated with that factor.
275+
NOTE: this correction should only be applied to the physical wavefunction.
276+
277+
PARAMETERS
278+
----------
279+
1. list_LT_coeff : list
280+
relative list of low-temperature coefficients
281+
2. list_L2 : list
282+
relative list of L operators
283+
RETURNS
284+
-------
285+
1. C2_corr : np.array
286+
the low-temperature correction self-derivative term
287+
"""
288+
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)

0 commit comments

Comments
 (0)