Using PyTrilinos 2005 Trilinos Users Group Meeting 1 Nov 2005 3:30-4:30 Bill Spotz.

Slides:



Advertisements
Similar presentations
Purdue University Center for Education and Research in Information Assurance and Security Building a distributed intrusion detection system with Perl Diego.
Advertisements

Three types of remote process invocation
Python Whats in a name? Snake logos and mascot notwithstanding, its named after Monty Pythons Flying Circus Humor-impaired can safely.
INTRODUCTION TO SIMULATION WITH OMNET++ José Daniel García Sánchez ARCOS Group – University Carlos III of Madrid.
Python for Science Shane Grigsby. What is python? Why python? Interpreted, object oriented language Free and open source Focus is on readability Fast.
Strategies for solving scientific problems using computers.
MATLAB Presented By: Nathalie Tacconi Presented By: Nathalie Tacconi Originally Prepared By: Sheridan Saint-Michel Originally Prepared By: Sheridan Saint-Michel.
Data Analytics and Dynamic Languages Lee E. Edlefsen, Ph.D. VP of Engineering 1.
CIS 101: Computer Programming and Problem Solving Lecture 8 Usman Roshan Department of Computer Science NJIT.
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
Reasons to study concepts of PL
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Mx? A programming language for scientific computation. Related Languages: Matlab IDL Maple, Mathcad, Mathematica.
SCRIPTING LANGUAGE. The first interactive shells were developed in the 1960s to enable remote operation of the first time-sharing systems, and these,
Scripting Languages CS351 – Programming Paradigms.
Guide To UNIX Using Linux Third Edition
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
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.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
–Streamline / organize Improve readability of code Decrease code volume/line count Simplify mechanisms Improve maintainability & clarity Decrease development.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Programming Languages and Paradigms Object-Oriented Programming.
Dr. Chris Musselle – Consultant R Meets Julia Dr Chris Musselle.
Chapter 6 Operating System Support. This chapter describes how middleware is supported by the operating system facilities at the nodes of a distributed.
Taking Ownership of Your Package’s Python Interface 2005 Trilinos Users Group Meeting 31 Oct :15-2:15 Bill Spotz.
PyTrilinos: A Python Interface to Trilinos Bill Spotz Sandia National Laboratories Reproducible Research in Computational Geophysics August 31, 2006.
Python: An Introduction
Java Introduction Lecture 1. Java Powerful, object-oriented language Free SDK and many resources at
CHAPTER FOUR COMPUTER SOFTWARE.
Page 1 Trilinos Software Engineering Technologies and Integration Numerical Algorithm Interoperability and Vertical Integration –Abstract Numerical Algorithms.
Ruby! Ronald L. Ramos. What is Ruby? Ruby is a scripting language designed by Yukihiro Matsumoto, also known as Matz. It runs on a variety of platforms,
Parallel Interactive Computing with PyTrilinos and IPython Bill Spotz, SNL (Brian Granger, Tech-X Corporation) November 8, 2007 Trilinos Users Group Meeting.
Trilinos 101 (Part II) Creating and managing linear algebra data in Trilinos: Data management using Epetra and Teuchos Michael A. Heroux Sandia National.
Scientific Computing Beyond Matlab Nov 19, 2012 Jason Su.
1 Computer Systems -- Introduction  Chapter 1 focuses on:  the structure of a Java application  basic program elements  preparing and executing a program.
Amesos Sparse Direct Solver Package Ken Stanley, Rob Hoekstra, Marzio Sala, Tim Davis, Mike Heroux Trilinos Users Group Albuquerque 3 Nov 2004.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Presentation: SOAP/WS in a distributed object framework, Application Servers & AXIS SOAP.
Ch 1. A Python Q&A Session Spring Why do people use Python? Software quality Developer productivity Program portability Support libraries Component.
Invitation to Computer Science 5 th Edition Chapter 6 An Introduction to System Software and Virtual Machine s.
FLUKA GUI Status FLUKA Meeting CERN, 10/7/2006.
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear.
Guide to Programming with Python Chapter One Getting Started: The Game Over Program.
Presentation: SOAP/WS in a distributed object framework, Application Servers & AXIS SOAP.
PyTrilinos: a Python Interface to Selected Trilinos Packages Bill Spotz Trilinos Users Group Meeting November 2, 2004.
Amesos Sparse Direct Solver Package Tim Davis, Mike Heroux, Rob Hoekstra, Marzio Sala, Ken Stanley, Heidi Thornquist, Jim Willenbring Trilinos Users Group.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Amesos Interfaces to sparse direct solvers October 15, :30 – 9:30 a.m. Ken Stanley.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
1 Stratimikos Unified Wrapper to Trilinos Linear Solvers and Preconditioners Roscoe A. Bartlett Department of Optimization & Uncertainty Estimation Sandia.
Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin Company, for the United States Department of Energy’s National Nuclear.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Thyra For Developers Roscoe A. Bartlett Department of Optimization & Uncertainty Estimation Sandia National Laboratories Trilinos Users Group Meeting (Developers.
Getting Started with SIDL using the ANL SIDL Environment (ASE) ANL SIDL Team MCS Division, ANL April 2003 The ANL SIDL compilers are based on the Scientific.
PHP vs. Python. Similarities are interpreted, high level languages with dynamic typing are Open Source are supported by large developer communities are.
Introduction Mehdi Einali Advanced Programming in Java 1.
Photos placed in horizontal position with even amount of white space between photos and header Sandia National Laboratories is a multi-program laboratory.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
Combining Trilinos Packages To Solve Linear Systems Michael A. Heroux Sandia National Labs.
3/12/2013Computer Engg, IIT(BHU)1 MPI-1. MESSAGE PASSING INTERFACE A message passing library specification Extended message-passing model Not a language.
What’s New for Epetra Michael A. Heroux Sandia National Laboratories Sandia is a multiprogram laboratory operated by Sandia Corporation, a Lockheed Martin.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
DOE/Office of Science/ASCR (Sandia National Laboratories)
CST 1101 Problem Solving Using Computers
Microsoft .NET 3. Language Innovations Pan Wuming 2017.
Python for Scientific Computing
Trilinos Software Engineering Technologies and Integration
Presentation transcript:

Using PyTrilinos 2005 Trilinos Users Group Meeting 1 Nov :30-4:30 Bill Spotz

Outline A little python evangelism Configuring, compiling and installing PyTrilinos A word about documentation… PyTrilinos.Epetra –Communicators and MPI –Maps, Vectors, CrsMatrix, etc… Other modules –Galeri, Amesos, IFPACK, ML … (and Teuchos) Cross-language polymorphism Efficiency issues What needs to be done

Why Python? “Why Python?” by Eric Raymond, author of The Cathedral and the Bazaar: Some highlights: –“Language collector”, preferred Perl –Initially recoiled at indentation delimiting code blocks –Recognized Perl’s scalability problems –Would only use C/C++ for kernel hacking, scientific computing and 3D graphics –Tried python for writing a GUI front-end configuration tool –Whitespace as syntax stopped feeling unnatural after ~20 min –Mastered python in ~1 day: misstep rate  0, before he had learned python’s feature set –Months after writing code, it was still readable without serious mental effort

My Own Personal Experience First OO design project: framework for coupling nonlinear PDEs (test bed for JFNK) Alfred Lorber suggested python After 1.5 DAYS: –I learned python –Alfred & I developed Grid and Field classes –Base class for PhysicsModules, two implementations from Brusselator problem (1D,FD) plus Dirichlet BCs –Base class for Solver that accepts arbitrary # of PhysicsModules, explicit implementation (Euler) –Debugged and working –Ready for implicit solvers…need for PyTrilinos

What Is So Great About Python? Interpreted, interactive, object-oriented Remarkable power with clear syntax Modules, classes, exceptions, high-level dynamic data types, dynamic typing Huge collection of libraries (modules) GUIs: –X11, Motif, Tk, Mac, MFC, wxWidgets… Extensible with compiled languages, embeddable into applications Portable –UNIX, Windows, OS/2, Mac, Amiga… Scalable Productivity: as a programmer, you can focus on problem, rather than language issues…rapid prototyping

What is PyTrilinos? PyTrilinos is a collection of python interfaces to selected Trilinos packages Amesos Anasazi AztecOO Epetra EpetraExt Galeri IFPACK LOCA ML New_Package NOX Triutils

How Do I Build and Access PyTrilinos? Prerequisites –Python 2.3 or higher –Python Numeric module –SWIG or higher When configuring Trilinos, –Use --enable-python[=path] or --with-python[=path] –If building NOX, you must use --with-gnumake –Optionally specify --with-swig=path Building Trilinos –Those packages that are enabled and have python interfaces should get built when make is invoked Installing PyTrilinos –Uses --prefix=PREFIX configuration option Using PyTrilinos –Each package is a module under the PyTrilinos package name –Use from PyTrilinos import Epetra,...

Documentation: How Do I Use PyTrilinos? Web site: – –FAQ, Automated listing of what header files are wrapped, some descriptions of C++/python differences, Users Guide –Use the C++ package doxygen pages as a first guide Repository: –Trilnios/packages/PyTrilinos/doc –Overview, ACM-TOMS paper, SciPy’05 presentation, Users Guide Python: –dir() function: lists contents of a complex python object –help() function: returns “man page” of a python object based on its documentation string(s) –These functions, plus the Trilinos web pages should be sufficient to figure out most of PyTrilinos

PyTrilinos.Epetra Communicators –Epetra.SerialComm() and Epetra.MpiComm() supported –New communicator: Epetra.PyComm() -- returns most appropriate communicator –If Trilinos is configured with MPI, then MPI_Init() is called when Epetra is imported and MPI_Finalize() is registered with atexit module –Global operator methods (Broadcast, MaxAll, MinAll, SumAll, …) typically take an arbitrary python object and return a Numeric array of doubles, ints or longs (integer return codes are checked internally).

PyTrilinos.Epetra Communicator Example from Numeric import * from PyTrilinos import Epetra comm = Epetra.PyComm() n = comm.NumProc() data = comm.MyPID() + 1 sum = comm.SumAll(data) # One argument, returns array not int assert(sum[0] == n*(n+1)/2) vals = arange(5) # [0, 1, 2, 3, 4] myVals = vals * data maxVals = vals * n maxAll = comm.MaxAll(myVals) assert(maxAll == maxVals) minAll = comm.MinAll(myVals) assert(minAll == vals)

PyTrilinos MPI Support Uses standard python interpreter (some python MPI implementations require new python executable: mpipython) Standard parallel invocation –mpirun -np 4 python script.py Marzio claims: –It seems to work with LAM/MPI only –It seems to require shared MPI library –Easier with GCC-4.0 –It works fine on MAC OS X 10.4

PyTrilinos.Epetra Maps –Epetra.Map(), Epetra.BlockMap() and Epetra.LocalMap() are supported Vectors –Epetra.Vectors occupy the same “design space” as Numeric arrays, so the PyTrilinos implementation inherits from both (Numeric has wide-spread acceptance in the scientific python community) –Epetra.Vector() supports some of the standard constructors, but can also take an arbitrary python object –Other classes that should support this model: Epetra.MultiVector, Epetra.IntVector, Epetra.SerialDenseVector, Epetra.SerialDenseMatrix, Epetra.IntSerialDenseVector, Epetra.IntSerialDenseMatrix Import/Export available

Two Ways of Building an Epetra.CrsMatrix The easy way… from PyTrilinos import Epetra comm = Epetra.PyComm() nGlobal = 10 * comm.NumProc() map = Epetra.Map(nGlobal, 0, comm) matrix = Epetra.CrsMatrix(Epetra.Copy, map, 0) myElements = map.MyGlobalElements() for gid in myElements: matrix[gid,gid] = 2.0 if gid > 0: matrix[gid,gid-1] = -1.0 # Like MATLAB! if gid < nGlobal - 1: matrix[gid,gid+1] = -1.0 matrix.FillComplete()

Two Ways of Building an Epetra.CrsMatrix The efficient way… from PyTrilinos import Epetra comm = Epetra.PyComm() nGlobal = 10 * comm.NumProc() map = Epetra.Map(nGlobal, 0, comm) matrix = Epetra.CrsMatrix(Epetra.Copy, map, 0) nLocal = map.NumMyElements() for lid in xrange(nLocal): gid = map.GID(lid) if gid != nGlobal-1 and gid != 0: indices = [gid-1, gid, gid+1] values = [-1.0, 2.0, -1.0 ] else: indices = [gid] values = [1.0] matrix.InsertGlobalValues(gid, values, indices) # As Epetra matrix.FillComplete()

The Galeri Package The Trilinos_Util CrsMatrixGallery and VbrMatrixGallery classes are being replaced by the Galeri package –Better documentation, easier to introduce new matrices –PyTrilinos interface available Several finite difference matrices available Examples: from PyTrilinos import Epetra, Galeri comm = Epetra.PyComm() pList = { “n”: 100 } map1 = Galeri.CreateMap(”Linear", comm, pList) matrix1 = Galeri.CreateCrsMatrix(”Tridiag", map, pList) map2, matrix2, x, b, exact = Galeri.ReadHB("gre__115.rua", comm)

Parameter Lists Goal: wherever Trilinos expects a parameter list, accept a python dictionary # Create a Cartesian map, containing nx x ny x NumProcs nodes comm = Epetra.PyComm() nx = 2 ny = 2 * comm.NumProc() pList = { "nx": nx, # Number of nodes in the X-direction "ny": ny, # Number of nodes in the Y-direction "mx": 1, # Number of processors in the X-direction "my": comm.NumProc() # Number of processors in the Y-direction } map = Galeri.CreateMap("Cartesian2D", comm, pList) Currently input only, no sublists

Linear Solvers and Preconditioners Amesos: –All classes and the Factory are wrapped –You can use KLU, SuperLU, SuperLU_DIST, UMFPACK, MUMPS, DSCPACK, TAUCS, PARDISO within Python AztecOO –AztecOO class is wrapped IFPACK: –All capabilities of the Factory class are wrapped ML: –The MultiLevelPreconditioner class is wrapped; therefore all “stable” ML capabilities can be tested within PyTrilinos –Still missing the support for Maxwell equations

Cross-Language Polymorphism Consider a pure virtual base class such as Epetra_Operator Python “shadow class” is Epetra.Operator (actually Epetra.PyOperator for now) C++ methods and functions that take a Epetra_Operator will expect methods such as Apply(), OperatorRangeMap(), etc, to be implemented Python classes that inherit from Epetra.PyOperator can define Apply(), OperatorRangeMap(), etc. in python Wrapper generator SWIG has “director” feature that directs callbacks between languages Class Epetra.PyRowMatrix also implemented Proceed step-by-step to localize errors

Cross-Language Polymorphism Example from PyTrilinos import Epetra, AztecOO class MyOperator(Epetra.PyOperator): def __init__(self, map): Epetra.PyOperator.__init__(self, map.Comm()) self.__map = map def Apply(*args): LHS = args[1] RHS = args[2] n = RHS.MyLength() RHS[0,0 ] = 2.0 * LHS[0,0 ] - LHS[0,1 ] RHS[0,n-1] = 2.0 * LHS[0,n-1] - LHS[0,n-2] for i in xrange(1, n-1): RHS[0,i] = 2.0 * LHS[0,i] - LHS[0,i-1] - LHS[0,i+1] return 0 def OperatorRangeMap(*args): # First argument is always self self = args[0] return self.__map

Cross-Language Polymorphism, Continued comm = Epetra.PyComm() n = 100 * comm.NumProc() # Scaled problem size map = Epetra.Map(n, 0, comm) op = MyOperator(map) LHS = Epetra.MultiVector(map,1) RHS = Epetra.MultiVector(map,1) # Now create an AztecOO solver, and solve the problem using # the C++ code. Could be done with Epetra_RowMatrix as well. problem = Epetra.LinearProblem(op, LHS, RHS) solver = AztecOO.AztecOO(problem) solver.SetAztecOption(AztecOO.AZ_solver, AztecOO.AZ_cg ) solver.SetAztecOption(AztecOO.AZ_precond, AztecOO.AZ_none) solver.SetAztecOption(AztecOO.AZ_output, 16 ) solver.Iterate(1550, 1e-5) For more examples, see ml/python/examples/exPyOperator.py and exPyRowMatrix.py

Building a More Efficient Epetra.PyOperator C++ code calls a virtual method of Trilinos class Using the SWIG director feature and callback facility, the Trilinos wrapper calls a user-written python method The python method implements a python loop, which is inefficient If efficiency is an issue, you can try slice syntax or use the weave module to have the python method execute compiled C/C++ code Typically see factor of speedup

Building a More Efficient Epetra.PyOperator Using slice syntax: def Apply(*args): LHS = args[1] RHS = args[2] n = RHS.MyLength() RHS[0,0 ] = 2.0 * LHS[0,0 ] - LHS[0,1 ] RHS[0,n-1] = 2.0 * LHS[0,n-1 ] - LHS[0,n-2] RHS[0,1:-1] = 2.0 * LHS[0,1:-1] - LHS[0,:-2] - LHS[0,2:] return 0

Building a More Efficient Epetra.PyOperator Using weave: def Apply(*args): LHS = args[1] RHS = args[2] n = RHS.MyLength() code = “”” RHS[0,0 ] = 2.0 * LHS[0,0 ] - LHS[0,1 ]; RHS[0,n-1] = 2.0 * LHS[0,n-1] - LHS[0,n-2]; for (int i=0; i<n; i++) { RHS[0,i] = 2.0 * LHS[0,i] - LHS[0,i-1] - LHS[0,i+1]; } “”” weave.inline(code, [‘RHS’,’LHS’,’n’], type_converters = weave.converters.blitz) return 0

Speedup Experiment: ( ,  ) #EquationMethodTimeNotes 1AllNaive29.12Baseline 2BCsSlice syntax BCsweave28.90Slice syntax preferable 4  Slice syntax  weave19.20weave preferable 6  weave6.99Slice syntax complicated 7 (u,v)(u,v) Slice syntax (u,v)(u,v) weave1.44More flexible

PyTrilinos Performace vs. MATLAB CPU sec to fill n x n dense matrix CPU sec to fill n x n diagonal matrix CPU sec for 100 MatVecs n MATLABPyTrilinos n MATLABPyTrilinos , , , n MATLABPyTrilinos

PyTrilinos Performance vs. Trilinos Fine-grained script: Course-grained script: n TrilinosPyTrilinos , , ,000,

What Needs to Be Done Handling all methods with C array arguments –SWIG library numeric.i –Package by package, class by class, method by method Treating all array-type objects as Numeric arrays Accepting python dictionaries for parameter lists –(Teuchos::Parameter::List/PyObject) class –Implement everywhere Handling Teuchos::RefCountPtrs transparently Test and example scripts PyTrilinos refactor –Move PyTrilinos classes to Teuchos –Change PyTrilinos to be a “cleanup” package Robustness –Portability, parallelism, advanced features Documentation New Packages…

Some Final Words Python takes the out of programming PyTrilinos allows you to –Play around with Trilinos objects interactively –Quickly develop parallel scripts –Rapidly prototype applications –Glue Trilinos to other packages easily –Developers can write unit tests that cover large parts of the code very quickly SciPy provides tons of scientific computing capabilities Several excellent plotting packages exist Legitimate, free, object-oriented alternative to MATLAB