Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bar_with_pessimistic_uncertainty convergence error #1344

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises an exception without the fix. Didn't launch a CI job as it is an unambigious failure

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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

df_and_err_from_u_kln handles the behavior correctly: https://github.com/proteneer/timemachine/blob/master/timemachine/fe/bar.py#L136-L139


_, _, 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