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

Implementation of Girsanov reweighting in deeptime MSM estimator #290

Merged
merged 22 commits into from
Oct 23, 2024

Conversation

anyschaefer
Copy link
Contributor

We extended the MSM estimator class, such that the transition counts are reweighted according to the reweighting factor trajectory.

Joana-Lysiane Schäfer, Bettina G. Keller, Implementation of Girsanov reweighting in OpenMM and Deeptime

We demonstrated the correct functioning and error-free applicability of the newly implemented
functions using both a low-dimensional test system and a molecular system.
The corresponding reference "Implementation of Girsanov reweighting in OpenMM and Deeptime" is currently under review and will be publicly available shortly.
The required input files and setup for the evaluation of a reweighted Markov state model are available at reweightingtools

@clonker
Copy link
Member

clonker commented Apr 30, 2024

Super cool, thank you for your contribution! Do you think it is possible to add a sanity unit test to the new estimator? The failing tests are due to a tab/space mismatch. Let me know if you need support, I am happy to integrate this.

@@ -213,7 +214,83 @@ def effective_count_matrix(dtrajs, lag, average='row', mact=1.0, n_jobs=None, ca
return sparse.effective_counts.effective_count_matrix(dtrajs, lag, average=average, mact=mact, n_jobs=n_jobs,
callback=callback)

def girsanov_reweighted_count_matrix(dtraj, lag, reweighting_factors,
sliding=True, sparse_return=True, nstates=None):
r"""Generate a Girsanov reweighted count matrix from given microstate trajectory. :footcite:`donati2017girsanov`
Copy link
Member

Choose a reason for hiding this comment

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

This will need an entry in references.bib to render correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we will add the reference as soon as it is published

Copy link

codecov bot commented May 6, 2024

Codecov Report

Attention: Patch coverage is 98.63014% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.07%. Comparing base (f4ae6e4) to head (1da295d).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ime/markov/tools/estimation/sparse/count_matrix.py 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #290      +/-   ##
==========================================
+ Coverage   92.03%   92.07%   +0.04%     
==========================================
  Files         142      143       +1     
  Lines       11657    11725      +68     
==========================================
+ Hits        10728    10796      +68     
  Misses        929      929              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anyschaefer
Copy link
Contributor Author

Super cool, thank you for your contribution! Do you think it is possible to add a sanity unit test to the new estimator? The failing tests are due to a tab/space mismatch. Let me know if you need support, I am happy to integrate this.

Thank you, that's great! We added a sanity unit test for the new estimator and fixed the tap/space mismatch. When trying to run the tests with pytest tests/ or reinstall the modified package we get import errors due to different ..._bindings.cpython-311-x86_64-linux-gnu.so files. The problem concerns modules of deeptime that we have not modified, how to deal with this problem?

@clonker
Copy link
Member

clonker commented May 7, 2024

The bindings are part of the c++ module of deeptime, If all dependencies are available, you can set up a development environment with it using python setup.py develop. Otherwise you can just use pip install . and then use that module for testing. There are some tests failing right now in CI due to another part of deeptime, I have to fix that :) but generally, if your test runs through then that's fine for me.

@clonker
Copy link
Member

clonker commented May 7, 2024

If you update your branch against the current main, the errors unrelated to this PR should be gone. :)

Copy link
Member

@clonker clonker left a comment

Choose a reason for hiding this comment

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

The formatting is a bit off for some of the changes (like no spaces around equal signs) and you have a few problems in your doctests.

deeptime/markov/tools/estimation/sparse/count_matrix.py Outdated Show resolved Hide resolved
factors = np.concatenate(factors)
data = factors
else:
raise NotImplementedError('An input format other than a tuple (g,M) for the reweighting factors is not implemented.')
Copy link
Member

Choose a reason for hiding this comment

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

could be covered by tests

deeptime/util/types.py Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

perhaps you can parametrize the tests to cover dense and sparse representations

@anyschaefer
Copy link
Contributor Author

If you update your branch against the current main, the errors unrelated to this PR should be gone. :)

Unfortunately, I still have the same problem. Not only the tests in 'tests/' also the doctests gives me only message pointing to the import error.
My way to setup is: create anaconda environment with python 3.11; clone my updated fork or the original deeptime repository; in the deeptime folder with 'pip install .' install everything and with 'pytest tests/' or 'pytest --doctest-modules deeptime' I still get the import errors for the cpython extension files (e.g. 'deeptime.numeric._numeric_bindings') even if I can find them in the respective directories.
Do you know where the error can come from?

@clonker
Copy link
Member

clonker commented May 8, 2024

this is probably due to the way python discovers modules: first in the local directory. as there is a deeptime directory in your working dir, it'll find that one but without the compiled sources which are in your site packages :)

one way around this is using nox: pip install nox and then you just call nox inside the deeptime directory. that should take care of things. alternatively, just cd tests and then run

python -m pytest --doctest-modules --durations=20 --pyargs .

@clonker
Copy link
Member

clonker commented Jul 9, 2024

ah damn, i didn't implement numpy 2.0 support yet, hence the failures. i'll push a fix soon, then ci should be green (plusminus the test you're adding).

@clonker
Copy link
Member

clonker commented Jul 16, 2024

for all i am concerned this can be squashed and merged now. i still think the testing could be a bit more thorough (as indicated by coverage) but i'll leave that up to you if you want to provide it.


>>> C_sliding.toarray()
array([[1., 2.],
[0., 1.]])
Copy link
Member

Choose a reason for hiding this comment

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

Sorry to bug about this again, but the test expectation does not match the result here, please do fix :)

Copy link
Member

Choose a reason for hiding this comment

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

Are you able to reproduce the test failure locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh no, of course I'll fix it! unfortunately not until September.

@clonker
Copy link
Member

clonker commented Oct 22, 2024

Welcome back! It looks good to me now and the test failure is unrelated, so if you think it is ready, I will hit the merge button.

@clonker clonker merged commit 5f85b3e into deeptime-ml:main Oct 23, 2024
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants