-
Notifications
You must be signed in to change notification settings - Fork 131
Type-hinting elastica #367
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
Conversation
sy-cui
left a comment
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.
Great work. Minor comments
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## update-0.3.3 #367 +/- ##
================================================
- Coverage 94.00% 93.96% -0.05%
================================================
Files 51 53 +2
Lines 3170 3295 +125
Branches 347 335 -12
================================================
+ Hits 2980 3096 +116
- Misses 140 152 +12
+ Partials 50 47 -3 ☔ View full report in Codecov by Sentry. |
sy-cui
left a comment
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.
LGTM
bhosale2
left a comment
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.
LGTM
Ali-7800
left a comment
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.
LGTM!
Type-hinting PyElastica
Resolve #255
Note
mypytest.type-hintingpython library is to enhance the readability and to reduce ambiguity, not to increase the codebase.mypycan easily become a cumbersome task. (https://www.reddit.com/r/Python/comments/10zdidm/why_type_hinting_sucks/)Anyor# type: ignore. (mostly numpy-broadcasting)Major Updates
mypytest is added as part of github-action (Makefile)protocoltrees for different components in PyElastica (described below)elastica/typing.pyfile. (described below)RodType,RigidBodyType, etc) used for each feature are now typed properly.Contactfeature: refactor system validation messages. (i.e.common_check_systems_identity,common_check_systems_difference,common_check_systems_validity)InteractionPlane: this operator was never possible to be used. Now, it is part offorcingfeature, and can be used like external forces. (apply_normal_force-->apply_forces)elastica/memory_block/memory_block_rod_base.py-->elastica/memory_block/utils.py..usingstatement. It was useful for some testing features, but it is an over-exploitation of dynamic types. Now, we only support passing exact object (RodType,RigidBodyType, etc)__final_systems._systemslist at finalize step needs to be discussed._systemsto__final_systems, Restart issue while loading a ring-rod #376 could be resolved.extend_stepper_interfaceandintegrateshould work same as before.extend_stepper_interface.integrateor custom stepping as above.Minor Changes
autoflake8toautoflake:autoflake8was made because the originalautoflakewas out of maintenance. Sinceautoflakeis back on maintenance,autoflake8is now deprecated. (Makefile)KnotTheoryCompatibleProtocolmoved intoCosseratRodProtocol.njitdecorators are skipped frommypycheck:numbaimplicitly modify the return type, which is hard to trace exactly. For readability, we keepnumpytype-hinting syntax.SelfContactExternalContactProtocols
Systems
flowchart LR direction RL subgraph Systems Protocol direction RL SLBD(SlenderBodyGeometryProtool) SymST["SymplecticSystem:\n• KinematicStates/Rates\n• DynamicStates/Rates"] style SymST text-align:left ExpST["ExplicitSystem:\n• States (Unused)"] style ExpST text-align:left P((position\nvelocity\nacceleration\n..)) --> SLBD subgraph StaticSystemType Surface Mesh end subgraph SystemType direction TB Rod RigidBody end SLBD --> SymST SystemType --> SymST SLBD --> ExpST SystemType --> ExpST end subgraph Timestepper Protocol direction TB StP["StepperProtocol\n• step(SystemCollection, time, dt)"] style StP text-align:left SymplecticStepperProtocol["SymplecticStepperProtocol\n• PositionVerlet"] style SymplecticStepperProtocol text-align:left ExpplicitStepperProtocol["ExpplicitStepperProtocol\n(Unused)"] end subgraph SystemCollection end SymST --> SystemCollection --> SymplecticStepperProtocol ExpST --> SystemCollection --> ExpplicitStepperProtocol StaticSystemType --> SystemCollectionSystem Collection (Build memory block)
flowchart LR Sys((Systems)) St((Stepper)) subgraph SystemCollectionType direction LR StSys["StaticSystem:\n• Surface\n• Mesh"] style StSys text-align:left DynSys["DynamicSystem:\n• Rod\n • CosseratRod\n• RigidBody\n • Sphere\n • Cylinder"] style DynSys text-align:left BlDynSys["BlockSystemType:\n• BlockCosseratRod\n• BlockRigidBody"] style BlDynSys text-align:left F{{"Feature Group (OperatorGroup):\n• Synchronize\n• Constrain values\n• Constrain rates\n• Callback"}} style F text-align:left end Sys --> StSys --> F Sys --> DynSys -->|Finalize| BlDynSys --> St DynSys --> F <--> StSystem Collection (Features)
flowchart LR Sys((Systems)) St((Stepper)) subgraph SystemCollectionType direction LR StSys["StaticSystem:\n• Surface\n• Mesh"] style StSys text-align:left DynSys["DynamicSystem:\n• Rod\n • CosseratRod\n• RigidBody\n • Sphere\n • Cylinder"] style DynSys text-align:left subgraph Feature direction LR Forcing -->|add_forcing_to| Synchronize Constraints -->|constrain| ConstrainValues Constraints -->|constrain| ConstrainRates Contact -->|detect_contact_between| Synchronize Connection -->|connect| Synchronize Damping -->|dampen| ConstrainRates Callback -->|collect_diagnosis| CallbackGroup end end Sys --> StSys --> Feature Sys --> DynSys DynSys --> Feature <--> StCommon Types Aliases
To use type aliases, developer should explicitly import using
from elastica.typing import ...syntax.typing.pyis not included in the top access tree (i.e. `elastica/init.py).SystemType: any generic object type for simulator (i.e.Rod,RigidBody, etc.)SystemCollectionType: object collection (i.e.BaseSystemCollectionor simulator that user defines)OperatorType: any genericstepused in timestepperSteppersOperationstype: collection ofOperatorTypeused to define specific timestepperTasks
elastica/rodTyping: Add typehinting forRodmodules #341rods#396elastica/timestepperTyping: timestepper module #372 @skim0119timestepperfix pytest and cleanup integration routine #373elastica/memory_block@armantekinalp Typing/memory block #384elastica/rigid_body@sy-cuielastica/meshelastica/module@skim0119modules#382elastica/systems@skim0119 Typing:systems#394contact#397contact#397Useful Links