Presentation is loading. Please wait.

Presentation is loading. Please wait.

Python for Scientific Computing

Similar presentations


Presentation on theme: "Python for Scientific Computing"— Presentation transcript:

1 Python for Scientific Computing
Wim R.M. Cardoen Center for High Performance Computing Fall 2010

2 Overview Python NumPy SciPy Matplotlib Python using C/C++ and Fortran
IPython 11/18/2018

3 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 11/18/2018

4 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,… 11/18/2018

5 11/18/2018

6 11/18/2018

7 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 11/18/2018

8 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,... 11/18/2018

9 11/18/2018

10 NumPy and Scipy require: Fast Linear Algebra routines:
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) 11/18/2018

11 SciPy collection of mathematical algorithms
contains several subpackages, e.g.: scipy.linalg scipy.fftpack scipy.optimize scipy.integrate scipy.interpolate scipy.special 11/18/2018

12 11/18/2018

13 11/18/2018

14 11/18/2018

15 11/18/2018

16 11/18/2018

17 11/18/2018

18 11/18/2018

19 11/18/2018

20 11/18/2018

21 MatplotLib produces publication quality 2D plots
supports Latex commands >= 0.99: inclusion of mplot3D (3D pics) Note: Mayavi: 3D Scientific Data Visualization 11/18/2018

22 11/18/2018

23 11/18/2018

24 11/18/2018

25 11/18/2018

26 11/18/2018

27 11/18/2018

28 Source: http://en.wikipedia.org/wiki/Delaunay_triangulation
11/18/2018

29 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” 11/18/2018

30 11/18/2018

31 11/18/2018

32 11/18/2018

33 11/18/2018

34 Ipython Enhanced interactive Python shell TAB-completion
explore objects using ? %run command debug python script output/input cache history Suppress output call system commands 11/18/2018

35 Additional packages MPI: MPI4PY SymPy: Symbolic Math
PIL: Python Imaging Library Mayavi Interactive 3D Visualization PyMol : 3D Molecular Viewer NLopt: Non-linear optimization 11/18/2018

36 Links: http://www.python.org/ http://numpy.scipy.org
11/18/2018


Download ppt "Python for Scientific Computing"

Similar presentations


Ads by Google