CENTER FOR HIGH PERFORMANCE COMPUTING Python for Scientific
36 Slides1.89 MB
CENTER FOR HIGH PERFORMANCE COMPUTING Python for Scientific Computing Wim R.M. Cardoen Center for High Performance Computing [email protected] Fall 2010
CENTER FOR HIGH PERFORMANCE COMPUTING Overview Python NumPy SciPy Matplotlib Python using C/C and Fortran IPython 01/09/2023 2
CENTER FOR HIGH PERFORMANCE COMPUTING Why Python? High-level interpreted language Very clear syntax easy-to-read Open source Platform independent Large number of libraries Binding to all standard GUI kits (TkInter, Qt, .) Powerful automated testing tools Easily integrated with C/C , and Fortran Actively used and extended by scientists 01/09/2023 3
CENTER FOR HIGH PERFORMANCE COMPUTING Python Language Clear syntax - easy to understand Indentation for blocks Use of namespace, exception handling Automatic doc.: doc strings & pydoc Dynamic typing Supports both procedural & OO approach Easy code testing Garbage collecting Functional programming, iterators, 01/09/2023 4
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 5
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 6
CENTER FOR HIGH PERFORMANCE COMPUTING Numpy:Why? The “trad.” Python list: can contain data of whatever type memory el. may have different sizes the list can grow & shrink dynamically passing through list by loops/iterators not very efficient for numerical calculations. We need something more efficient: python fast math NumPy 01/09/2023 7
CENTER FOR HIGH PERFORMANCE COMPUTING Multi-dimensional array object i.e. ndarray 1. homogeneous (all have the same type) 2. indexing/slicing 3. vectorization 4. broadcasting Derived objects such as masked arrays, matrices 1. matrix: derived from ndarray: always 2D attributes: T(transpose), H (hermit. conj.), I (invert) 2. masked arrays: missing or invalid entries Universal func.: operates on ndarrays in el-by-el fashion NumPy: basic toolkit for other packages e.g. SciPy,. 01/09/2023 8
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 9
CENTER FOR HIGH PERFORMANCE COMPUTING What’s under the hood? NumPy and Scipy require: Fast Linear Algebra routines: BLAS, LAPACK / ATLAS / GOTO-BLAS FFT Routines: routines for computing the DFT UMFPACK: routines for solving unsymmetric sparse linear systems Alternative: MKL (Intel) 01/09/2023 10
CENTER FOR HIGH PERFORMANCE COMPUTING SciPy collection of mathematical algorithms contains several subpackages, e.g.: scipy.linalg scipy.fftpack scipy.optimize scipy.integrate scipy.interpolate scipy.special 01/09/2023 11
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 12
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 13
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 14
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 15
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 16
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 17
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 18
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 19
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 20
CENTER FOR HIGH PERFORMANCE COMPUTING MatplotLib produces publication quality 2D plots supports Latex commands 0.99: inclusion of mplot3D (3D pics) Note: Mayavi: 3D Scientific Data Visualization http://code.enthought.com/projects/mayavi/ 01/09/2023 21
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 22
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 23
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 24
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 25
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 26
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 27
CENTER FOR HIGH PERFORMANCE COMPUTING Source: http://en.wikipedia.org/wiki/Delaunay triangulation 01/09/2023 28
CENTER FOR HIGH PERFORMANCE COMPUTING Interfacing C/C and Python Approaches for C/C : SWIG: Simplied Wrapper & Interface Generator Weave: inclusion C/C code in Python PyInline: inline other languages in Python Pyrex: python with C-data types Approaches for Fortan: f2py f2py -c --fcompiler gfortran -m essai essai.f90 import essai essai.trial(13) # subroutine trial(x) defined in “essai.f90” 01/09/2023 29
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 30
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 31
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 32
CENTER FOR HIGH PERFORMANCE COMPUTING 01/09/2023 33
CENTER FOR HIGH PERFORMANCE COMPUTING Ipython Enhanced interactive Python shell TAB-completion explore objects using ? %run command debug python script output/input cache history Suppress output call system commands 01/09/2023 34
CENTER FOR HIGH PERFORMANCE COMPUTING Additional packages MPI: MPI4PY SymPy: Symbolic Math PIL: Python Imaging Library Mayavi Interactive 3D Visualization PyMol : 3D Molecular Viewer NLopt: Non-linear optimization 01/09/2023 35
CENTER FOR HIGH PERFORMANCE COMPUTING Links: http://www.python.org/ http://numpy.scipy.org http://www.scipy.org http://matplotlib.sourceforge.net http://ipython.scipy.org 01/09/2023 36