Introduction to Python

Size: px
Start display at page:

Download "Introduction to Python"

Transcription

1 Introduction to Python Part 3: Advanced Topics Michael Kraus Max-Planck-Institut für Plasmaphysik, Garching 1. December 2011

2 Advanced Topics calling and embedding C and Fortran code: Weave: inline C/C++ code, translation of Python code to C++ Cython: extension of the Python language providing static typed functions and variables, generating efficient C code for fast computations ctypes: call functions in C libraries f2py: wrap Fortran code parallelisation: threading multiprocessing parallel python (PP) mpi4py GUI programming with PyQt and PySide symbolic computing with Sage

3 Calling and Embedding C and Fortran Code in Python Python is very fast when writing code, but not necessarily so fast when executing code (especially for numerical applications) implement time-consuming parts of your program in C/C++/Fortran example: solving the 2D Laplace equation by an iterative finite difference scheme (500x500 grid, 100 iterations) Type of Solution Time Taken (secs) Python Numpy 29.3 Weave (Blitz) 9.5 Weave (Inline) 4.3 f2py 2.9 Cython 2.5 Matlab 29.0 Pure C [Numbers from the Beginners Guide to Using Python for Performance Computing:

4 Sample Problem: Laplace Equation solving the 2D Laplace equation using an iterative finite difference scheme (four point averaging, Gauss-Seidel or Gauss-Jordan) solve for some unknown function u(x, y) such that 2 u = 0 with some boundary condition specified discretise the domain into an (n x n y ) grid of points the function u can be represented as a two-dimensional array u(n x, n y ) the values of u along the sides of the domain are given (and stay fixed) the solution can be obtained by iterating in the following manner: for i in range (1, nx -1): for j in range (1, ny -1): u[i,j] = ( (u[i -1, j] + u[i+1, j ])* dy **2 + \ (u[i, j -1] + u[i, j +1])* dx **2 \ ) / (2.0*( dx **2 + dy **2))

5 Sample Problem: Laplace Equation in NumPy the for loop of the Laplace solver can be readily expressed by a much simpler NumPy expression: u[1: -1, 1: -1] = ( (u[0: -2, 1: -1] + u[2:, 1: -1])* dy **2 + \ (u[1: -1, 0: -2] + u[1: -1, 2:])* dx **2 \ ) / (2.0*( dx **2 + dy **2)) the advantage of this expression is that it is completely done in C speedup of a factor of 50x over the pure Python loop (another factor of 5 or so if you link NumPy with Intel MKL or ATLAS) (slight) drawback: this expression uses temporary arrays during one iteration, the computed values at an already computed location will not be used in the original for loop, once the value of u[1,1] is computed, the next value for u[1,2] will use the newly computed u[1,1] and not the old one since the NumPy expression uses temporary arrays internally, only the old value of u[1,1] will be used the algorithm will still converge but in twice as much time reduction of the benefit by a factor of 2

6 Weave Weave is a subpackage of SciPy and has two modes of operation weave.blitz accelerates Python code by translating it to C++ code which it compiles into a Python module weave.inline allows to embed C/C++ code directly into Python code mainly used to speed up calculations on arrays fast/efficient: directly operates on NumPy arrays (no temporary copies) the first time you run a blitz or inline function, it gets compiled into a Python module, the next time it is called, it will run immediately References:

7 Sample Problem: Laplace Equation in weave.blitz to use weave.blitz, the accelerated code has to be put into a string which is passed to the weave.blitz function: from scipy import weave expr = """ u[1: -1, 1: -1] = ( (u[0: -2, 1: -1] + u[2:, 1: -1])* dy **2 + \ (u[1: -1, 0: -2] + u[1: -1, 2:])* dx **2 \ ) / (2.0*( dx **2 + dy **2)) """ weave. blitz (expr, check_size =0) the first time the code is called, weave.blitz converts the NumPy expression into C++ code, builds a Python module, and invokes it for the array expressions, weave.blitz uses Blitz++ speedup of x over the Python loop weave.blitz does not use temporary arrays for the computation (the computed values are re-used immediately) and therefore behaves more like the original for loop

8 Sample Problem: Laplace Equation in weave.inline in weave.inline the C/C++ code has to be put into a string which is passed to the weave.inline function, together with the variables used: from scipy. weave import converters, inline code = """ for ( int i =1; i<nx -1; ++i) { for ( int j =1; j<ny -1; ++j) { u(i,j) = ( (u(i -1,j) + u(i+1,j ))* dy*dy + (u(i,j -1) + u(i,j +1))* dx*dx ) / (2.0*( dx*dx + dy*dy )); } } """ inline (code, [ u, dx, dy, nx, ny ], type_ converters = converters. blitz, compiler = gcc ) here we use Blitz++ arrays (speedup x over the Python loop) with pointer arithmetic, you can get an additional speedup of a factor 2 weave.inline does not use temporary arrays for the computation

9 Cython Cython is a programming language based on Python provides extra syntax allowing for static type declarations (remember: Python is generally dynamically typed) the source code gets translated into optimised C/C++ code and compiled as Python extension modules Cython can compile (most) regular Python code but the optional static type declarations usually achieve major speed improvements allows for very fast program execution and tight integration with external C libraries combines the benefits of Python with the speed of C References:

10 Cython: Compilation Cython code must, unlike Python, be compiled: a.pyx source file is compiled by Cython to a.c file, containing the code of a Python extension module the.c file is compiled by a C compiler to a.so (shared object library) file which can be imported directly into a Python session several ways to build Cython code: use pyximport, importing Cython.pyx files as if they were.py files (using distutils to compile and build the background) write a distutils setup.py run the cython command-line utility manually to produce the.c file from the.pyx file, then manually compile the.c file into a shared object library use the Sage notebook which allows Cython code inline

11 Cython: Compilation imagine a simple hello world script: hello.pyx def say_hello_to ( name ): print (" Hello %s!" % name ) implicit compilation using pyximport: >>> import pyximport >>> pyximport. install () >>> import hello >>> hello. say_hello_to (" Mike ") Hello Mike! this allows to automatically run Cython on every.pyx that Python is trying to import use this for simple Cython builds where no extra C libraries and no special building setup is needed

12 Cython: Compilation the following could be a corresponding setup.py script: setup.py from distutils. core import setup from distutils. extension import Extension from Cython. Distutils import build_ ext ext_modules = [ Extension (" hello ", [" hello. pyx " ])] setup ( name = Hello World App, cmdclass = { build_ext : build_ext }, ext_ modules = ext_ modules ) you can specify additional build settings (include dirs, linker flags,...) ext_modules = [ Extension (" hello ", [" hello. pyx "], include_dirs = [ numpy. get_include ()], extra_compile_args = [ - fopenmp ], extra_link_args = [ - fopenmp ] )]

13 Cython: Compilation the script can be called with: > python setup. py build_ ext -- inplace after compilation, Cython modules can be imported like every other Python module: >>> import hello >>> hello. say_hello_to (" Mike ") Hello Mike!

14 Cython: Static Types Cython can compile normal Python code without changes (with a few exceptions of some as-yet unsupported language features), but for performance critical code, it is often helpful to add static type declarations they allow Cython to step out of the dynamic nature of the Python code and generate simpler and faster C code (sometimes faster by orders of magnitude) however, type declarations can make the source code more verbose and thus less readable it is discouraged to use them without good reason, i.e. only in performance critical sections where they really make the code substantially faster

15 Cython: Static Types consider the following pure Python code: def def f(x): return x**2 -x integrate_f (a, b, N): s = 0 dx = (b-a)/n for i in range (N): s += f(a+i*dx) return s * dx simply compiling this in Cython gives a 35% speedup adding some static types can make a much larger difference

16 Cython: Static Types with additional type declarations, the former example might look like: def f( double x): return x**2 -x def integrate_ f ( double a, double b, int N): cdef int i cdef double s, dx s = 0 dx = (b-a)/n for i in range (N): s += f(a+i*dx) return s * dx typing the iterator variable i with C semantics, tells Cython to compile the for-loop to pure C code typing a, s and dx is important as they are involved in arithmetic within the for-loop this results in a 4x speedup over the pure Python version

17 Cython: Static Types Python function calls can be expensive: one needs to convert to and from Python objects to do the call in our example, the argument is assumed to be a C double both inside f() and in the call to it, yet a Python float object must be constructed around the argument in order to pass it Cython provides the cdef keyword for declaring a C-style function: cdef double f( double x): return x**2 -x speedup: 150x over pure Python but: now the function is no longer available from Python-space, as Python wouldn t know how to call it using the cpdef keyword instead, a Python wrapper is created as well

18 Cython: Static Types and NumPy Arrays you can use NumPy from Cython exactly the same as in regular Python, but by doing so you are loosing potentially high speedups Cython has support for fast access to NumPy arrays: import numpy as np cimport numpy as np def update (np. ndarray [ double, ndim =2] f): cdef unsigned int i, j cdef np. ndarray [ double, ndim =2] h = \ np. zeros ([ xmax, ymax ], dtype = DTYPE ) for i in range (0, f. shape [0]): for j in range (0, f. shape [1]):... typing the contents of ndarray by specifying the datatype and the number of dimensions enables access to the data buffer directly at C speed, otherwise the [] operator still uses full Python operations

19 Sample Problem: Laplace Equation in Cython a Cython implementation of the Laplace solver using static types: laplace cython.pyx cimport numpy as np def laplace_cython (np. ndarray [ double, ndim =2] u, double dx, double dy ): cdef unsigned int i, j for i in xrange (1, u. shape [0] -1): for j in xrange (1, u. shape [1] -1): u[i,j] = ( (u[i+1, j] + u[i -1, j]) * dy **2 + (u[i, j +1] + u[i, j -1]) * dx **2 ) / (2.0*( dx **2 + dy **2)) looks very similar to the original pure Python implementation except for the additional type-declarations using cimport numpy, you have to add the NumPy includes to setup.py: ext_modules = [ Extension (" laplace_cython ", [" laplace_cython. pyx "], include_ dirs = [ numpy. get_ include ()])]

20 Cython: External Libraries Cython provides declarations for many functions from the standard C library, e.g. for the C math library: cython cmath.py from libc. math cimport sin cdef double f( double x): return sin (x*x) calling C s sin() functions is substantially faster than Python s math.sin() function as there s no wrapping of arguments, etc. the math library is not linked by default in addition to cimporting the declarations, you must configure your build system to link against the shared library m, e.g. in setup.py: ext_modules = [ Extension (" cython_cmath ", [" cython_cmath. pyx "], libraries =["m" ])]

21 Cython: External Libraries if you want to access C code for which Cython does not provide a ready to use declaration, you must declare them yourself: cdef extern from " math. h": double sin ( double ) this declares the sin() function in a way that makes it available to Cython code and instructs Cython to generate C code that includes the math.h header file the C compiler will see the original declaration in math.h at compile time, but Cython does not parse math.h and thus requires a separate definition you can declare and call into any C library as long as the module that Cython generates is properly linked against the shared or static library

22 Cython: Faster Code if you re confident you ve done everything right, there are a few directives that can further speed up your code boundscheck=false disables array boundary checks wraparound=false disables negative indexing of NumPy arrays there are several ways of setting these compiler directives globally, with a special header comment at the top of the file: # cython : boundscheck = False # cython : wraparound = False locally, as function decorators or in a with statement: cimport boundscheck ( False ) def update (np. ndarray [ double, ndim =2] f):... with cython. boundscheck ( True ):...

23 Cython: Parallelisation Cython supports native parallelism via OpenMP (more backends might be supported in the future) by default, Python s Global Interpreter Lock (GIL) prevents that several threads use the Python interpreter simultaneously to use this kind of parallelism, the GIL must be released parallel loops can be created by using prange([start], stop[, step], nogil=false, schedule=none) OpenMP automatically starts a thread pool and distributes the work according to the schedule used static: approx. equally sized chunks, one for each thread dynamic:iterations are distributed as threads request them, chunk size of 1 guided: iterations are distributed as threads request them, the chunk size is proportional to the number of unassigned iterations divided by the number of threads, decreasing to 1 auto: the decision regarding scheduling is delegated to the compiler or runtime system

24 Cython: Parallelisation thread-locality and reductions are automatically inferred for variables example with reduction: the values from the thread-local copies of the variable will be reduced with the operator and assigned to the original variable after the loop from cython. parallel import prange cdef int i cdef int sum = 0 for i in prange (n, nogil = True ): sum += i example with a shared NumPy array: from cython. parallel import prange def func (np. ndarray [ double ] x, double alpha ): cdef unsigned int i for i in prange (x. shape [0], nogil = True ): x[ i] = alpha * x[ i]

25 Sample Problem: Laplace Equation in Parallel Cython laplace cython parallel.pyx # cython : boundscheck ( False ) from cython. parallel import prange cimport numpy as np def laplace_cython_parallel (np. ndarray [ double, ndim =2] u,\ double dx, double dy ): cdef unsigned int i, j for i in prange (1, u. shape [0] -1, nogil = True ): for j in xrange (1, u. shape [1] -1): u[i,j] = ( (u[i+1, j] + u[i -1, j]) * dy*dy + (u[i, j +1] + u[i, j -1]) * dx*dx ) / (2.0*( dx **2 + dy **2)) you have to add the NumPy includes and OpenMP flags to setup.py: ext_ modules = [ Extension (" laplace_ cython_ parallel ", [" laplace_cython_parallel. pyx "], include_dirs = [ numpy. get_include ()], extra_compile_args = [ - fopenmp ], extra_link_args = [ - fopenmp ])]

26 ctypes the ctypes module of the Python Standard Library provides C compatible data types and allows calling functions in shared libraries ctypes can be used to wrap these libraries in pure Python to use ctypes to access C code you need to know some details about the underlying C library (names, calling arguments, types, etc.), but you do not have to write C extension wrapper code or compile anything with a C compiler (like in Cython) simple example: libc.rand() >>> import ctypes >>> libc = ctypes. CDLL ("/ usr / lib / libc.so") >>> libc. rand () ctypes provides functionality to take care of correct datatype handling, automatic type casting, passing values by reference, pointers, etc. Reference:

27 f2py f2py is a NumPy module that lets you easily call Fortran functions from Python the f2py command builds a shared library and creates Python wrapper code that makes the Fortran routine look like a native Python module: > f2py -c laplace. f -m laplace_ fortran in Python you only have to import it like every other Python module: >>> import laplace_ fortran >>> laplace_ fortran. laplace (...) when passing arrays, f2py automatically takes care of the right layout, i.e. row-major in Python and C vs. column-major in Fortran References:

28 f2py in the Fortran routine you have to include some additional directives telling f2py the intent of the parameters: subroutine laplace (u, n, m, dx, dy) real *8, dimension (1:n,1: m) :: u real *8 :: dx, dy integer :: n, m, i, j! f2py intent (in, out ) :: u! f2py intent (in) :: dx,dy! f2py intent ( hide ) :: n,m end... subroutine the dimensions of the array are passed implicitly by Python: >>> dx = dy = 0.1 >>> u = np. zeros ( (100,100) ) >>> u [0] = 1. >>> laplace_fortran. laplace (u, dx, dy)

29 Sample Problem: Laplace Solver with f2py laplace.f90 subroutine laplace (u, nx, ny, dx, dy) real *8, dimension (1: nx,1: ny) :: u real *8 :: dx, dy integer :: nx, ny, i, j! f2py intent (in, out ) :: u! f2py intent (in) :: dx, dy! f2py intent ( hide ) :: nx, ny do i=2, nx -1 do j=2, ny -1 u(i,j) = ( (u(i -1,j) + u(i+1,j ))* dy*dy + (u(i,j -1) + u(i,j +1))* dx*dx enddo enddo ) / (2.0*( dx*dx + dy*dy )); end subroutine

30 Performance Python Benchmark Reloaded 2D Laplace Solver: 500x500 grid, 100 iterations Type of Solution Time GNU (ms) Time Intel (ms) Numpy Weave (Blitz) 286 n/a Weave (Inline) 291 n/a Cython Cython (fast) Cython (2 threads) Cython (4 threads) ctypes f2py Pure C Pure Fortran (Benchmarked on an Intel Xeon 2.83GHz)

31 Parallel Programming Python includes a multithreading and a multiprocessing package multithreading is seriously limited by the Global Interpreter Lock, which allows only one thread to be interacting with the interpreter at a time this restricts Python programs to run on a single processor regardless of how many CPU cores you have and how many threads you create multiprocessing allows spawning subprocesses which run on different cores but are completely independent entities communication is only possible by message passing which makes parallelisation an effort that is probably not justified by the gain (we re talking about Python! your code won t run on 1000s of cores) however, you can compile NumPy and SciPy with threaded libraries like ATLAS or MKL use Cython s prange for very simple parallelisation of loops via OpenMP use Parallel Python (PP) use mpi4py (again, message passing, but quite common in C and Fortran)

32 Parallel Python (PP) the PP module provides a mechanism for parallel execution of python code on systems with multiple cores and clusters connected via network simple to implement job-based parallelisation technique internally PP uses processes and Inter Process Communication (IPC) to organise parallel computations all the details and complexity are hidden from you and your application, it just submits jobs and retrieves their results very simple way to write parallel Python applications cross-platform portability (Linux, MacOSX, Windows), interoperability, dynamic load-balancing software written with PP works in parallel also on many computers connected via local network or internet even if the run different operating systems (it s pure Python!) Reference:

33 Parallel Python (PP) import the pp module: import pp start pp execution server with the number of workers set to the number of processors in the system: job_ server = pp. Server () submit all the tasks for parallel execution: f1 = job_ server. submit ( func1, args1, depfuncs1, modules1 ) f2 = job_ server. submit ( func1, args2, depfuncs1, modules1 ) f3 = job_ server. submit ( func2, args3, depfuncs2, modules2 )... retrieve the results as needed: r1 = f1 () r2 = f2 () r3 = f3 ()...

34 Parallel Python (PP) import import math pp def sum_primes ( nstart, nfinish ): sum = 0 for n in xrange ( nstart, nfinish +1): if isprime ( n): # checks if n is a prime sum += n return sum nprimes = job_server = pp. Server () ncpus = job_server. get_ncpus () np_cpu, np_add = divmod ( nprimes, ncpus ) ranges = [ (i* np_cpu +1, (i +1)* np_cpu ) for i in range (0, ncpus )] ranges [ ncpus -1] = ( ranges [ ncpus -1][0], ranges [ ncpus -1][1]+ np_add ) sum = 0 jobs = [( job_server. submit ( sum_primes, input, ( isprime,), (" math ",))) for input in ranges ] for job in jobs : sum += job ()

35 Parallel Python (PP) the task object, returned by a submit call, has an argument finished which indicates the status of the task and can be used to check if it has been completed: task = job_server. submit (f1, (a,b,c))... if task. finished : print (" The task is done!") else print (" Still working on it... ") you can perform an action at the time of completion of each individual task by setting the callback argument of the submit method: sum = 0 def add_sum (n): sum += n... task = job_server. submit ( sum_primes, ( nstart, nend ), callback = add_sum )

36 mpi4py MPI for Python provides full-featured bindings of the Message Passing Interface standard for the Python programming language allows any Python program to exploit multiple processors point-to-point (sends, receives) and collective (broadcasts, scatters, gathers) communications of any picklable Python object (e.g. ndarray) (pickling: conversion of a Python object hierarchy into a byte stream) provides an object oriented interface which closely follows the MPI-2 C++ bindings and works with most of the MPI implementations any user of the standard C/C++ MPI bindings should be able to use this module without the need of learning a new interface mpi4py also allows wrapping of C/C++ and Fortran code that uses MPI with Cython and f2py Reference:

37 GUI Programming lots of options: Tkinter: Python s default GUI toolkit included in the Standard Library wxpython: Python wrapper for wxwidgets PyGTK: Python wrapper for GTK PyQt and PySide: Python wrappers for Qt (not just a GUI library!) Traits and TraitsUI: development model that comes with automatically created user interfaces

38 PyQt and PySide PyQt and PySide are Python bindings for the Qt application framework run on all platforms supported by Qt (Linux, MacOSX, Windows) the interface of both modules is almost identical (PySide is slightly cleaner, see wiki/differences_between_pyside_and_pyqt) main difference: License (PyQt: GPL and commercial, PySide: LGPL) and PySide is supported by Nokia (who develops Qt) generate Python code from Qt Designer add new GUI controls written in Python to Qt Designer Documentation:

39 PySide simple example: only shows a small window pyside simple example.py import sys from PySide import QtGui def main (): app = QtGui. QApplication ( sys. argv ) w = QtGui. QWidget () w. resize (250, 150) w. move (300, 300) w. setwindowtitle ( Simple Example ) w. show () sys. exit ( app. exec_ ()) if name == main : main () we can do a lot with this window: resize it, maximise it, minimise it

40 PySide necessary imports: basic GUI widgets are located in the QtGui module from PySide import QtGui every PySide application must create an application object, the sys.argv parameter is a list of arguments from the command line: app = QtGui. QApplication ( sys. argv ) QtGui.QWidget is the base class of all user interface objects in PySide, the default constructor has no parent and creates a window: w = QtGui. QWidget () resize the window, move it around on the screen, and set a title: w. resize (250, 150) w. move (300, 300) w. setwindowtitle ( Simple Example )

41 PySide make the window visible: w. show () finally, enter the main loop of the application: sys. exit ( app. exec_ ()) the event handling starts from this point: the main loop receives events from the window system and dispatches them to the application widgets the main loop ends, if we call the exit() method or the main widget is destroyed (e.g. by clicking the little x on top of the window) the sys.exit() method ensures a clean exit

42 PySide you could also set an application icon: w. setwindowicon ( QtGui. QIcon ( my_app. png )) the QtGui.QIcon is initialised by providing it with a (path and) filename you can move and resize at once: w. setgeometry (300, 300, 250, 150) the first two parameters are the x and y positions of the window the latter two parameters are the width and height of the window

43 PySide this was a procedural example, but in PySide your re writing objects: pyside object example.py class Example ( QtGui. QWidget ): def init ( self ): super ( Example, self ). init () self. initui () def initui ( self ): self. setgeometry (300, 300, 250, 150) self. setwindowtitle ( PySide Object Example ) self. setwindowicon ( QtGui. QIcon ( my_app. png )) self. show () def main (): app = QtGui. QApplication ( sys. argv ) ex = Example () sys. exit ( app. exec_ ()) if name == main : main ()

44 PySide create a new class called Example that inherits from QtGui.QWidget: class Example ( QtGui. QWidget ): we must call two constructors: for the Example class and for the inherited class: def init ( self ): super ( Example, self ). init () the super() method returns the parent object of the Example class the constructor method is always called init () in Python the creation of the GUI is delegated to the initui() method: self. initui ()

45 PySide our Example class inherits lots of methods from the QtGui.QWidget class: self. setgeometry (300, 300, 250, 150) self. setwindowtitle ( PySide Object Example ) self. setwindowicon ( QtGui. QIcon ( my_app. png ))

46 PySide add a button and some tooltips: QtGui. QToolTip. setfont ( QtGui. QFont ( SansSerif, 10)) self. settooltip ( This is a <b> QWidget </b> widget ) btn = QtGui. QPushButton ( Button, self ) btn. settooltip ( This is a <b> QPushButton </b> widget ) btn. resize ( btn. sizehint ()) btn. move (50, 50)

47 PySide QtGui provides static methods to set default properties like fonts: QtGui. QToolTip. setfont ( QtGui. QFont ( SansSerif, 10)) set a tooltip for our Example class: self. settooltip ( This is a <b> QWidget </b> widget ) create a button which is placed within our Example class main widget: btn = QtGui. QPushButton ( Button, self ) set a tooltip for the button, resize it and move it somewhere: btn. settooltip ( This is a <b> QPushButton </b> widget ) btn. resize ( btn. sizehint ()) btn. move (50, 50) GUI elements can give a size hint corresponding to their content (e.g. button text, picture size)

48 PySide bring the button to life by connecting it to a slot: btn = QtGui. QPushButton ( Quit, self ) btn. clicked. connect ( QtCore. QCoreApplication. instance (). quit ) btn. resize ( qbtn. sizehint ()) btn. move (50, 50) now we can close our window programatically (not only by clicking x) you have to import QtCore for this to work: from PyQt4 import QtCore the event processing system in PySide uses the signal & slot mechanism if we click on the button, the signal clicked is emitted it can be connected to any Qt slot or any Python callable QtCore.QCoreApplication is created with the QtGui.QApplication it contains the main event loop and processes and dispatches all events it s instance() method returns its current instance the quit() method terminates the application

49 PySide add a QtGui.QLineEdit where the user can enter some text that is displayed in a popup window when he clicks the OK button: def initui ( self ):... self. inputle = QtGui. QLineEdit ( self ) self. inputle. resize (120,20) self. inputle. move (10,50) okbtn = QtGui. QPushButton ( OK, self ) okbtn. clicked. connect ( self. showmessage ) okbtn. resize ( okbtn. sizehint ()) okbtn. move (150, 50)... we also have to define a function that serves as slot: def showmessage ( self ): QtGui. QMessageBox. information (self, " Information ", self. inputle. text ())

50 PySide the QtGui.QLineEdit has to be an element of the class so that the slot can access it self. inputle = QtGui. QLineEdit ( self ) the OK button is connected to the method showmessage: okbtn. clicked. connect ( self. showmessage ) showmessage reads the content of the QtGui.QLineEdit via it s text() method and creates a QtGui.QMessageBox: QtGui. QMessageBox. information (self, " Information ", self. inputle. text ()) the title of the QtGui.QMessageBox is set to "Information" the message it displays is the content of the QtGui.QLineEdit

51 PySide this just gives you a taste of how PySide (and PyQt) works there are quite a few other important basic topics: menus, toolbars, statusbar layout: absolute positioning vs. layout classes signals & slots: emit signals yourself event models catch events and ask to ignore or accept them ( Do you really want to quit? ) dialogs: input, file, print,... widgets: combo box, check box, toggle button, slider, progress bar,... custom widgets threading building UIs with the Designer the aforementioned tutorial is a good place to start:

52 Symbolic Computating with Sage Sage is an open-source mathematics software system based on Python combines nearly 100 packages under a unified interface includes a huge range of mathematics, including basic algebra, calculus, elementary to very advanced number theory, cryptography, numerical computation, commutative algebra, group theory, combinatorics, graph theory, exact linear algebra and much more the user interface is a notebook in a web browser or the command line it s a viable, free alternative to Maple, Mathematica, and MATLAB References: Sage: Beginner s Guide (2011) Craig Finch

Introduction to Python

Introduction to Python Introduction to Python Part 3: Advanced Topics Michael Kraus (michael.kraus@ipp.mpg.de) Max-Planck-Institut für Plasmaphysik, Garching 7. March 2012 Some Advanced Topics calling and embedding C and Fortran

More information

About 1. Chapter 1: Getting started with pyqt5 2. Remarks 2. Examples 2. Installation or Setup 2. Hello World Example 6. Adding an application icon 8

About 1. Chapter 1: Getting started with pyqt5 2. Remarks 2. Examples 2. Installation or Setup 2. Hello World Example 6. Adding an application icon 8 pyqt5 #pyqt5 Table of Contents About 1 Chapter 1: Getting started with pyqt5 2 Remarks 2 Examples 2 Installation or Setup 2 Hello World Example 6 Adding an application icon 8 Showing a tooltip 10 Package

More information

Scientific Computing with Python and CUDA

Scientific Computing with Python and CUDA Scientific Computing with Python and CUDA Stefan Reiterer High Performance Computing Seminar, January 17 2011 Stefan Reiterer () Scientific Computing with Python and CUDA HPC Seminar 1 / 55 Inhalt 1 A

More information

Interfacing With Other Programming Languages Using Cython

Interfacing With Other Programming Languages Using Cython Lab 19 Interfacing With Other Programming Languages Using Cython Lab Objective: Learn to interface with object files using Cython. This lab should be worked through on a machine that has already been configured

More information

LECTURE 20. Optimizing Python

LECTURE 20. Optimizing Python LECTURE 20 Optimizing Python THE NEED FOR SPEED By now, hopefully I ve shown that Python is an extremely versatile language that supports quick and easy development. However, a lot of the nice features

More information

LECTURE 17. GUI Programming

LECTURE 17. GUI Programming LECTURE 17 GUI Programming GUI PROGRAMMING IN PYTHON There are a number of platform-independent GUI toolkits available including: Tkinter wrapper around Tcl/Tk. PyQt Python bindings for the Qt C++ framework.

More information

An introduction to scientific programming with. Session 5: Extreme Python

An introduction to scientific programming with. Session 5: Extreme Python An introduction to scientific programming with Session 5: Extreme Python PyTables For creating, storing and analysing datasets from simple, small tables to complex, huge datasets standard HDF5 file format

More information

Speeding up Python using Cython

Speeding up Python using Cython Speeding up Python using Cython Rolf Boomgaarden Thiemo Gries Florian Letsch Universität Hamburg November 28th, 2013 What is Cython? Compiler, compiles Python-like code to C-code Code is still executed

More information

Mixed language programming with NumPy arrays

Mixed language programming with NumPy arrays Mixed language programming with NumPy arrays Simon Funke 1,2 Ola Skavhaug 3 Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Center for Biomedical Computing, Simula Research Laboratory 1 Dept. of Informatics,

More information

Object-Oriented Programming

Object-Oriented Programming iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 33 Overview 1 2 3 4 5 6 2 / 33 I Qt is a cross-platform application and UI framework in C++. Using Qt, one can write GUI applications once and deploy

More information

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions

Running Cython. overview hello world with Cython. experimental setup adding type declarations cdef functions & calling external functions Running Cython 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions 3 Using Cython

More information

Python Scripting for Computational Science

Python Scripting for Computational Science Hans Petter Langtangen Python Scripting for Computational Science Third Edition With 62 Figures 43 Springer Table of Contents 1 Introduction... 1 1.1 Scripting versus Traditional Programming... 1 1.1.1

More information

High Performance Computing with Python

High Performance Computing with Python High Performance Computing with Python Pawel Pomorski SHARCNET University of Waterloo ppomorsk@sharcnet.ca April 29,2015 Outline Speeding up Python code with NumPy Speeding up Python code with Cython Using

More information

Python Scripting for Computational Science

Python Scripting for Computational Science Hans Petter Langtangen Python Scripting for Computational Science Third Edition With 62 Figures Sprin ger Table of Contents 1 Introduction 1 1.1 Scripting versus Traditional Programming 1 1.1.1 Why Scripting

More information

Python GUIs. $ conda install pyqt

Python GUIs. $ conda install pyqt PyQT GUIs 1 / 18 Python GUIs Python wasn t originally desined for GUI programming In the interest of "including batteries" the tkinter was included in the Python standard library tkinter is a Python wrapper

More information

Advanced and Parallel Python

Advanced and Parallel Python Advanced and Parallel Python December 1st, 2016 http://tinyurl.com/cq-advanced-python-20161201 By: Bart Oldeman and Pier-Luc St-Onge 1 Financial Partners 2 Setup for the workshop 1. Get a user ID and password

More information

Graphical User Interfaces

Graphical User Interfaces Chapter 14 Graphical User Interfaces So far, we have developed programs that interact with the user through the command line, where the user has to call a Python program by typing its name and adding the

More information

Implementation of Parallelization

Implementation of Parallelization Implementation of Parallelization OpenMP, PThreads and MPI Jascha Schewtschenko Institute of Cosmology and Gravitation, University of Portsmouth May 9, 2018 JAS (ICG, Portsmouth) Implementation of Parallelization

More information

OpenACC Course. Office Hour #2 Q&A

OpenACC Course. Office Hour #2 Q&A OpenACC Course Office Hour #2 Q&A Q1: How many threads does each GPU core have? A: GPU cores execute arithmetic instructions. Each core can execute one single precision floating point instruction per cycle

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Robot Vision Systems Lecture 8: Python wrappers in OpenCV

Robot Vision Systems Lecture 8: Python wrappers in OpenCV Robot Vision Systems Lecture 8: Python wrappers in OpenCV Michael Felsberg michael.felsberg@liu.se Why Python Wrappers Assume a small library based on OpenCV Python interface for Testing Distribution Prototyping

More information

LECTURE 18 GUI Programming Part 2

LECTURE 18 GUI Programming Part 2 LECTURE 18 GUI Programming Part 2 BASIC PYQT Last lecture, we created a basic PyQt4 application which had a few buttons and a menu bar. import sys from PyQt4 import QtGui, QtCore class Example(QtGui.QMainWindow):

More information

PySide. overview. Marc Poinot (ONERA/DSNA)

PySide. overview. Marc Poinot (ONERA/DSNA) PySide overview Marc Poinot (ONERA/DSNA) Outline Quite short but practical overview Qt Toolkit overview Model/View PySide pyqt4 vs PySide Designer & Cython Widget bindings Class reuse ONERA/PySide-2/8

More information

GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill. Faculty of Informatics, Masaryk University.

GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill. Faculty of Informatics, Masaryk University. GUI in C++ PV264 Advanced Programming in C++ Nikola Beneš Jan Mrázek Vladimír Štill Faculty of Informatics, Masaryk University Spring 2017 PV264: GUI in C++ Spring 2017 1 / 23 Organisation Lectures this

More information

Speeding up Python. Antonio Gómez-Iglesias April 17th, 2015

Speeding up Python. Antonio Gómez-Iglesias April 17th, 2015 Speeding up Python Antonio Gómez-Iglesias agomez@tacc.utexas.edu April 17th, 2015 Why Python is nice, easy, development is fast However, Python is slow The bottlenecks can be rewritten: SWIG Boost.Python

More information

multiprocessing HPC Python R. Todd Evans January 23, 2015

multiprocessing HPC Python R. Todd Evans January 23, 2015 multiprocessing HPC Python R. Todd Evans rtevans@tacc.utexas.edu January 23, 2015 What is Multiprocessing Process-based parallelism Not threading! Threads are light-weight execution units within a process

More information

Day 15: Science Code in Python

Day 15: Science Code in Python Day 15: Science Code in Python 1 Turn In Homework 2 Homework Review 3 Science Code in Python? 4 Custom Code vs. Off-the-Shelf Trade-offs Costs (your time vs. your $$$) Your time (coding vs. learning) Control

More information

High Performance Computing with Python

High Performance Computing with Python High Performance Computing with Python Pawel Pomorski SHARCNET University of Waterloo ppomorsk@sharcnet.ca March 15,2017 Outline Speeding up Python code with NumPy Speeding up Python code with Cython Speeding

More information

Qt + Maemo development

Qt + Maemo development ES3 Lecture 11 Qt + Maemo development Maemo Nokia's Linux based platform Almost entirely open source Nokia N770, N800, N810, N900 only models Only N900 has 3G/phone capability N900 has relatively fast

More information

An Introduction to F2Py

An Introduction to F2Py An Introduction to Jules Kouatchou, Hamid Oloso and Mike Rilee Jules.Kouatchou@nasa.gov, Amidu.O.Oloso@nasa.gov and Michael.Rilee@nasa.gov Goddard Space Flight Center Software System Support Office Code

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Graphical User Interfaces Robert Rand University of Pennsylvania December 03, 2015 Robert Rand (University of Pennsylvania) CIS 192 December 03, 2015 1 / 21 Outline 1 Performance

More information

Message-Passing and MPI Programming

Message-Passing and MPI Programming Message-Passing and MPI Programming 2.1 Transfer Procedures Datatypes and Collectives N.M. Maclaren Computing Service nmm1@cam.ac.uk ext. 34761 July 2010 These are the procedures that actually transfer

More information

An introduction to scientific programming with. Session 5: Extreme Python

An introduction to scientific programming with. Session 5: Extreme Python An introduction to scientific programming with Session 5: Extreme Python Managing your environment Efficiently handling large datasets Optimising your code Squeezing out extra speed Writing robust code

More information

CS 4300 Computer Graphics

CS 4300 Computer Graphics CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 8 September 22, 2011 GUIs GUIs in modern operating systems cross-platform GUI frameworks common GUI widgets event-driven programming Model-View-Controller

More information

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3 6 Iterative Solvers Lab Objective: Many real-world problems of the form Ax = b have tens of thousands of parameters Solving such systems with Gaussian elimination or matrix factorizations could require

More information

Function call overhead benchmarks with MATLAB, Octave, Python, Cython and C

Function call overhead benchmarks with MATLAB, Octave, Python, Cython and C Function call overhead benchmarks with MATLAB, Octave, Python, Cython and C André Gaul September 23, 2018 arxiv:1202.2736v1 [cs.pl] 13 Feb 2012 1 Background In many applications a function has to be called

More information

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26,

SERIOUS ABOUT SOFTWARE. Qt Core features. Timo Strömmer, May 26, SERIOUS ABOUT SOFTWARE Qt Core features Timo Strömmer, May 26, 2010 1 Contents C++ refresher Core features Object model Signals & slots Event loop Shared data Strings Containers Private implementation

More information

Running Cython and Vectorization

Running Cython and Vectorization Running Cython and Vectorization 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions

More information

Distributed Memory Programming With MPI Computer Lab Exercises

Distributed Memory Programming With MPI Computer Lab Exercises Distributed Memory Programming With MPI Computer Lab Exercises Advanced Computational Science II John Burkardt Department of Scientific Computing Florida State University http://people.sc.fsu.edu/ jburkardt/classes/acs2

More information

Lecture 2: Introduction to OpenMP with application to a simple PDE solver

Lecture 2: Introduction to OpenMP with application to a simple PDE solver Lecture 2: Introduction to OpenMP with application to a simple PDE solver Mike Giles Mathematical Institute Mike Giles Lecture 2: Introduction to OpenMP 1 / 24 Hardware and software Hardware: a processor

More information

Extensions in C and Fortran

Extensions in C and Fortran Extensions in C and Fortran Why? C and Fortran are compiled languages Source code is translated to machine instructons by the compiler before you run. Ex: gfortran -o mycode mycode.f90 gcc -o mycode mycode.c

More information

Exercises Lecture 3 Layouts and widgets

Exercises Lecture 3 Layouts and widgets Exercises Lecture 3 Layouts and widgets Aim: Duration: This exercise will help you explore and understand Qt's widgets and the layout approach to designing user interfaces. 2h The enclosed Qt Materials

More information

MPI Casestudy: Parallel Image Processing

MPI Casestudy: Parallel Image Processing MPI Casestudy: Parallel Image Processing David Henty 1 Introduction The aim of this exercise is to write a complete MPI parallel program that does a very basic form of image processing. We will start by

More information

Running Cython and Vectorization

Running Cython and Vectorization Running Cython and Vectorization 1 Getting Started with Cython overview hello world with Cython 2 Numerical Integration experimental setup adding type declarations cdef functions & calling external functions

More information

CERTIFICATE IN WEB PROGRAMMING

CERTIFICATE IN WEB PROGRAMMING COURSE DURATION: 6 MONTHS CONTENTS : CERTIFICATE IN WEB PROGRAMMING 1. PROGRAMMING IN C and C++ Language 2. HTML/CSS and JavaScript 3. PHP and MySQL 4. Project on Development of Web Application 1. PROGRAMMING

More information

On the performance of the Python programming language for serial and parallel scientific computations

On the performance of the Python programming language for serial and parallel scientific computations Scientific Programming 13 (2005) 31 56 31 IOS Press On the performance of the Python programming language for serial and parallel scientific computations Xing Cai a,b, Hans Petter Langtangen a,b and Halvard

More information

Open Multi-Processing: Basic Course

Open Multi-Processing: Basic Course HPC2N, UmeåUniversity, 901 87, Sweden. May 26, 2015 Table of contents Overview of Paralellism 1 Overview of Paralellism Parallelism Importance Partitioning Data Distributed Memory Working on Abisko 2 Pragmas/Sentinels

More information

Shared memory programming model OpenMP TMA4280 Introduction to Supercomputing

Shared memory programming model OpenMP TMA4280 Introduction to Supercomputing Shared memory programming model OpenMP TMA4280 Introduction to Supercomputing NTNU, IMF February 16. 2018 1 Recap: Distributed memory programming model Parallelism with MPI. An MPI execution is started

More information

Practical Introduction to Message-Passing Interface (MPI)

Practical Introduction to Message-Passing Interface (MPI) 1 Outline of the workshop 2 Practical Introduction to Message-Passing Interface (MPI) Bart Oldeman, Calcul Québec McGill HPC Bart.Oldeman@mcgill.ca Theoretical / practical introduction Parallelizing your

More information

PTN-202: Advanced Python Programming Course Description. Course Outline

PTN-202: Advanced Python Programming Course Description. Course Outline PTN-202: Advanced Python Programming Course Description This 4-day course picks up where Python I leaves off, covering some topics in more detail, and adding many new ones, with a focus on enterprise development.

More information

Pythran: Crossing the Python Frontier

Pythran: Crossing the Python Frontier DEPARTMENT: Scientific Programming Pythran: Crossing the Python Frontier Serge Guelton Institut Mines-Télécom Bretagne Editors: Konrad Hinsen, konrad.hinsen@cnrs.fr; Matthew Turk, matthewturk@gmail.com

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

Numba: A Compiler for Python Functions

Numba: A Compiler for Python Functions Numba: A Compiler for Python Functions Stan Seibert Director of Community Innovation @ Anaconda My Background 2008: Ph.D. on the Sudbury Neutrino Observatory 2008-2013: Postdoc working on SNO, SNO+, LBNE

More information

Mixed Python/C programming with Cython September /14. Mixed Python/C programming with Cython Ben Dudson, 22nd September 2017

Mixed Python/C programming with Cython September /14. Mixed Python/C programming with Cython Ben Dudson, 22nd September 2017 Mixed Python/C programming with Cython September 2017 1/14 Mixed Python/C programming with Cython Ben Dudson, 22nd September 2017 Mixed Python/C programming with Cython September 2017 2/14 Cython http://cython.org/

More information

QUIZ. What is wrong with this code that uses default arguments?

QUIZ. What is wrong with this code that uses default arguments? QUIZ What is wrong with this code that uses default arguments? Solution The value of the default argument should be placed in either declaration or definition, not both! QUIZ What is wrong with this code

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Interfacing With Other Programming Languages Using Cython

Interfacing With Other Programming Languages Using Cython Lab 1 Interfacing With Other Programming Languages Using Cython Lab Objective: Learn to interface with object files using Cython. This lab should be worked through on a machine that has already been configured

More information

PYTHON TRAINING COURSE CONTENT

PYTHON TRAINING COURSE CONTENT SECTION 1: INTRODUCTION What s python? Why do people use python? Some quotable quotes A python history lesson Advocacy news What s python good for? What s python not good for? The compulsory features list

More information

Some possible directions for the R engine

Some possible directions for the R engine Some possible directions for the R engine Luke Tierney Department of Statistics & Actuarial Science University of Iowa July 22, 2010 Luke Tierney (U. of Iowa) Directions for the R engine July 22, 2010

More information

PYTHON IS SLOW. Make it faster with C. Ben Shaw

PYTHON IS SLOW. Make it faster with C. Ben Shaw PYTHON IS SLOW Make it faster with C Ben Shaw It s OK that Python isn t fast, you can write your slow functions in C! Everyone TABLE OF CONTENTS C Module vs C Types TABLE OF CONTENTS C Module vs C Types

More information

Inheritance, Polymorphism and the Object Memory Model

Inheritance, Polymorphism and the Object Memory Model Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation

More information

Course May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points

Course May 18, Advanced Computational Physics. Course Hartmut Ruhl, LMU, Munich. People involved. SP in Python: 3 basic points May 18, 2017 3 I/O 3 I/O 3 I/O 3 ASC, room A 238, phone 089-21804210, email hartmut.ruhl@lmu.de Patrick Böhl, ASC, room A205, phone 089-21804640, email patrick.boehl@physik.uni-muenchen.de. I/O Scientific

More information

Mixed language programming

Mixed language programming Mixed language programming Simon Funke 1,2 Ola Skavhaug 3 Joakim Sundnes 1,2 Hans Petter Langtangen 1,2 Center for Biomedical Computing, Simula Research Laboratory 1 Dept. of Informatics, University of

More information

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static Table of Contents Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static Series Chart with Dynamic Series Master-Detail

More information

A Comparison of Unified Parallel C, Titanium and Co-Array Fortran. The purpose of this paper is to compare Unified Parallel C, Titanium and Co-

A Comparison of Unified Parallel C, Titanium and Co-Array Fortran. The purpose of this paper is to compare Unified Parallel C, Titanium and Co- Shaun Lindsay CS425 A Comparison of Unified Parallel C, Titanium and Co-Array Fortran The purpose of this paper is to compare Unified Parallel C, Titanium and Co- Array Fortran s methods of parallelism

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

CS1 Lecture 3 Jan. 22, 2018

CS1 Lecture 3 Jan. 22, 2018 CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow

More information

TxWin 5.xx Programming and User Guide

TxWin 5.xx Programming and User Guide TxWin 5.xx Programming and User Guide Jan van Wijk Brief programming and user guide for the open-source TxWin text UI library Presentation contents Interfacing, include files, LIBs The message event model

More information

Semantic Analysis. Lecture 9. February 7, 2018

Semantic Analysis. Lecture 9. February 7, 2018 Semantic Analysis Lecture 9 February 7, 2018 Midterm 1 Compiler Stages 12 / 14 COOL Programming 10 / 12 Regular Languages 26 / 30 Context-free Languages 17 / 21 Parsing 20 / 23 Extra Credit 4 / 6 Average

More information

Table of Contents EVALUATION COPY

Table of Contents EVALUATION COPY Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...

More information

PyTest Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : May, More documents are freely available at PythonDSP

PyTest Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : May, More documents are freely available at PythonDSP PyTest Guide Meher Krishna Patel Created on : Octorber, 2017 Last updated : May, 2018 More documents are freely available at PythonDSP Table of contents Table of contents i 1 PyTest Guide 2 1.1 Code to

More information

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo TH IRD EDITION Python Cookbook David Beazley and Brian K. Jones O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo Table of Contents Preface xi 1. Data Structures and Algorithms 1 1.1. Unpacking

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Composite Types and Language Standards Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 March 2008 Programming with MPI p. 2/?? Composite Types

More information

Core Development > PEP Index > PEP Addition of the multiprocessing package to the standard library

Core Development > PEP Index > PEP Addition of the multiprocessing package to the standard library Core Development > PEP Index > PEP 371 -- Addition of the multiprocessing package to the standard library PEP: 371 Title: Version: 70469 Addition of the multiprocessing package to the standard library

More information

Astronomical Data Analysis with Python

Astronomical Data Analysis with Python Astronomical Data Analysis with Python Lecture 8 Yogesh Wadadekar NCRA-TIFR July August 2010 Yogesh Wadadekar (NCRA-TIFR) Topical course 1 / 27 Slides available at: http://www.ncra.tifr.res.in/ yogesh/python_course_2010/

More information

Programming in Python

Programming in Python COURSE DESCRIPTION This course presents both the programming interface and the techniques that can be used to write procedures in Python on Unix / Linux systems. COURSE OBJECTIVES Each participant will

More information

1: Introduction to Object (1)

1: Introduction to Object (1) 1: Introduction to Object (1) 김동원 2003.01.20 Overview (1) The progress of abstraction Smalltalk Class & Object Interface The hidden implementation Reusing the implementation Inheritance: Reusing the interface

More information

ctypes extending python was never easier! Anant Narayanan Malaviya National Institute of Technology

ctypes extending python was never easier! Anant Narayanan Malaviya National Institute of Technology C! ctypes extending python was never easier! Anant Narayanan Malaviya National Institute of Technology So what is python? Dynamically typed, interpreted language Allows for fast prototyping, thanks to

More information

Introductory OpenMP June 2008

Introductory OpenMP June 2008 5: http://people.sc.fsu.edu/ jburkardt/presentations/ fdi 2008 lecture5.pdf... John Information Technology Department Virginia Tech... FDI Summer Track V: Parallel Programming 10-12 June 2008 Introduction

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Functions in C C Programming and Software Tools

Functions in C C Programming and Software Tools Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

Python Working with files. May 4, 2017

Python Working with files. May 4, 2017 Python Working with files May 4, 2017 So far, everything we have done in Python was using in-memory operations. After closing the Python interpreter or after the script was done, all our input and output

More information

6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics

6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics 6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics Grab Bag & Perspective January 31, 2014 6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics January 31, 2014 1 / 19 Outline 1 Perspective

More information

CS Programming Languages: Python

CS Programming Languages: Python CS 3101-1 - Programming Languages: Python Lecture 5: Exceptions / Daniel Bauer (bauer@cs.columbia.edu) October 08 2014 Daniel Bauer CS3101-1 Python - 05 - Exceptions / 1/35 Contents Exceptions Daniel Bauer

More information

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur

Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur Deep Learning for Visual Computing Prof. Debdoot Sheet Department of Electrical Engineering Indian Institute of Technology, Kharagpur Lecture - 05 Classification with Perceptron Model So, welcome to today

More information

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006 C Compilation Model Comp-206 : Introduction to Software Systems Lecture 9 Alexandre Denault Computer Science McGill University Fall 2006 Midterm Date: Thursday, October 19th, 2006 Time: from 16h00 to 17h30

More information

CS11 Java. Fall Lecture 1

CS11 Java. Fall Lecture 1 CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon

More information

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science Functions in C C Programming and Software Tools N.C. State Department of Computer Science Functions in C Functions are also called subroutines or procedures One part of a program calls (or invokes the

More information

Oh my. Maya is Qt! Kristine Middlemiss, Autodesk Developer Consultant, Autodesk Developer Network

Oh my. Maya is Qt! Kristine Middlemiss, Autodesk Developer Consultant, Autodesk Developer Network Oh my. Maya is Qt! Kristine Middlemiss, Autodesk Developer Consultant, Autodesk Developer Network 1 2 Biography Topics» Introducing Qt» How Qt fits into Maya» Ways to work with Qt»Qt Designer with Maya

More information

A QUICK OVERVIEW OF THE OMNeT++ IDE

A QUICK OVERVIEW OF THE OMNeT++ IDE Introduction A QUICK OVERVIEW OF THE OMNeT++ IDE The OMNeT++ Integrated Development Environment is based on the Eclipse platform, and extends it with new editors, views, wizards, and additional functionality.

More information

Python GUI programming with PySide. Speaker: BigLittle Date: 2013/03/04

Python GUI programming with PySide. Speaker: BigLittle Date: 2013/03/04 Python GUI programming with PySide Speaker: BigLittle Date: 2013/03/04 CLI vs. GUI CLI (Command Line Interface) Take less resources. User have much more control of their system. Only need to execute few

More information

Ch. 11: References & the Copy-Constructor. - continued -

Ch. 11: References & the Copy-Constructor. - continued - Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed

More information

Visual Profiler. User Guide

Visual Profiler. User Guide Visual Profiler User Guide Version 3.0 Document No. 06-RM-1136 Revision: 4.B February 2008 Visual Profiler User Guide Table of contents Table of contents 1 Introduction................................................

More information

Scientific Python. 1 of 10 23/11/ :00

Scientific Python.   1 of 10 23/11/ :00 Scientific Python Neelofer Banglawala Kevin Stratford nbanglaw@epcc.ed.ac.uk kevin@epcc.ed.ac.uk Original course authors: Andy Turner Arno Proeme 1 of 10 23/11/2015 00:00 www.archer.ac.uk support@archer.ac.uk

More information

Introduction to Python Part 2

Introduction to Python Part 2 Introduction to Python Part 2 v0.2 Brian Gregor Research Computing Services Information Services & Technology Tutorial Outline Part 2 Functions Tuples and dictionaries Modules numpy and matplotlib modules

More information

Programming with MPI

Programming with MPI Programming with MPI p. 1/?? Programming with MPI Miscellaneous Guidelines Nick Maclaren Computing Service nmm1@cam.ac.uk, ext. 34761 March 2010 Programming with MPI p. 2/?? Summary This is a miscellaneous

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

Traditional Smalltalk Playing Well With Others Performance Etoile. Pragmatic Smalltalk. David Chisnall. August 25, 2011

Traditional Smalltalk Playing Well With Others Performance Etoile. Pragmatic Smalltalk. David Chisnall. August 25, 2011 Étoilé Pragmatic Smalltalk David Chisnall August 25, 2011 Smalltalk is Awesome! Pure object-oriented system Clean, simple syntax Automatic persistence and many other great features ...but no one cares

More information

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 9 Robert Grimm, New York University 1 Review Last week Modules 2 Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic

More information