-
Notifications
You must be signed in to change notification settings - Fork 11
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
developing back end run methods #216
Conversation
cadeduckworth
commented
Sep 15, 2022
- separating functionality for use with _single_universe without iterating frames
- retaining functionality for use with _single_frame
* separating functionality for use with _single_universe without iterating frames * retaining functionality for use with _single_frame
* try/except pattern condensed to one run method * single run method implemented for _single_universe and _single_frame * functionality of original run method retained, while removing frame iteration for _single_universe usage * progress bar still active when using _single_universe, but no frame iteration occurs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address comments and add tests + CHANGELOG.
Update docs https://github.com/Becksteinlab/MDPOW/tree/develop/doc/sphinx/source/analysis : write how users are supposed to create EnsembleAnalysisClasses. Develop a simple example that could be used as a tutorial or example in the docs. This example can be the basis for a test. |
removed raise added docstrings to describe use of NotImplementedError responded with reason for removing _conclude_universe() next step: updating html documentation following successful testing
fixed expected indent block error removed raise removed _conclude_universe()
…ntedError for _single_frame() and _single_universe() so try/except pattern in run method works properly
…nto ensemble_run_update
Codecov Report
@@ Coverage Diff @@
## develop #216 +/- ##
===========================================
+ Coverage 78.90% 79.15% +0.25%
===========================================
Files 11 12 +1
Lines 1692 1713 +21
Branches 269 269
===========================================
+ Hits 1335 1356 +21
Misses 274 274
Partials 83 83
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
…n method, mdpow/tests/test_run_except.py
…achieve an ordered selection format
…h assert atom group order
… pytest locally * selection string format updated, final, correct, and consistent with original intended selection order * updated values calculated for circmean, circvar for use in test_results_recursive2() * changed order for arguments in assert_almost_equal() for use in test_results_recursive2() to align with format in numpy.testing docs, (actual, desired) for readability, does not affect accuracy or testing purposes
…ralAnalysis to test_dihedral.py
…' into ensemble_run_update test merge
|
||
def _single_frame(self): | ||
"""Calculate data from a single frame of trajectory | ||
|
||
Called on each frame for universes in the Ensemble. | ||
""" | ||
pass # pragma: no cover | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test that checks that this NotImplementedError is raised. If necessary by calling the method explicitly
def test_single_frame_raises_NotImplementedError():
...
ea = EnsembleAnalysis(...)
with pytest.raises(NotImplementedError):
ea._single_frame()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/Becksteinlab/MDPOW/blob/ensemble_run_update/mdpow/tests/test_dihedral.py
- file does not exist in pull request because it was deleted and moved to another pull request, so I just linked the source from the branch
- function is at end of module
- this is the explicit call of _single_universe() to test NotImplementedError is raised when not defined, but specifically moved for use in DihedralAnalysis as instructed
I am going to add explicit tests for raising NotImplementedError for _single_frame() and _single_universe() similar to pattern in your comment above, placed in test_ensemble.py, because test_run.py is for the partition coefficient calculation and test_ensemble.py deals with EnsembleAnalysis class where this run method that calls single_frame/uni is defined
- will be in this pull request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look into https://github.com/Becksteinlab/MDPOW/pull/216/files and you see the annotation by codecov that says that the line was not covered by tests.
Also check the codecov report in the checks and ultimately https://app.codecov.io/gh/Becksteinlab/MDPOW/pull/216
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mdpow/analysis/ensemble.py
Outdated
|
||
NotImplementedError will detect whether _single_universe or _single_frame | ||
should be implemented, based on which is defined in the EnsembleAnalysisClass. | ||
Only one of the two aforementioned functions should be defined for the respective | ||
analysis class. For verbose functionality, the analysis will currently show two | ||
iteration bars, where only one of which will actually be iterated, while the other | ||
will load to completion instantaneously, showing the system that is being worked on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These implementation details are developer documentation and do not need to be in run()
— users read these docs and will be confused. Put it into the part of the docs that talks about EnsembleAnalysis and how to write your own. Add a section to https://mdpow.readthedocs.io/en/latest/analysis/ensemble_analysis.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to create a Read the Docs account and link my GitHub account and repository to make these changes as indicated in the Sphinx documentation, or do I make the changes to the text files (i.e. ensemble_analysis.txt) and push the changes straight to GitHub?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need an account. The CI is already using RTD.
You only need to edit the docs here, namely ensemble_analysis.txt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI puts an updated view of the docs for the PR at https://mdpow--216.org.readthedocs.build/en/216/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I think everything merged and pushed correctly, and all tests passed. I do need to modify the docs slightly after following the link above, but will wait until your review to make all necessary documentation changes in one commit.
* test_ensemble.py ** test_ensemble_analysis_run() ** testing NotImplementedError is raised for: *** _single_frame() *** _single_universe() * passes locally
…ted-dihedral-analysis updating with changes for backend and testing from PR #216 ensemble_run_update
…r EnsembleAnalysis run methods to _single_frame and _single_universe, including new tests for NotImplementedError usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments for guidance on doc writing.
Also need tests.
CHANGES
Outdated
@@ -5,7 +5,26 @@ CHANGES for MDPOW | |||
Add summary of changes for each release. Use ISO 8061 dates. Reference | |||
GitHub issues numbers and PR numbers. | |||
|
|||
2022-12-07 0.8.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to 0.9.0 — we are making API changes so under semantic versioning this cannot be a patch release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
turn the date into 2022-??-?? — we don't know a release date yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact: add everything to the 0.8.1 entry below and change that 0.8.1 to 0.9.0
CHANGES
Outdated
* defined new test for updated ensemble.EnsembleAnalysis.run() method (#216): | ||
- new test, test_ensemble_analysis_run(), uses TestAnalysis class, | ||
is in test_ensemble.py | ||
- new test checks that NotImplementedError is raised when _single_frame | ||
or _single_universe are not defined, to implement correct method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove — CHANGES only lists what's important to users
CHANGES
Outdated
* source and html docs updated for EnsembleAnalysis | ||
to reflect changes and describe proper usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove — not relevant to users (this goes in the commit message)
CHANGES does not just collect commit messages, it summarizes changes at a high level with a view towards what a user of the code needs to know when they upgrade
systems. This allows for users to easily run analyses on MDPOW simulations. | ||
|
||
NotImplementedError will detect whether _single_universe or _single_frame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use sphinx reST markup
NotImplementedError will detect whether _single_universe or _single_frame | |
:exc:`NotImplementedError` will detect whether :meth:`_single_universe` or :meth:`_single_frame` |
For specific Python directives and roles see https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#the-python-domain (leave out a leading :py:
because that's the default for us). See also https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html for more on reST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To actually make the markup link to the doc, use something like
:meth:`~EnsembleAnalysis._single_universe`
The tilde will make it appear as only _single_universe
.
systems. This allows for users to easily run analyses on MDPOW simulations. | ||
|
||
NotImplementedError will detect whether _single_universe or _single_frame | ||
should be implemented, based on which is defined in the EnsembleAnalysisClass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark up
:class:`EnsembleAnalysis`
Note that this works (or should work) because you're currently documenting the mdpow.analysis.ensemble
module.
But if it doesn't work (i.e., you go to the HTML docs on RTD and clicking on EnsembleAnalysis
does NOT lead you to the full docs) then write it as
:class:`mdpow.analysis.ensemble.EnsembleAnalysis`
if you want to see the full "path" or
:class:`~mdpow.analysis.ensemble.EnsembleAnalysis`
if you only want the class name.
mdpow/analysis/ensemble.py
Outdated
Run on each universe in the ensemble during when | ||
self.run in called. | ||
|
||
NotImplementedError will detect whether _single_universe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark-up NotImplementedError
and _single_universe
and _single_frame
mdpow/analysis/ensemble.py
Outdated
|
||
NotImplementedError will detect whether _single_universe | ||
or _single_frame should be implemented, based on which | ||
is defined in the EnsembleAnalysisClass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is defined in the :class:`EnsembleAnalysis` class.
Only use the proper identifiers, don't make any up by adding "Class" to the end.
mdpow/analysis/ensemble.py
Outdated
NotImplementedError will detect whether _single_universe | ||
or _single_frame should be implemented, based on which | ||
is defined in the EnsembleAnalysisClass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark up etc
|
||
NotImplementedError will detect whether _single_universe | ||
or _single_frame should be implemented, based on which | ||
is defined in the EnsembleAnalysisClass. | ||
""" | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your tests do not check that the base class raises NotImplementedError.
mdpow/analysis/ensemble.py
Outdated
@@ -509,15 +517,8 @@ def run(self, start=None, stop=None, step=None): | |||
on each frame in the system. | |||
|
|||
First iterates through keys of ensemble, then runs _setup_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add markup
:meth:`_setup_system`
with pytest.raises(NotImplementedError) as excinfo: | ||
TestAnalysis._single_universe(self) | ||
assert excinfo.type == 'NotImplementedError' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orbeckst Can you provide more detail for the linked comment? This test might not have shown up with the recent commit, but if it did, can you elaborate on how it is not correctly testing the base class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov indicates that these lines were not tested. Codecov is not always right but it's something to look into carefully. Come up with a way to convince yourself (and me) that your tests really test the code that you think they do. Perhaps temporarily change the raise NotImplementError to ValueError and then your test should fail. Report back on what you did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed exception/error types and nothing changed. If the test and class definitions were nested correctly, pytest would have also picked up that
assert excinfo.type ==
should have been assert excinfo.type is
, so basically nothing was happening. There is a way to match directly to string but I did it incorrectly and this way is simpler.
I split the single test into two separate, one for _singe_frame
and one for _single_universe
. Each has its own TestAnalysis class definition, where it shows that the run method not being tested is defined, so the undefined run method is explicitly tested for raising NotImplementedError, for each case.
There is probably a way to consolidate the two tests back into one, but it is very clear what is being done this way. It still seems there is a simpler method. I will review again in the morning and make changes requested for documentation so this can be merged if everything is correct otherwise!
…ne test for _single_universe, tested with other error types to confirm coverage
Now coverage of the patch is 100%, that's good. Please ping me when you have addressed the remaining comments (docs, CHANGES, etc), @cadeduckworth . Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just minor comments.
CHANGES
Outdated
and use _single_frame OR _single_universe (#216) | ||
* _prepare_universe and _conclude_universe removed from | ||
EnsembleAnalysis.run() method, no longer needed (per comments, #199) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
mdpow/analysis/dihedral.py
Outdated
msg = '''Dihedral calculations require AtomGroups with | ||
only 4 atoms, %s selected''' % len(group) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformat this message so that it does not contain newline/space
msg = '''Dihedral calculations require AtomGroups with | |
only 4 atoms, %s selected''' % len(group) | |
msg = ("Dihedral calculations require AtomGroups with " | |
f"only 4 atoms, {len(group)} selected") |
And we can use f-strings.
mdpow/analysis/ensemble.py
Outdated
"""Calculations on a single :class:`MDAnalysis.Universe <MDAnalysis.core.groups.universe.Universe>` object. | ||
|
||
Run on each :class:`MDAnalysis.Universe <MDAnalysis.core.groups.universe.Universe>` | ||
in the :class:`~mdpow.analysis.ensemble.Ensemble` | ||
during when :meth:`run` in called. | ||
|
||
:exc:`NotImplementedError` will detect whether | ||
:meth:`~EnsembleAnalysis._single_universe` | ||
or :meth:`~EnsembleAnalysis._single_frame` | ||
should be implemented, based on which is defined | ||
in the :class:`~mdpow.analysis.ensemble.EnsembleAnalysis`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you format it so that it fits into 79 character wide lines?
The first line can be broken over multiple lines, there should just be an empty line to separate the summary/header line from the synopsis.
def test_single_universe(self): | ||
dh = self.Ens.select_atoms('name C4', 'name C17', 'name S2', 'name N3') | ||
with pytest.raises(NotImplementedError): | ||
DihedralAnalysis([dh])._single_universe() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is not strictly necessary but we can leave it in, as a check that the DihedralAnalysis does not do something weird to _single_universe()
.
Congratulations @cadeduckworth , PR is merged! 🚀 |