Scientific Computing Beyond Matlab Nov 19, 2012 Jason Su.

Slides:



Advertisements
Similar presentations
Guy Griffiths. General purpose interpreted programming language Widely used by scientists and programmers of all stripes Supported by many 3 rd -party.
Advertisements

Python for Science Shane Grigsby. What is python? Why python? Interpreted, object oriented language Free and open source Focus is on readability Fast.
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Computer Science 121 Scientific Computing Winter 2012.
Python Lab Proteomics Informatics, Spring 2014 Week 1 28 th Jan, 2014 Himanshu Grover
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
Reasons to study concepts of PL
Platforms for Agent-Based Computational Economics Rob Axtell Brookings CSED.
Script Languages in Science CCOM Student Seminar Series Kurt Schwehr 12-Nov-2008.
Language Issues Misunderstimated? Sublimable? Hopefuller? "I know how hard it is for you to put food on your family.” "I know the human being and fish.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
By. What advantages has it? The Reasons for Choosing Python  Python is free  It is object-oriented  It is interpreted  It is operating-system independent.
ECLIPSE IDE N AME : A SHOK P ADMARAJU C OURSE : T OPICS ON S OFTWARE E NGINEERING I NSTRUCTOR : D R. S ERGIU D ASCALU.
Alan Edelman, Jeff Bezanson Viral Shah, Stefan Karpinski Jeremy Kepner and the vibrant open-source community Computer Science & AI Laboratories Novel Algebras.
CS 350 Operating Systems & Programming Languages Ethan Race Oren Rasekh Christopher Roberts Christopher Rogers Anthony Simon Benjamin Ramos.
© 2004 The MathWorks, Inc. 1 MATLAB for C/C++ Programmers Support your C/C++ development using MATLAB’s prebuilt graphics functions and trusted numerics.
JCE A Java-based Commissioning Environment tool Hiroyuki Sako, JAEA Hiroshi Ikeda, Visible Information Center Inc. SAD Workshop.
Xin Liu Sep 16, Introduction Xin (Shane) Liu PhD Candidate in Computer Science Research Area: Computer Graphics Tutorial Page: pages.cpsc.ucalgary.ca/~liuxin/CPSC453.
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Dr. Chris Musselle – Consultant R Meets Julia Dr Chris Musselle.
A one day crash course on Python
Python Mini-Course University of Oklahoma Department of Psychology Day 1 – Lesson 1 Getting Started 4/5/09 Python Mini-Course: Day 1 - Lesson 1 1.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Computer Science 121 Scientific Computing Winter 2014.
Company Overview for GDF Suez December 29, Enthought’s Business Enthought provides products and consulting services for scientific software solutions.
Introduction to Python By Neil Cook Twitter: njcuk Slides/Notes:
Introduction to Julia: Why are we doing this to you? (Fall 2015) Steven G. Johnson, MIT Applied Math MIT classes , 18.06, ,
October 5, 2015 Pretty Programming and Packaging with Python Fedor Baart, Genna Donchyts, Hessel Winsemius Slides and course material will be made available.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Programming Languages: Scratch Intro to Scratch. Lower level versus high level Clearly, lower level languages can be tedious Higher level languages quickly.
Introduction to Pyrex September 2002 Brian Quinlan
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Hands-on Introduction to R. We live in oceans of data. Computers are essential to record and help analyse it. Competent scientists speak C/C++, Java,
Productivity Tools Ken Nguyen Department of Information Technology Clayton State University.
Editing & Compiling: UNIX vs. IDE and an Intro to Architecture.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
Scientific Computing Introduction to Matlab Programming.
CLIP Command Line InterPreter for a subset of C++.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Evaluating Python as an Introductory Programming Language A. Thomas and H.L. Liang UNISA.
Eclipse 24-Apr-17.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Data-Intensive Computing: From Clouds to GPUs Gagan Agrawal December 3,
Siena Computational Crystallography School 2005
1 Writing Better R Code Hui Zhang Research Analytics.
CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young.
Python  Monty or Snake?. Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.
COMP 4332 Tutorial 1 Feb 16 WANG YUE Tutorial Overview & Learning Python.
Jeff Howbert Introduction to Machine Learning Winter Machine Learning MATLAB Essentials.
Python & NetworkX Youn-Hee Han
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.
CIS 595 MATLAB First Impressions. MATLAB This introduction will give Some basic ideas Main advantages and drawbacks compared to other languages.
PYTHON FOR HIGH PERFORMANCE COMPUTING. OUTLINE  Compiling for performance  Native ways for performance  Generator  Examples.
1 Programming and problem solving in C, Maxima, and Excel.
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
Python – It's great By J J M Kilner. Introduction to Python.
Python Scripting for Computational Science CPS 5401 Fall 2014 Shirley Moore, Instructor October 6,
Python for data analysis Prakhar Amlathe Utah State University
CSC391/691 Intro to OpenCV Dr. Rongzhong Li Fall 2016
Lecture 20 Optimizing Python.
Prepared by Kimberly Sayre and Jinbo Bi
Programming vs. Packaged
Introduction to MATLAB
CSE Social Media & Text Analytics
Python for Scientific Computing
Brief Intro to Python for Statistics
Simulation And Modeling
Igor Stančin, Alan Jović to: {igor.stancin,
Presentation transcript:

Scientific Computing Beyond Matlab Nov 19, 2012 Jason Su

Motivation I’m interested in (re-)coding a general solver for sc/mcDESPOT relaxometry mapping – Open source – Extensibility to new/add’l sequences with better sensitivity to certain parameters, e.g. B0 and MWF – Better parallelization But: – Large-scale code development in Matlab is cumbersome – Matlab is slow – C is hard (to write, read, debug) Creates large barrier for others to contribute

Matlab Pros Ubiquitous, code is cross- platform Can be fast with vectorized code Data visualization Quick development time Great IDE for general research – Poor for large projects Many useful native libraries/toolboxes Built-in profiling tools Cons Requires license, not free (though there is Octave) Vectorized code is often non-intuitive to write and hard to read Slow for general computations Limited parallel computing and GPU support

C/C++ Pros Fast Great IDEs for large coding projects – Not as great for general science work Strong parallel computer support and CUDA Community libraries for scientific computing Profiling dependent on IDE Cons High learning curve and development time No data visualization Compiled code is platform specific Compiler is not generally installed with OSX and Windows

Python Pros Preinstalled with OSX and Linux-based systems Readability is a core tenet (“pythonic”) Quick development time Native parallel computing support and community GPU modules Extensive community support – Including neuroimaging- specific: NiPype, NiBabel Built-in profiling module and some IDE tools Cons Slow for general computation Mixed bag of IDEs, some are great for coding, others for research Out of the box it’s a poor alternative: no linear algebra or data visualization

Python & Friends Cons Slow for general computation Mixed bag of IDEs, some are great for coding, others for research Out of the box it’s a poor alternative: no linear algebra or data visualization Solutions Cython, JIT compilers like PyPy There are a few good options out there that I’ve found: – Eclipse + PyDev, NetBeanz – Spyder – closest to MATLAB – Sage Math Notebook, IPython – like Mathematica – It may come down to preference. NumPy + SciPy + Matplotlib = PyLab – Sage Math includes these as well as other capabilities like symbolic math and graph theory

Pythonic? A term of praise used by the community to refer to clean code that is readable, intuitive, explicit, and takes advantage of coding idioms Python people = [‘John Doe’, ’Jane Doe’, ’John Smith’] smith_family = [] for name in people: if ‘Smith’ in name: smith_family.append(name) smith_family = [name for name in people if ‘Smith’ in name] Matlab people = {‘John Doe’, ’Jane Doe’, ’John Smith’}; smith_family = {} for name = people if strfind(name{1},’Smith’) smith_family = [smith_family name]; end

Installation On any OS: – Sage Math ( easy unzip installation but many “extraneous” packages (500MB) Some issues on OSX with matplotlib On OSX: – Use MacPorts to install Python (2.7), SciPy, matplotlib, and Cython Requires gcc compiler available through Apple Developer

NumPy + SciPy vs Matlab Same core libraries: LAPACK Equivalent syntax but not trying to be similar NumPy_for_Matlab_Users Key differences: – Python uses 0 (zero) based indexing. The initial element of a sequence is found using [0]. – In NumPy arrays have pass-by-reference semantics. Slice operations are views into an array.

Syntax Matlab a\b max(a(:)) a(end-4:end) [0:9] NumPy linalg.lstsq(a,b) a.max() a[-5:] arange(10.) or r_[:10.]

Cython Requires a C compiler Cython is Python with C data types. – Dynamic typing of Python has overhead, slow for computation Allows seamless coding of Python and embedded C-speed routines Python values and C values can be freely intermixed, with conversions occurring automatically wherever possible – This means for debugging C-level code, we can use all the plotting tools available in Python Process is sort of like EPIC 1.Write a.pyx source file 2.Run the Cython compiler to generate a C file 3.Run a C compiler to generate a compiled library 4.Run the Python interpreter and ask it to import the module

Code Comparison – Matlab Let’s try a really basic speed comparison test s = 0 tic for i = 1:1e8 s = s + i; end toc tic x = 1:1e8; sum(x) toc

Code Comparison – C #include int main() { long long unsigned int sum = 0; long long unsigned int i = 0; long long unsigned int max = ; clock_t tic = clock(); for (i = 0; i <= max; i++) { sum = sum + i; } clock_t toc = clock(); printf("%15lld, Elapsed: %f seconds\n", sum, (double)(toc - tic) / CLOCKS_PER_SEC); return 0; }

Code Comparison – Python import time from numpy import * s = 0 t = time.time() for i in xrange( ): s += i print time.time() - t t = time.time() x = arange( ) sum(x) print time.time() - t

Code Comparison – Cython addCy.pyx import time cdef long long int n = cdef long long int s = 0 cdef long long int i = 0 t = time.time() for i in xrange(n+1): s += i print time.time() – t runCy.py import pyximport; pyximport.install() import addCy

Speed Comparison Language/ImplementationTime (sec) Matlab/For loop0.547 Matlab/Vector sum0.817 (0.036 for sum only!) Python/For loop Python/NumPy sum0.648 (0.135 for sum only) C/For loop0.222 Cython/For loop0.068 (!)

Summary Python – Full featured programming language with an emphasis on “pythonic” readability NumPy/SciPy – Core libraries for linear algebra and computation (fft, optimization) Cython – Allows as much optimization as you want, degrading gracefully from high-level Python to low-level C – Profile, don’t over optimize too early!