python for matlab users - csdms › mediawiki › images › thomas_hauser_c… · python scripting...

30
CU Research Computing: University of Colorado Boulder Python for Matlab Users Thomas Hauser Director of Research Computing [email protected] Monte Lunacek HPC Application Specialist [email protected]

Upload: others

Post on 07-Jun-2020

37 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

CU Research Computing: University of Colorado Boulder

Python for Matlab UsersThomas Hauser Director of Research Computing [email protected] 

Monte Lunacek HPC Application Specialist [email protected] 

Page 2: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Who are we?

CU Research Computing: University of Colorado Boulder 2/30

Page 3: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

What is Python?

CU Research Computing: University of Colorado Boulder 3/30

Page 4: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

What is Python?

CU Research Computing: University of Colorado Boulder

Flexible, powerful programming language

Easy, clean syntaxVery readable codeBalanced high level programming with low­level optimization

Large community of support

Free as in free beerFree as in free speech

·Object orientedRuns everywhereTesting framework

­­­

···

Pyrex, CythonF2py

­­

·Modular system, large number of libraries­

··

4/30

Page 5: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Minimum packages for computationalscience

CU Research Computing: University of Colorado Boulder

python: the base languagenumpy: arrays, fast operations on arraysscipy: higher level computational routinesmatplotlib: plottingipython: notebooks, flexible shell, and parallelpandas: data analysis

······

5/30

Page 6: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

What can you do with Python?

CU Research Computing: University of Colorado Boulder

OS support: manage files and directoriesGlue existing applicationsLAPACK and BLAS: access powerful C and Fortran librariesParallelData AnalysisVisualizationGUI programmingScrape websitesBuild websitesAnything!

··········

6/30

Page 7: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

OutlinePart One

Part Two

CU Research Computing: University of Colorado Boulder

Python Overview (30 minutes)

Lab (10 minutes)Break (10 minutes)

·IPython and NotebookFunctions, lists, and Dictionaries

­­

··

Numpy (20 minutes)Plotting with Matplotlib (10 minutes)Lab (10 minutes)Data Analysis (20 minutes)

····

7/30

Page 8: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Python OverviewTest driving three ways to interact with PythonFunctions, lists, dictionaries

··

Page 9: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Hello World

What do you notice about this code?

CU Research Computing: University of Colorado Boulder

#!/Users/mlunacek/anaconda/bin/python

def say_hello(): print 'hello world'

say_hello()

PYTHON

9/30

Page 10: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Three ways to run

CU Research Computing: University of Colorado Boulder 10/30

Page 11: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Terminal

CU Research Computing: University of Colorado Boulder

$ ls hello_world.py hello_world.py$ python hello_world.py hello world$ ./hello_world.py hello worldbash-mac$

BASH

11/30

Page 12: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

IPython shell

CU Research Computing: University of Colorado Boulder

OS supportFormatted printTab Completion%run

HistoryIntrospection (?,??)%paste and %cpaste

····

Persistence­···

12/30

Page 13: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Quick Introduction to Python

How

CU Research Computing: University of Colorado Boulder

FunctionsListsDictionaries

···

IPython terminalNotebook

··

13/30

Page 14: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

/Users/mlunacek/Documents/tutorials/python/python_hpc/Python4Matlab

data_analysis

dictionary_and_lab

functions_and_lists

matplotlib

numpyTutorial

python4matlab

To import a notebook, drag the file onto the listing below or click here.

CU Research Computing: University of Colorado Boulder 14/30

Page 15: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

CU Research Computing: University of Colorado Boulder

Lab and BreakDictionaries

15/30

Page 16: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Endthought

http://www.enthought.com/

CU Research Computing: University of Colorado Boulder 16/30

Page 17: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Anaconda

https://store.continuum.io/cshop/anaconda

CU Research Computing: University of Colorado Boulder 17/30

Page 18: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Github

https://github.com/ResearchComputing/python_hpc

CU Research Computing: University of Colorado Boulder 18/30

Page 19: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Lab

CU Research Computing: University of Colorado Boulder

Go to the directory where you dowloaded the codeunzip the fileNavigate to Python4MatlabLaunch IPython Notebook

····

ipython notebook

dictionary_and_lab

­­

19/30

Page 20: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

/Users/mlunacek/Documents/tutorials/python/python_hpc/Python4Matlab

data_analysis

dictionary_and_lab

functions_and_lists

matplotlib

numpyTutorial

python4matlab

To import a notebook, drag the file onto the listing below or click here.

CU Research Computing: University of Colorado Boulder 20/30

Page 21: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

CU Research Computing: University of Colorado Boulder

Numpy and Matplotlib

21/30

Page 22: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

/Users/mlunacek/Documents/tutorials/python/python_hpc/Python4Matlab

data_analysis

dictionary_and_lab

functions_and_lists

matplotlib

numpyTutorial

python4matlab

To import a notebook, drag the file onto the listing below or click here.

CU Research Computing: University of Colorado Boulder 22/30

Page 23: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

CU Research Computing: University of Colorado Boulder

Lab 2Numpy and Matplotlib

23/30

Page 24: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

/Users/mlunacek/Documents/tutorials/python/python_hpc/Python4Matlab

data_analysis

dictionary_and_lab

functions_and_lists

matplotlib

numpyTutorial

python4matlab

To import a notebook, drag the file onto the listing below or click here.

CU Research Computing: University of Colorado Boulder 24/30

Page 25: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

CU Research Computing: University of Colorado Boulder

PandasData Analysis

25/30

Page 26: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

/Users/mlunacek/Documents/tutorials/python/python_hpc/Python4Matlab

data_analysis

dictionary_and_lab

functions_and_lists

matplotlib

numpyTutorial

python4matlab

To import a notebook, drag the file onto the listing below or click here.

CU Research Computing: University of Colorado Boulder 26/30

Page 27: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

What did we learn?

CU Research Computing: University of Colorado Boulder

Python's syntax is cleanNotebook, IPython terminalData structures

Ways to act on these containersPlotting with matplotlib

···

Lists, dictionaries,numpy arrayspandas DataFrame

­­­

··

27/30

Page 28: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

What's next?

CU Research Computing: University of Colorado Boulder 28/30

Page 29: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

Links

CU Research Computing: University of Colorado Boulder

Scientific Programming: scipyParallel Computing

Performance

Templates: jinja2SQL database: sqlalchemyWebsites: djangoHardware Raspbery Pi

··

IPython Parallelmpi4py

­­

·profilingf2pycythonctypes

­­­­

····

29/30

Page 30: Python for Matlab Users - CSDMS › mediawiki › images › Thomas_Hauser_C… · Python Scripting for Computational Science Python Snakes Its Way Into HPC Andy Terrel: Getting Started

References

Thank you!

CU Research Computing: University of Colorado Boulder

Python Scripting for Computational SciencePython Snakes Its Way Into HPCAndy Terrel: Getting Started with Python in HPCPython TutorialThink PythonEnthoughtAnacondaData Analysis with Python

········

30/30