Presentation is loading. Please wait.

Presentation is loading. Please wait.

Animation and Advanced Python Features

Similar presentations


Presentation on theme: "Animation and Advanced Python Features"— Presentation transcript:

1 Animation and Advanced Python Features

2 Python is the best thing ever!
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 Python is the worst thing ever!
Phase II Python is the worst thing ever!

13 For loop: O(1000) times slower than fortran
Autocorrelation function pyanswer, fanswer pytime, ftime, py/f e 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 Python implementation fortran implementation

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

16 Vectorize: O(10) times slower than fortran
Distance table N=256 vectime, ftime, vec/f 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 Pos natom=64,000 pytime, itertime, py/iter For implementation Iter implementation Main loop

22 meshgrid implementation
np.meshgrid: np.array instead of lists Cubic Pos natom=64,000 pytime, mtime, py/m For implementation meshgrid implementation Main loop

23 np.einsum: general tensor contraction (Einstein notation)
pos \cdot kvecs pytime, eintime, py/ein

24 f2py: compile fortran modules and import
makefile md.f90 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


Download ppt "Animation and Advanced Python Features"

Similar presentations


Ads by Google