[Trilinos-Users] Re: ParameterList XML files

Bill Spotz wfspotz at sandia.gov
Thu May 3 14:34:15 MDT 2007


At the request of Ross Bartlett, I have made an addition to the XML  
capabilities in PyTrilinos.  If you  install PyTrilinos, you now get  
a script named ParamConvert.py installed as an executable as well.   
You can use this script to convert files between XML and python  
dictionary representations of Teuchos ParameterLists.  The direction  
of the conversion is dictated by the extension of the input file:

   $ ParamConvert.py params.xml

will produce params.py with a python dictionary that corresponds to  
the ParameterList described by params.xml.  Likewise,

   $ ParamConvert.py params.py

would create params.xml.  You can also specify the output file name  
explicitly.  The main benefit of this script is that you can convert  
an XML file to python, edit the easier-to-read python file, and then  
convert the python file back to XML.

To get this to work, I had to add the following classes to  
PyTrilinos.Teuchos: XMLInputSource, FileInputSource and  
StringInputSource.

On Apr 23, 2007, at 1:25 PM, Bill Spotz wrote:

> Trilinos users,
>
> I wanted to drop a note to let people know that I have added  
> support for classes XMLObject, XMLParameterListWriter and  
> XMLParameterListReader to the PyTrilinos module Teuchos.  Thus, if  
> you build PyTrilinos, you can write scripts for building and  
> maintaining ParameterList XML files such as the following:
>
>   from PyTrilinos import Teuchos
>   params = { "precond"  : "IC",
>              "maxiters" : 100,
>              "tol"      : 1.0e-6 }
>   xmlObj = Teuchos.XMLParameterListWriter().toXML(params)
>   open("params.xml","w").write(xmlObj.toString())
>
> This script produces params.xml:
>
>   <ParameterList>
>   <Parameter name="maxiters" type="int" value="100"/>
>   <Parameter name="precond" type="string" value="IC"/>
>   <Parameter name="tol" type="double" value="1e-06"/>
>   </ParameterList>
>
> The advantages are:
>
>   (1) You don't have to compile a program.
>   (2) You can use python's elegant dictionary syntax.
>   (3) You can avoid editing XML directly.
>
> for more information, see
>
>   http://software.sandia.gov/Trilinos/packages/pytrilinos/ 
> development/Teuchos.html
>
> This capability has been added to the development branch (for those  
> who have access to it) and will be a part of release 8.0.

** Bill Spotz                                              **
** Sandia National Laboratories  Voice: (505)845-0170      **
** P.O. Box 5800                 Fax:   (505)284-5451      **
** Albuquerque, NM 87185-0370    Email: wfspotz at sandia.gov **




More information about the Trilinos-Users mailing list