80 likes | 226 Views
Using PyTrilinos: A Tutorial. Bill Spotz Sandia National Laboratories 2006 Trilinos Users Group Meeting Nov 8, 2006. Outline. Building PyTrilinos (Teuchos & Epetra only) Installing PyTrilinos Getting help for PyTrilinos An interactive exploration of Epetra Parameter lists
E N D
Using PyTrilinos:A Tutorial Bill Spotz Sandia National Laboratories 2006 Trilinos Users Group Meeting Nov 8, 2006
Outline • Building PyTrilinos (Teuchos & Epetra only) • Installing PyTrilinos • Getting help for PyTrilinos • An interactive exploration of Epetra • Parameter lists • Writing scripts to solve problems
Building PyTrilinos • Configure script: • Take a working configure script, and just add --enable-python • For our purposes, restrict to Teuchos and Epetra: --disable-default-packages \ --enable-teuchos \ --enable-epetra • You may need to be explicit about the C++ compiler: CXX=g++ • Think about where you want to install: --prefix=PREFIX • Building • Invoking configureandmake should do the trick…
Installing PyTrilinos • Install command: $ [sudo] make install • If no prefix specified, then PyTrilinos is installed where your python knows to find it • If you specified prefix, then you need to tell python how to find the PyTrilinos package: • Environment variables: LD_LIBRARY_PATH=PREFIX/lib PYTHONPATH=PREFIX/lib/python2.4/site-packages • Within python (e.g. .pythonrc): import sys sys.path.append("PREFIX/lib/python2.4/site-packages") • Try it: $ python >>> from PyTrilinos import Epetra
Getting Help • From shell: $ pydoc PyTrilinos • From python: $ python >>> from PyTrilinos import Epetra >>> help(Epetra) >>> dir(Epetra) • From web site: • FAQ • Overview • Release 7.0 (including tutorial) • Development (including tutorial) • Trilinos doxygen pages • Submitting bugs: • Under bugzilla, submit to the appropriate Trilinos package, specifying the “Python wrappers” component
Exploring Epetra Interactively • Communicators • Printing Epetra objects • Maps • C-arrays as return objects • Vectors • NumPy hybrids • MultiVectors • CrsMatrix objects
Parameter Lists • Old school: >>> from PyTrilinos import Teuchos >>> pList = Teuchos.ParameterList() >>> pList.set("one", 1) >>> . . . • Python dictionaries can be used in place of ParameterLists: • Keys must be strings • Values must be bool, int, float, str, or dict (or ParameterList) >>> pList = {"one" : 1, "two" : 2} • Returned ParameterLists are actually PyDictParameterLists
Writing Scripts • Feel free to tackle your own problem • Write a function that returns your favorite Epetra.CrsMatrix • Suggestion: Power method (see software.sandia.gov/ Trilinos/packages/docs/dev/ packages/epetra/doc/html/ index.html) • Alternatively: CG algorithm (from G&vL):