Skip to content

Commit 24f50f2

Browse files
MesoHops 1.4.0
This commit presents a major upgrade from the previous version of MesoHops, with improvements including: 1. Correction of a bug in the calculation of boundary error bounds. 2. Reduced memory and CPU time when calculating the adaptive basis via Numba implementation and array optimization. 3. A small flux boundary filter that further improves performance when the basis is large. 4. Reduced memory and CPU time when calculating the time-derivative operator. 5. Reduced memory during noise generation. 6. A low-temperature correction to capture the effects of ultrafast correlation function modes. 7. An effective integration of the noise to allow accurate calculations with larger time steps. 8. Improved internal consistency, documentation, and testing. As a result of these improvements: 1. MesoHops now depends on Numba. 2. Maximum hierarchy depth is 255.
1 parent f3c22fb commit 24f50f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2059
-1425
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.pyc
22
.DS_Store
33
mesohops.egg-info
4+
.idea
5+
.idea

docs/build/html/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ <h3>Navigation</h3>
4545
<div class="bodywrapper">
4646
<div class="body" role="main">
4747

48-
<div class="section" id="welcome-to-pyhops-s-documentation">
49-
<h1>Welcome to PYHOPS’s documentation!<a class="headerlink" href="#welcome-to-pyhops-s-documentation" title="Permalink to this headline"></a></h1>
48+
<div class="section" id="welcome-to-mesohops-s-documentation">
49+
<h1>Welcome to PYHOPS’s documentation!<a class="headerlink" href="#welcome-to-mesohops-s-documentation" title="Permalink to this headline"></a></h1>
5050
<div class="toctree-wrapper compound">
5151
<p class="caption"><span class="caption-text">Contents:</span></p>
5252
<ul>

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#
1313
# import os
1414
# import sys
15-
# sys.path.insert(0, os.path.abspath('/Users/leovarvelo/Documents/PythonLibrary/pyhopslib/pyhops'))
16-
#sys.path.insert(0, os.path.abspath('/Users/leovarvelo/Documents/Sphinx/copy_pyhops/pyhops'))
15+
# sys.path.insert(0, os.path.abspath('/Users/leovarvelo/Documents/PythonLibrary/mesohopslib/mesohops'))
16+
#sys.path.insert(0, os.path.abspath('/Users/leovarvelo/Documents/Sphinx/copy_mesohops/mesohops'))
1717

1818
# -- Project information -----------------------------------------------------
1919

docs/source/rec.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ py==1.8.1
4040
pycparser==2.19
4141
pycryptodome==3.9.7
4242
Pygments==2.5.2
43-
# Editable install with no version control (pyhops==0.2)
44-
-e /Users/leovarvelo/Documents/PythonLibrary/pyhopslib
43+
# Editable install with no version control (mesohops==0.2)
44+
-e /Users/leovarvelo/Documents/PythonLibrary/mesohopslib
4545
PyNaCl==1.3.0
4646
pyOpenSSL==19.1.0
4747
pyparsing==2.4.6

docs/source/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ py==1.8.1
4141
pycparser==2.19
4242
pycryptodome==3.9.7
4343
Pygments==2.5.2
44-
# Editable install with no version control (pyhops==0.2)
45-
#-e /Users/leovarvelo/Documents/PythonLibrary/pyhopslib
44+
# Editable install with no version control (mesohops==0.2)
45+
#-e /Users/leovarvelo/Documents/PythonLibrary/mesohopslib
4646
PyNaCl==1.3.0
4747
pyOpenSSL==19.1.0
4848
pyparsing==2.4.6

mesohops/dynamics/basis_functions.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,64 @@
22

33
__title__ = "Basis Functions"
44
__author__ = "D. I. G. Bennett, B. Citty"
5-
__version__ = "1.2"
5+
__version__ = "1.4"
66

77

8-
def determine_error_thresh(sorted_error, max_error):
8+
def determine_error_thresh(sorted_error, max_error, offset=0.0):
99
"""
1010
Determines which error value becomes the error threshold such
1111
that the sum of all errors below the threshold remains less than max_error.
1212
1313
Parameters
1414
----------
1515
1. sorted_error : np.array
16-
List of error values.
16+
List of error values, sorted least to greatest.
1717
1818
2. max_error : float
1919
Maximum error value.
2020
21+
3. offset : float
22+
Pre-calculated squared-error value that all values in sorted_error
23+
must be modulated by.
24+
2125
Returns
2226
-------
2327
1. error_thresh : float
2428
Error value at which the threshold is established.
2529
"""
2630
error_thresh = 0.0
2731
if len(sorted_error) > 0:
28-
index_thresh = np.argmax(np.sqrt(np.cumsum(sorted_error ** 2)) > max_error)
29-
32+
index_thresh = np.argmax(np.cumsum(sorted_error) + offset >= max_error)
3033
if index_thresh > 0:
3134
error_thresh = sorted_error[index_thresh - 1]
32-
elif sorted_error[0] <= max_error:
35+
36+
# If argmax = 0, either all cumulatively summed elements are less than
37+
# max_error (and should all be truncated from the basis), or all elements are
38+
# greater than/equal to max_error (and should all be added to the basis).
39+
elif sorted_error[0] + offset < max_error:
3340
error_thresh = np.inf
3441
return error_thresh
42+
43+
def calculate_delta_bound(delta_sq, stable_error_sq):
44+
45+
"""
46+
Calculates the error remaining after the stable step. The total error E
47+
satisfies E^2 = E_S^2 + E_B^2 < delta_sq where E_S and E_B are the stable
48+
and boundary errors, respectively. Therefore, the remaining squared boundary error
49+
threshold delta_bound_sq is given by delta_bound_sq = delta_sq - E_S^2.
50+
51+
Parameters
52+
----------
53+
1. delta_sq : float
54+
Total squared error tolerance.
55+
56+
2. stable_error_sq : float
57+
Squared stable error.
58+
59+
Returns
60+
-------
61+
1. delta_bound_sq : float
62+
Boundary squared error tolerance.
63+
"""
64+
delta_bound_sq = delta_sq - stable_error_sq
65+
return delta_bound_sq

mesohops/dynamics/basis_functions_adaptive.py

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
__title__ = "Adaptive Basis Functions"
77
__author__ = "D. I. G. Bennett, B. Citty"
8-
__version__ = "1.2"
8+
__version__ = "1.4"
99

1010

1111
def error_sflux_hier(Φ, list_s0, n_state, n_hier, H2_sparse_hamiltonian):
@@ -33,7 +33,7 @@ def error_sflux_hier(Φ, list_s0, n_state, n_hier, H2_sparse_hamiltonian):
3333
3434
Returns
3535
-------
36-
1. E2_flux_state : array
36+
1. E2_flux_state : np.array
3737
Error introduced by losing flux within k from S_t to S_t^C
3838
for each k in A_t.
3939
"""
@@ -147,33 +147,28 @@ def error_flux_up(Φ, n_state, n_hier, n_hmodes, list_w, K2_aux_bymode,
147147
5. list_w : list
148148
List of exponents for bath correlation functions.
149149
150-
6. list_absindex_mode : list
151-
List of the absolute indices of the modes in current basis.
152-
153-
7. K2_aux_by_mode : np.array
150+
6. K2_aux_by_mode : np.array
154151
Mode values of each auxiliary in the space of [mode,k].
155152
156-
8. M2_mode_from_state : np.array
153+
7. M2_mode_from_state : np.array
157154
The L_m[s,s] value in the space of [mode,s].
158155
159-
9. static_filter_param : dict
160-
a dictionary of parameters for the static filter.
161-
162-
10. type : str
156+
8. type : str
163157
Hierarchy or State basis ("H" or "S").
164158
165-
11. F2_filter : np.array
159+
9. F2_filter : np.array
166160
Filters out unwanted auxiliary connections in the space of [mode,k].
167161
168162
Returns
169163
-------
170-
1. E2_flux_up_error : np. array
164+
1. E2_flux_up_error : np.array
171165
Error induced by neglecting flux from A_t (or A_S)
172166
to auxiliaries with lower summed index in A_t^C.
173167
"""
174168
# Get flux factors
175169
# ----------------
176-
W2_bymode = np.tile(list_w,[1,n_hier]).reshape([n_hmodes, n_hier], order="F")
170+
list_w = np.abs(list_w)
171+
W2_bymode = list_w.reshape([n_hmodes,1], order="F")
177172

178173
# Reshape hierarchy (to matrix)
179174
# ------------------------------
@@ -182,13 +177,13 @@ def error_flux_up(Φ, n_state, n_hier, n_hmodes, list_w, K2_aux_bymode,
182177
# \sum_s |L_m[s,s] \psi_k[s]|^2 = \sum_s |M2[m,s] * \psi_k[s]|^2
183178
# \sum_s |M2[m,s]|^2 * |\psi_k[s]|^2
184179
P2_pop_modes = (np.abs(M2_mode_from_state).power(2) @ (np.abs(C2_phi) ** 2))
185-
E2_error = np.abs(W2_bymode) ** 2 * (1 + K2_aux_bymode) ** 2 * P2_pop_modes / hbar ** 2
180+
E2_error = (W2_bymode ** 2) * (1 + K2_aux_bymode) ** 2 * P2_pop_modes / hbar ** 2
186181
if F2_filter is not None:
187182
E2_error = F2_filter*E2_error
188183

189184
elif (type == "S"):
190185
P2_pop_state = np.abs(C2_phi) ** 2
191-
E2_error = np.abs(np.abs(W2_bymode) * (1 + K2_aux_bymode)) ** 2
186+
E2_error = np.abs(W2_bymode * (1 + K2_aux_bymode)) ** 2
192187
if F2_filter is not None:
193188
E2_error *= F2_filter
194189
E2_error = np.transpose(M2_mode_from_state.power(2)) @ E2_error
@@ -231,13 +226,14 @@ def error_flux_down(Φ, n_state, n_hier, n_hmodes, list_g, list_w, M2_mode_from_
231226
List of exponents for bath correlation functions.
232227
233228
7. M2_mode_from_state : np.array
234-
The L_m[s,s] value in the space of [mode,s].
229+
L_m[s,s] value in the space of [mode,s].
235230
236231
8. type : str
237232
Hierarchy or State basis ("H" or "S").
238233
239234
9. flag_gcorr : bool
240-
True if using linear absorption EOM False otherwise.
235+
True indicates the use of linear absorption EOM while False
236+
indicates otherwise.
241237
242238
10. F2_filter : np.array
243239
Filters out unwanted auxiliary connections in the space of [mode,k]
@@ -250,27 +246,23 @@ def error_flux_down(Φ, n_state, n_hier, n_hmodes, list_g, list_w, M2_mode_from_
250246
"""
251247
# Constants
252248
# ---------
253-
C2_phi = np.asarray(Φ).reshape([n_state, n_hier], order="F")
254-
E1_Lm = M2_mode_from_state @ (np.abs(C2_phi[:, 0]) ** 2) # This is the <L_m> term assuming psi_0 normalized
249+
C2_phi_squared = np.abs(np.asarray(Φ).reshape([n_state, n_hier], order="F")) **2
250+
E1_Lm = M2_mode_from_state @ C2_phi_squared[:, 0] # This is the <L_m> term assuming psi_0 normalized
255251
if flag_gcorr:
256252
E1_Lm /= 2
257253

258254
# Get flux factors
259255
# ----------------
260-
G2_bymode = np.tile(list_g,[1,n_hier]).reshape([n_hmodes, n_hier], order="F")
261-
W2_bymode = np.tile(list_w,[1,n_hier]).reshape([n_hmodes, n_hier], order="F")
256+
list_g_div_w = np.square(np.abs(list_g/list_w))
257+
G2_div_W2_bymode = list_g_div_w.reshape([n_hmodes,1], order="F")
262258
if type == "H":
263259
# Hierarchy Type Downward Flux
264260
# ============================
265261
D2_mode_from_state = np.zeros([n_hmodes,n_state])
266262
D2_mode_from_state[:,:] = M2_mode_from_state.toarray() - E1_Lm.reshape([len(E1_Lm),1])
267-
E2_flux_down_error = (
268-
np.real(
269-
(np.abs(G2_bymode / W2_bymode) ** 2)
270-
* ((np.abs(D2_mode_from_state) ** 2) @ (np.abs(C2_phi) ** 2))
271-
)
272-
/ hbar**2
273-
)
263+
D2_mode_from_state = np.abs(D2_mode_from_state) ** 2
264+
E2_flux_down_error = D2_mode_from_state @ C2_phi_squared
265+
E2_flux_down_error *= G2_div_W2_bymode / hbar**2
274266
if F2_filter is not None:
275267
E2_flux_down_error = F2_filter * E2_flux_down_error
276268

@@ -279,12 +271,13 @@ def error_flux_down(Φ, n_state, n_hier, n_hmodes, list_g, list_w, M2_mode_from_
279271
# ========================
280272
D2_state_from_mode = np.zeros([n_state,n_hmodes])
281273
D2_state_from_mode[:,:] = np.transpose(M2_mode_from_state).toarray() - E1_Lm
282-
E2_flux_down_error = np.abs(G2_bymode / W2_bymode)**2
274+
D2_state_from_mode = np.abs(D2_state_from_mode) ** 2
275+
E2_flux_down_error = G2_div_W2_bymode
283276
if F2_filter is not None:
284-
E2_flux_down_error *= F2_filter
277+
E2_flux_down_error = F2_filter * E2_flux_down_error
285278
E2_flux_down_error = (
286-
(np.abs(D2_state_from_mode) ** 2) @ (E2_flux_down_error)
287-
* (np.abs(C2_phi) ** 2)/hbar**2
279+
C2_phi_squared *
280+
(D2_state_from_mode @ E2_flux_down_error)/hbar**2
288281
)
289282
else:
290283
E2_flux_down_error = 0
@@ -323,7 +316,7 @@ def error_sflux_stable_state(Φ, n_state, n_hier, H2_sparse_hamiltonian,
323316
324317
Returns
325318
-------
326-
1. E1_state_flux : array
319+
1. E1_state_flux : np.array
327320
Error associated with flux out of each state in S_t.
328321
"""
329322
C2_phi = np.asarray(Φ).reshape([n_state, n_hier], order="F")[

0 commit comments

Comments
 (0)