-
Notifications
You must be signed in to change notification settings - Fork 670
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
helper script for upgrading from 0.10 to 0.11 (ten2eleven.py) #377
Comments
Instead of |
And more on using |
Add #389 ( |
So the camelCase/single_underscore is a nicety, but it's not going to break any scripts, and will issue a nice message. I think it's a lot more realistic for the script to read a script then give a line of line numbers and possible changes that need making, so something like:
But if someone can make it replace things in place then that's better. Either way we'll need a list of replacements. |
We definitely need the list of changes; I hope that @tylerjereddy 's page MDAnalysis 0.11.0 unifying release user guide will have this list. I think we can write fixes for ( |
Let me take a look. If my progress is too slow we can always re-assign to someone else. |
Sure, thanks. I would definitely try to use lib2to3. The docs on writing fixes seem a decent starting point. (And it actually sounds like a fun exercise to me.) Oliver Beckstein Am Aug 12, 2015 um 5:58 schrieb Tyler Reddy notifications@github.com:
|
I've produced a crude fixer (https://github.com/tylerjereddy/ten2eleven) that seems to work on a simple test conversion for
For the modules that now have different import paths, the fixers will be more complicated than that one! The example page Oli linked shows one way to deal with changing import statements (have to deal with |
@tylerjereddy – progress! Do you see a way that we can make a self-contained package so that users can pip install our upgrade script? I am thinking of making it a separate repo and package. It would be nice if we can get away with just copying & modifying the original |
Not sure about that just yet. I've added a new fixer for converting atomgroup methods to properties. That one was much harder, but seems to work properly. The best bet beyond the reference you provided is just to hack patterns together based on the fixers already in the standard library. Presumably we can deal with the packaging retroactively after various fixers are drafted. |
Likewise working for atomgroup count methods camelcase --> new properties. |
I think I would try out the suggestion to use the find_pattern.py script, preferrably on the older unit tests: Perhaps a good test is to use 0.10.0 unit tests, run, check failures, convert, run tests and hopefully end up with zero failures. |
Ok, it is now possible to run the current full suite of fixers on the command line like this:
or a specific fixer:
Now, as far as installing with pip and using on other systems, I may need a little help, but there are only three lines of code in We also have a new fixer for the import statement migrations to |
Fixes required because of #373 # These methods are now properties returning an object
AtomGroup.bond() -> AtomGroup.bond.value()
AtomGroup.angle() -> AtomGroup.angle.value()
AtomGroup.torsion() -> AtomGroup.dihedral.value()
AtomGroup.improper() -> AtomGroup.improper.value()
# Torsions now called dihedrals throughout package
# (class names)
Torsion -> Dihedral
Improper_Torsion -> ImproperDihedral
AtomGroup.torsions -> AtomGroup.dihedrals
Atom.torsions -> Atom.dihedrals
Universe.torsions -> Universe.dihedrals
# From MDAnalysis.lib.distances
calc_torsions() -> calc_dihedrals() |
I've added two new fixers to deal with some of those. More to come, hopefully, as time permits. |
These are the camelCase changes. Should just be simple find and replaces # from core.AtomGroup
totalMass -> total_mass
totalCharge -> total_charge
centerOfGeometry -> center_of_geometry
radiusOfGyration -> radius_of_gyration
shapeParameter -> shape_parameter
momentOfInertia -> moment_of_inertia
principalAxes -> principal_axes
packIntoBox -> pack_into_box
asUniverse -> as_universe
# from lib.distances
applyPBC -> apply_PBC EDIT 2015-8-30 (@orbeckst): fixed |
Ok, I wrote a new fixer to cover those. |
So, I've started testing
The substantial reduction in the number of errors relative to a modest increase in the number of failures is probably a decent sign for the first attempt. I see that there are a lot of issues with failures involving frame numbers and trajectory slicing, which is not surprising given the fact that the module doesn't handle this particular issue at the moment. Consider for example this test: self.trajectory.rewind()
assert_equal(self.ts.frame, 1, "rewinding to frame 1") One can easily imagine various similar cases where a user or a unit test would have any arbitrary frame number based assumption in their code. I'm skeptical that we could account for all of these cases, though I'd be happy to be proven wrong! Adjusting all instances of |
# Previously
ts = u.trajectory[i]
ts.frame == i + 1
# Now
ts = u.trajectory[i]
ts.frame == i So you might be able to look for |
Yes, that is what I was arguing in my comment--difficult to do this kind of conversion automatically for any arbitrary usage of a frame number. |
Hi @tylerjereddy , you're doing a terrific job here! I agree with what was said before: Do the safe conversions and point out potential problems as much as possible. Perhaps even by inserting comments into the code along the lines of # ten2eleven.py detected a possible incompatibility between this code and MDAnalysis >= 0.11.0
# NAME / DESCRIPTION / DATE
# Please manually review the following line (and remove these comments afterwards):
ts.frame == i + 1 I also opened a stub page on the wiki for migrating MDAnalysis code with ten2eleven.py. Can you please add a howto description there that tells users what to do and possibly what potential pitfalls are? Cheers! |
We also have to decide how to make
I vastly favour (2) but perhaps other people have different opinions, in particular @richardjgowers as release manager will have a deciding say in this. |
I favor 1. I think it's okay to continue providing the script as a convenience. Ultimately with an API break there will still be issues that require manual intervention, but the hope is that this eases the pain and codifies the changes that one needs to make. |
Is it possible to make it work as import MDAnalysis as mda
mda.ten2eleven('myfile.py') # spits out a file in same dir with fixes If I've understood this correctly, this is option 1 lite. |
@tylerjereddy I updated Oliver's table at the top with the changes to setters (singular to plural) |
@dotsdl Ok, I've added a new fixer that handles the following: ag.set_mass(new) --> ag.set_masses(new)
ag.set_charge(new) --> ag.set_charges(new)
ag.set_name(new) --> ag.set_names(new)
ag.set_type(new) --> ag.set_types(new)
ag.set_radius(new) --> ag.set_radii(new)
ag.set_bfactor(new) --> ag.set_bfactors(new)
ag.set_altloc(new) --> ag.set_altlocs(new)
ag.set_serial(new) --> ag.set_serials(new)
ag.set_resid(new) --> ag.set_resids(new)
ag.set_resname(new) --> ag.set_resnames(new)
ag.set_resnum(new) --> ag.set_resnums(new)
ag.set_segid(new) --> ag.set_segids(new) I see that you've added a sample conversion to the unifying release user guide, so that's good. |
I'm still investigating the other things discussed here. At the moment I'm focused on the fixer for the |
With the .frame fix, because we're only issuing a warning, it could just be a quick search for the string ".frame"? |
Option for Issue #377 Allows usage as: ``` import MDAnalysis as mda mda.ten2eleven('myscript.py') ```
I pushed a branch that takes @tylerjereddy 's tool and includes it in MDAnalysis. It then allows usage as: import MDAnalysis as mda
mda.ten2eleven('script.py') It's kind of @orbeckst 's option 1, except it isn't intrusively installing a script, and it will be present in the library for as long as we need it. If we put another change in 0.12.0, we'd just add another fixer and "ten2eleven" would actually work there too. Maybe "old2new" / "makemyscriptworkagainplease" or something might be a more future proof name. |
Sure about this? For me such a name would imply that I can use this kind of script for any future version upgrade (0.12 -> 0.13, 0.10 -> 1.00, ... ). Then the converting script needs to be updated and maintained for a long time for all different update combinations. I would figure that this is a huge amount of extra work that could be spend better otherwise. For a library like MDAnalysis deprecating old API's for 1-2 releases and then removing them sounds like a better approach in the long run. Offering a conversion script once for a huge (meaning a log of) API break is ok imho but as far as I understood the next versions of MDA are not planned to have huge API breaks. |
I think we can make it work for future changes (if any). I don't think different combinations will be a problem, things we change aren't getting changed again. It would be more annoying if we set this in stone and had to make a new script for 0.12 -> 0.13 (for example). I think the big features for 1.0 is vaguely looking like:
|
I'm still working to deal with @richardjgowers: is there a way we can eventually merge my repo in so I get a few commit credits to the dev branch (I rarely get to commit code changes these days it seems!). Obviously not that important as I've got my name on the fixer docstrings. |
I think I've got it working here: https://github.com/MDAnalysis/mdanalysis/commits/feature-merged-ten2eleven
(I used this: MDA was "A" ten2eleven was "B" http://blog.caplin.com/2013/09/18/merging-two-git-repositories/ Edit: |
If we are going down the module road then perhaps make a sub package migration:
At least keeps the name space cleaner. Oliver Beckstein Am Sep 3, 2015 um 7:21 schrieb Richard Gowers notifications@github.com:
|
Ok, I assume I can continue working on that feature branch (I've already pushed to it). I don't think I'm going to solve the #frame warning with indentation complexity:
class Dummy(object):
assert_almost_equal(ts.frame, 544) My fixers just notice You can see some brief discussion of this type of issue in the standard library |
I'm happy to leave |
Background
The 0.11.0 release will break the API in many places (see also the Release Notes for 0.11.0):
Timestep
and not of the trajectory readerMDAnalysis.lib
)AtomGroup
methods were changed to properties (and some were renamed)AtomGroup.numberOfAtoms()
(and similar methods for residues and segments) is now a propertyAtomGroup.n_atoms
; likewise,Universe.trajectory.numatoms
and.numframes
are now.n_atoms
and.n_frames
, respectively.AtomGroup.selectAtoms()
toAtomGroup.select_atoms()
(and same forUniverse.selectAtoms()
AtomGroup
s will changeAtomGroup.resids
(andsegids
) will return an array the size of theAtomGroup
; the old behavior will be obtained withAtomGroup.residues.resids
; likewiseResidueGroup.segids
will return an array the size of theResidueGroup
AtomGroup.set_<property>
are now pluralized to match the property names, where they were once singular. e.g.ag.set_resnum
is nowag.set_resnums
,ag.set_radius
is nowag.set_radii
.ten2eleven.py script
In order to ease the burden on users we would like to have a script
ten2eleven.py
that aids the user in the translation of Python code to the new syntax. That might not always be possible but some (tedious) changes could likely be automated.This should be somewhat similar to the py2to3 script.
Specifications
The script should take a python source file as input and write out an altered version of the file.
Automatically do substitutions and renamings like the following:
(We need a complete list of substitutions – please add to this issue report!)
It would also be desirable to flag pieces of code that should be manually inspected, e.g. anything related to
ts.frame
. Optionally, it should insert comment lines in places that should be inspected.It should keep a backup file of the original file and it should never overwrite the backup files.
The text was updated successfully, but these errors were encountered: