Skip to content

Commit

Permalink
Merge pull request #12 from jeremyleung521/westpa-2.0-restruct-thresh…
Browse files Browse the repository at this point in the history
…olds2

WESTPA2-threshold2 fix
  • Loading branch information
atbogetti authored May 18, 2022
2 parents 612c74b + 5b3e91c commit 3c4d6da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/westpa/core/sim_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ def report_bin_statistics(self, bins, save_summary=False):
self.rc.pstatus('norm = {:g}, error in norm = {:g} ({:.2g}*epsilon)'.format(norm, (norm - 1), (norm - 1) / EPS))
self.rc.pflush()

if min_seg_prob < 1e-100:
log.warning(
'\n Minimum segment weight is < 1e-100 and might not be physically relevant. Please reconsider your progress coordinate or binning scheme.'
)

if save_summary:
iter_summary = self.data_manager.get_iter_summary()
iter_summary['n_particles'] = len(segments)
Expand Down
22 changes: 14 additions & 8 deletions src/westpa/core/we_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ def _split_by_weight(self, bin, target_count, ideal_weight, number_of_groups):
# print(i.weight)
# print(self.smallest_allowed_weight)
if all(new_segment.weight < self.smallest_allowed_weight for new_segment in new_segments_list):
# print("instance of threshold break (bw)")
# print("instance of threshold break (bw)")
bin.add(segment)
else:
# print("no threshold break (bw)")
# print("no threshold break (bw)")
bin.update(new_segments_list)

# KFW CHECK BACK for new_segment in new_segments_list:
Expand Down Expand Up @@ -586,6 +586,7 @@ def _adjust_count(self, bin, groups, target_count):

# split
while len(bin) < threshold_target_count:
last_bin = len(bin)
for i in sorted_groups:
log.debug('adjusting counts by splitting')
# always split the highest probability walker into two
Expand All @@ -594,15 +595,15 @@ def _adjust_count(self, bin, groups, target_count):
bin.remove(segments[-1])
i.remove(segments[-1])
new_segments_list = self._split_walker(segments[-1], 2, bin)
# print(new_segments_list)
# for j in new_segments_list:
# print(j.weight)
# print(self.smallest_allowed_weight)
# print(j.weight)
if all(new_segment.weight < self.smallest_allowed_weight for new_segment in new_segments_list):
# print("instance of threshold break (ac)")
# print("instance of threshold break (ac)")
bin.add(segments[-1])
i.add(segments[-1])
else:
# print("no threshold break (ac)")
# print("no threshold break (ac)")
i.update(new_segments_list)
bin.update(new_segments_list)

Expand All @@ -614,13 +615,16 @@ def _adjust_count(self, bin, groups, target_count):

if len(bin) == target_count:
break
elif i == sorted_groups[-1]:
elif i == sorted_groups[-1] and last_bin == len(
bin
): # If the last "for" iteration didn't change anything, soft-break.
threshold_target_count = len(bin)

threshold_target_count = target_count

# merge
while len(bin) > threshold_target_count:
last_bin = len(bin)
sorted_groups.reverse()
# Adjust to go from lowest weight group to highest to merge
for i in sorted_groups:
Expand Down Expand Up @@ -649,7 +653,9 @@ def _adjust_count(self, bin, groups, target_count):
# in bash, "find . -name \*.py | xargs fgrep -n '_merge_walkers'"
if len(bin) == target_count:
break
elif i == sorted_groups[-1]:
elif i == sorted_groups[-1] and last_bin == len(
bin
): # If the last "for" iteration didn't change anything, soft-break.
threshold_target_count = len(bin)

def _check_pre(self):
Expand Down

0 comments on commit 3c4d6da

Please sign in to comment.