Skip to content

Commit

Permalink
Fixes bar_with_pessimistic_uncertainty convergence error (#1344)
Browse files Browse the repository at this point in the history
* A bug introduced in #1324
  • Loading branch information
badisa authored Jul 16, 2024
1 parent 8e2f36e commit ab3def7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 5 additions & 0 deletions tests/test_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ def test_df_from_u_kln_does_not_raise_on_incomplete_convergence():
assert np.isfinite(df)
assert np.isnan(ddf) # returns NaN for uncertainty on incomplete convergence

bootstrap_df, bootstrap_ddf = bar_with_pessimistic_uncertainty(u_kln, maximum_iterations=1)
np.testing.assert_equal(df, bootstrap_df)
# With the bootstrapping, we will compute a finite error
assert np.isfinite(bootstrap_ddf)


def test_pair_overlap_from_ukln():
# identical distributions
Expand Down
8 changes: 2 additions & 6 deletions timemachine/fe/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,8 @@ def bootstrap_bar(
* TODO[deboggle] -- upgrade from pymbar3 to pymbar4 and remove this
* TODO[performance] -- multiprocessing, if needed?
"""
u_kn, N_k = ukln_to_ukn(u_kln)
mbar = pymbar.MBAR(u_kn, N_k, maximum_iterations=maximum_iterations)

df, ddf = mbar.getFreeEnergyDifferences()
full_bar_result = df[0, 1]
full_bar_err = ddf[0, 1]
full_bar_result, full_bar_err = df_and_err_from_u_kln(u_kln, maximum_iterations=maximum_iterations)

_, _, n = u_kln.shape

Expand All @@ -197,7 +193,7 @@ def bootstrap_bar(
u_kln_sample = rng.choice(u_kln, size=(n,), replace=True, axis=2)
bar_result = df_from_u_kln(
u_kln_sample,
initial_f_k=mbar.f_k, # warm start
initial_f_k=np.array([0.0, full_bar_result]), # warm start
maximum_iterations=maximum_iterations,
)
bootstrap_samples.append(bar_result)
Expand Down

0 comments on commit ab3def7

Please sign in to comment.