Unifies the shared attributes and methods on all mechanics _Methods subclasses and makes ABC class MethodBase public#29815
Unifies the shared attributes and methods on all mechanics _Methods subclasses and makes ABC class MethodBase public#29815moorepants wants to merge 38 commits into
Conversation
…nify the abstract base methods.
… be more uniform and added some new abstract base class attributes.
…gesMethod classes.
… LagrangesMethod along with tests.
…anesMethod and JointsMethod. Adds new nonholonomic_constraints parameter to KanesMethod.
… and u are available for all Methods.
|
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.15. Click here to see the pull request description that was parsed. |
|
Code quality is failing on some unrelated files: |
|
@sympy/mechanics @Peter230655 this PR is ready enough for review. I am prepping it to better work with new updates in PyDy so we can support all Method classes and I have a PR coming with the TMTMethod which will also use this ABC class. |
| P.potential_energy = m * g * P.point.pos_from(O).dot(N.y) | ||
| L = Lagrangian(N, P) | ||
| raises(ValueError, lambda: LagrangesMethod(L, [q], bodies=P)) | ||
| raises(ValueError, lambda: LagrangesMethod(L, [q], bodies=[P])) |
There was a problem hiding this comment.
I changed this because my internal adjustments caused it to fail on P not being an iterable before catching the incorrect q type.
🟠Hi, I am the SymPy bot. I've noticed that some of your commits add or delete files. Since this is sometimes done unintentionally, I wanted to alert you about it. This is an experimental feature of SymPy Bot. If you have any feedback on it, please comment at sympy/sympy-bot#75. The following commits add new files:
If these files were added/deleted on purpose, you can ignore this message. |
| # LagrangesMethod: (attr) -lam_coeffs | ||
| # JointsMethod: NA | ||
| # System: NA | ||
| def constraints_jacobian(self): |
There was a problem hiding this comment.
Should this be a method or attribute?
There was a problem hiding this comment.
I am going to change this to an attribute. For all methods, if there are constraints, you have to generate the coefficients of the speeds one way or the other. So, all pieces of this matrix will have been computed and made available when the equations are formed. So I think an attribute is suitable in that case.
There was a problem hiding this comment.
Done, now a property attribute.
There was a problem hiding this comment.
One minor argument for method would be the options to add keyword arguments in the future. I don't have a good example, but if you can immediately think of one for which you wouldn't create a separate method then it might be worth keeping it a method.
In general though, I agree that a property is nicer.
There was a problem hiding this comment.
It is similar to mass_matrix in that it is just the linear coefficients of a specific set of equations.
We have multiple mass_matrix attributes and I plan to add a mass_matrix_augmented or something like that soon. You could of course imagine having extract_mass_matrix(full=True, aug=True) instead. For this Jacobian an analogy would be extract_constraint_jacobian(all=True, holonomic=True, nonholonomic=True) or something like that. But having these as methods don't quite align with the existing design which is:
__init__: provide all necessary input and organize the info_form_eoms(): do the heavy lifting to compute the equations of motion and extract the pieces- .mass_matrix: available after _form_eoms() as a (mostly) precomputed attribute
There was a problem hiding this comment.
I just added the correct extraction of this matrix from precomputed matrices in KanesMethod.
tjstienstra
left a comment
There was a problem hiding this comment.
Nice to see the work to make it more generic and available. As I'm just reading it from my phone I've only left some minor comments/suggestions.
I've removed it in the settings. I think it was something I added when changing a bunch of settings to make the repo more secure but I don't think this particular setting really helps with that. |
|
Thanks @oscarbenjamin, I agree. |
…d in all methods.
|
@tjstienstra I think I'm satisfied with this. I mostly copy the well designed System attributes and replicate them in the other methods classes. Maybe the only significant changes otherwise are the new |
|
This test has timed out for me about 3 or 4 times in this PR: |
|
I marked the test as slow. |
|
@tjstienstra have I addressed your comments sufficiently? Do you expect more review or possibly think this is good to go in? |
References to other Issues or PRs
Fixes #21772
Brief description of what is fixed or changed
We introduced the
_Methodsabstract base class some time ago and it unified some attributes among the subclasses (KanesMethod, LagrangesMethod, JointsMethod, System) but there were more common attributes that are helpful for downstream consumers of the *Method classes. This PR makes the renamed_Methods->MethodBaseclass public and adds more useful attributes and methods:It also deprecates attributes (but not parameters) for
forcelistandbodylistin favor ofloadsandbodies.Other comments
TODO:
AI Generation Disclosure
No AI was used.
Release Notes
MethodBaseabstract base class (moved from private).MethodBase: frame, holonomic_constraints, nonholomic_constraints, velocity_constraints, acceleration_constraints, bodies, loads, constraints_jacobianforcelistandbodylistattributes fromKanesMethodandLagrangesMethod.Methodsclasses.