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

ChainReader now subclasses BaseReader #3906

Merged
merged 5 commits into from May 26, 2023

Conversation

richardjgowers
Copy link
Member

@richardjgowers richardjgowers commented Nov 5, 2022

Fixes #4008
Fixes #3657

Changes made in this Pull Request:

ChainReader currently subclasses ProtoReader rather than ReaderBase, then attempts to implement many things regarding auxiliaries and transformations itself. I think it's getting many subtle things wrong with aux and transformations.

This PR makes ChainReader just another subclass of ReaderBase, which ultimately simplifies it.

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Few quick comments. :)

package/MDAnalysis/coordinates/base.py Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/base.py Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/base.py Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/base.py Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/chain.py Outdated Show resolved Hide resolved
package/MDAnalysis/coordinates/chain.py Show resolved Hide resolved
Comment on lines -652 to -655
#Overrides :meth:`~MDAnalysis.coordinates.base.ProtoReader.add_transformations`
#to avoid unintended behaviour where the coordinates of each frame are transformed
#multiple times when iterating over the trajectory.
#In this method, the trajectory is modified all at once and once only.
Copy link
Member

Choose a reason for hiding this comment

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

This comment suggests that there was a reason for applying transformations to individual trajectories instead of to the ChainReader itself. Did you look into this reason more closely?

Copy link
Member Author

Choose a reason for hiding this comment

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

@orbeckst
Copy link
Member

Is it realistic to have this in 2.5 or can we move it to 2.6?

@IAlibay IAlibay modified the milestones: 2.5.0, 2.6.0 May 24, 2023
@IAlibay
Copy link
Member

IAlibay commented May 24, 2023

Moving to a 2.6.0 target

@richardjgowers richardjgowers force-pushed the chainreader_subclasses_ReaderBase branch from 23ddffe to 66937df Compare May 25, 2023 10:57
@github-actions
Copy link

github-actions bot commented May 25, 2023

Linter Bot Results:

Hi @richardjgowers! Thanks for making this PR. We linted your code and found the following:

Some issues were found with the formatting of your code.

Code Location Outcome
main package ⚠️ Possible failure
testsuite ⚠️ Possible failure

Please have a look at the darker-main-code and darker-test-code steps here for more details: https://github.com/MDAnalysis/mdanalysis/actions/runs/5083982226/jobs/9135677279


Please note: The black linter is purely informational, you can safely ignore these outcomes if there are no flake8 failures!

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Patch coverage: 97.22% and project coverage change: -0.01 ⚠️

Comparison is base (5ab95ec) 93.60% compared to head (5aa250e) 93.60%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3906      +/-   ##
===========================================
- Coverage    93.60%   93.60%   -0.01%     
===========================================
  Files          192      192              
  Lines        25146    25141       -5     
  Branches      4058     4058              
===========================================
- Hits         23539    23532       -7     
- Misses        1089     1092       +3     
+ Partials       518      517       -1     
Impacted Files Coverage Δ
package/MDAnalysis/coordinates/base.py 94.58% <95.00%> (-0.11%) ⬇️
package/MDAnalysis/coordinates/chain.py 86.69% <100.00%> (-1.31%) ⬇️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@richardjgowers richardjgowers changed the title WIP bashing chain reader into shape ChainReader now subclasses BaseReader May 25, 2023
@@ -159,7 +158,7 @@ def check_allowed_filetypes(readers, allowed):
"supported for formats: {}".format(allowed))


class ChainReader(base.ProtoReader):
class ChainReader(base.ReaderBase):
Copy link
Member Author

Choose a reason for hiding this comment

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

this line change is what's happening in this PR. Previously by subclassing ProtoReader (which is a more distant ancestor) you had to also reimplement how transformations worked.

Instead ChainReader now subclasses ReaderBase (like a "normal" reader) and now only implements _read_next_timestep (like a "normal" Reader). This means that methods __next__, copy, add_transformations are all done by the base class.

tl;dr less code = less bugs

@richardjgowers
Copy link
Member Author

I'm not sure what the pylint failure means, it's not a line I've touched so I'm not going to try and understand it

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

Unfortunately pylint errors are not on diff - we'll need to fix it (or mute it) before merge.

@@ -614,7 +613,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
return False # do not suppress exceptions


class _Readermeta(type):
class _Readermeta(abc.ABCMeta):
Copy link
Member

Choose a reason for hiding this comment

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

re: pylint failure, do you not need to do a super.init call or something on line 625?

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly code like this is very much in the "if it ain't broke don't fix it" category for me

Copy link
Member

Choose a reason for hiding this comment

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

🤷🏽 then mute it I guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

So remove the linter?

Copy link
Member

Choose a reason for hiding this comment

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

no there's a # comment you can use - it's in the pylint docs iirc

@IAlibay IAlibay dismissed their stale review May 25, 2023 19:01

eh good enough for me

Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Great work, thanks @richardjgowers!

@richardjgowers richardjgowers merged commit 7e9c6f8 into develop May 26, 2023
23 of 25 checks passed
@richardjgowers richardjgowers deleted the chainreader_subclasses_ReaderBase branch May 26, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants