1 / 25

Animation and Advanced Python Features

Animation and Advanced Python Features. Phase I Python is the best thing ever!. 3D Visualization: Positions. particle configuration: “ pos ”. 3D Visualization: Scalars. particle configuration: “ pos ” velocity configuration: “ vel ” v elocity squared: “v2”

crystaln
Download Presentation

Animation and Advanced Python Features

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Animation and Advanced Python Features

  2. Phase I Python is the best thing ever!

  3. 3D Visualization: Positions particle configuration: “pos”

  4. 3D Visualization: Scalars particle configuration: “pos” velocity configuration: “vel” velocity squared: “v2” “v2” on “pos” is like a scalar field.

  5. 3D Visualization: Vectors particle configuration: “pos” velocity configuration: “vel” “vel” on “pos” is like a vector field.

  6. 3D Visualization: Vectors + Scalars Composition is easy. Import from existing scripts. Protect main loop with if __name__ == '__main__':

  7. 3D Animation: Positions all particle positions: “all_pos”

  8. 3D Animation: Positions + Velocities all particle positions: “all_pos” all particle velocities: “all_vel”

  9. Summary: 3D Visualization Snapshot Animation • Positions: • plot • scatter • Scalar field: • scatter with color • Vector field: • plot with quiver • Positions: • update Line3D artist • Scalar field: • update Path3DCollection artist • Vector field: • update Line3DCollection artist Don’t know how to update a particular artist? Use ArtistAnimation.

  10. 2D Visualization: Scalars spin lattice: “lat”

  11. Output to html spin lattice: “lat” We can upload your html videos to the course website under projects.

  12. Phase II Python is the worst thing ever!

  13. For loop: O(1000) times slower than fortran Autocorrelation function pyanswer, fanswer 15.694856 15.694856 pytime, ftime, py/f 0.039499 2.8e-05 1411 formula translation (fortran) was built with scientific computation in mind. Python implementation fortran implementation

  14. For loop: O(1000) times slower than fortran Distance table N=256 pytime, ftime, py/f 0.199822 0.000391 511 Python implementation fortran implementation

  15. Vectorize: O(10) times slower than fortran Autocorrelation function vecanswer, fanswer 15.694856 15.694856 vectime, ftime, vec/f 0.000368 2.6e-05 14 Vectorized Python implementation fortran implementation

  16. Vectorize: O(10) times slower than fortran Distance table N=256 vectime, ftime, vec/f 0.004272 0.000387 11 Vectorized Python implementation fortran implementation

  17. Vectorize: Q/ Where to put conditionals? Distance table Vectorized Python implementation fortran implementation

  18. Phase III Embracing Python

  19. Vectorize: Q/ Where to put conditionals? A/ Boolean Selector. Distance table Vectorized Python implementation fortran implementation

  20. Boolean selector: array of True and False of same shape

  21. List Comprehension: flatten for loop, remove append Cubic Posnatom=64,000 pytime, itertime, py/iter 0.0173 0.0062 2.8 For implementation Iter implementation Main loop

  22. np.meshgrid: np.array instead of lists Cubic Posnatom=64,000 pytime, mtime, py/m 0.0173 0.0011 15.7 For implementation meshgrid implementation Main loop

  23. np.einsum: general tensor contraction (Einstein notation) pos \cdotkvecs pytime, eintime, py/ein 0.005 0.0006 83

  24. f2py: compile fortran modules and import md.f90 makefile Type “make” to create the library file md.so Then import into Python

  25. Conclusion: Pick the right tool for the job • Python is a versatile language. It excels at: • Text parsing • Graphics • Composing available packaged functions • Interface with other codes • Python is not efficient at: • For loops • Memory management • Multiple Instruction Multiple Data (MIMD) Parallelization • In high-performance computing (HPC), consider Python as an interface • between backend performance code and the user. C, Fortran Data Structures Python Next step: analysis, graphics, ML, etc. f2py

More Related