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

developing back end run methods #216

Merged
merged 31 commits into from
Dec 12, 2022
Merged

developing back end run methods #216

merged 31 commits into from
Dec 12, 2022

Conversation

cadeduckworth
Copy link
Contributor

  • 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
@cadeduckworth cadeduckworth marked this pull request as draft September 15, 2022 17:30
* 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
Copy link
Member

@orbeckst orbeckst left a 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.

mdpow/analysis/ensemble.py Outdated Show resolved Hide resolved
mdpow/analysis/ensemble.py Show resolved Hide resolved
@orbeckst
Copy link
Member

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.

cadeduckworth and others added 9 commits October 21, 2022 20:21
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
@cadeduckworth cadeduckworth marked this pull request as ready for review October 28, 2022 23:26
@codecov
Copy link

codecov bot commented Oct 28, 2022

Codecov Report

Merging #216 (8870e39) into develop (cc104f0) will increase coverage by 0.25%.
The diff coverage is 100.00%.

@@             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              
Impacted Files Coverage Δ
mdpow/analysis/dihedral.py 100.00% <100.00%> (ø)
mdpow/analysis/ensemble.py 97.18% <100.00%> (+0.02%) ⬆️
mdpow/__init__.py 100.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

… 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

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
Copy link
Member

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()

Copy link
Contributor Author

@cadeduckworth cadeduckworth Nov 17, 2022

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

Copy link
Member

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

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

There are some edits that are now being fixed in PR #218 so don't make the changes here and wait for #218 to be merged.

See other inline comments but overall looking good!

EDIT: add entry to CHANGES

Comment on lines 514 to 520

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.
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Member

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/

Copy link
Contributor Author

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.

mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
mdpow/tests/test_dihedral.py Outdated Show resolved Hide resolved
* test_ensemble.py
** test_ensemble_analysis_run()
** testing NotImplementedError is raised for:
*** _single_frame()
*** _single_universe()
* passes locally
cadeduckworth added a commit that referenced this pull request Nov 17, 2022
…ted-dihedral-analysis

updating with changes for backend and testing from PR #216 ensemble_run_update
cadeduckworth added a commit that referenced this pull request Nov 17, 2022
Copy link
Member

@orbeckst orbeckst left a 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
Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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
Comment on lines 21 to 25
* 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
Copy link
Member

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
Comment on lines 26 to 27
* source and html docs updated for EnsembleAnalysis
to reflect changes and describe proper usage
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Use sphinx reST markup

Suggested change
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.

Copy link
Member

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.
Copy link
Member

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.

Run on each universe in the ensemble during when
self.run in called.

NotImplementedError will detect whether _single_universe
Copy link
Member

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


NotImplementedError will detect whether _single_universe
or _single_frame should be implemented, based on which
is defined in the EnsembleAnalysisClass.
Copy link
Member

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.

Comment on lines 483 to 485
NotImplementedError will detect whether _single_universe
or _single_frame should be implemented, based on which
is defined in the EnsembleAnalysisClass.
Copy link
Member

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
Copy link
Member

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.

@@ -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
Copy link
Member

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'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#216 #216 (comment)

@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?

Copy link
Member

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.

Copy link
Contributor Author

@cadeduckworth cadeduckworth Dec 8, 2022

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
@orbeckst
Copy link
Member

orbeckst commented Dec 8, 2022

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!

Copy link
Member

@orbeckst orbeckst left a 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)

Copy link
Member

Choose a reason for hiding this comment

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

remove empty line

Suggested change

Comment on lines 81 to 82
msg = '''Dihedral calculations require AtomGroups with
only 4 atoms, %s selected''' % len(group)
Copy link
Member

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

Suggested change
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.

Comment on lines 467 to 477
"""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`.
Copy link
Member

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.

Comment on lines +96 to +100
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()

Copy link
Member

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().

@orbeckst orbeckst merged commit e395ac7 into develop Dec 12, 2022
@orbeckst orbeckst deleted the ensemble_run_update branch December 12, 2022 20:33
@orbeckst
Copy link
Member

Congratulations @cadeduckworth , PR is merged! 🚀

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