[Trilinos-Users] PyTrilinos Teuchos Array(string,bool)
Coon, Ethan
ecoon at lanl.gov
Mon Sep 21 11:54:53 EDT 2015
Hi all,
I’m hoping to use PyTrilinos to generate ParameterLists, but am having trouble with our need for Array(bool) and Array(string) types. Are these supported? Can they be supported? It seems that everything else works as we need.
Below is an example demonstrating what I get, and attached is a simple script which I would like to work.
Thanks much for your thoughts/comments,
Ethan
[ecoon at --- ~] > ipython
Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21)
Type "copyright", "credits" or "license" for more information.
IPython 2.2.0 -- An enhanced Interactive Python.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import PyTrilinos
In [2]: print PyTrilinos.__version__
12.2
In [3]: import numpy
In [4]: print numpy.__version__
1.9.0
In [5]: my_params = """
<ParameterList name="Main" type="ParameterList">
<ParameterList name="Regions" type="ParameterList">
<Parameter name="my_bool" type="bool" value="true" />
<Parameter name="my_int" type="int" value="3" />
<Parameter name="my_double" type="double" value="3.1" />
<Parameter name="my_string" type="string" value="pi" />
<!--Parameter name="my_bool_array" type="Array(bool)" value="{true,false}" -->
<Parameter name="my_int_array" type="Array(int)" value="{3,4}" />
<Parameter name="my_double_array" type="Array(double)" value="{3.1,3.14159}" />
<!--Parameter name="my_string_array" type="Array(string)" value="{pi,i like pie}" -->
</ParameterList>
</ParameterList>
"""
In [6]: from PyTrilinos import Teuchos
In [7]: reader = Teuchos.XMLParameterListReader()
In [8]: source = Teuchos.StringInputSource(my_params)
In [9]: xmlObj = source.getObject()
In [10]: pList = reader.toParameterList(xmlObj)
In [11]: print pList
{'Regions': {'my_double_array': array([ 3.1 , 3.14159]), 'my_int': 3, 'my_bool': True, 'my_int_array': array([3, 4], dtype=int32), 'my_string': 'pi', 'my_double': 3.1}}
In [12]: my_params = """
<ParameterList name="Main" type="ParameterList">
<ParameterList name="Regions" type="ParameterList">
<Parameter name="my_bool" type="bool" value="true" />
<Parameter name="my_int" type="int" value="3" />
<Parameter name="my_double" type="double" value="3.1" />
<Parameter name="my_string" type="string" value="pi" />
<!--Parameter name="my_bool_array" type="Array(bool)" value="{true,false}" -->
<Parameter name="my_int_array" type="Array(int)" value="{3,4}" />
<Parameter name="my_double_array" type="Array(double)" value="{3.1,3.14159}" />
<Parameter name="my_string_array" type="Array(string)" value="{pi,i like pie}" />
</ParameterList>
</ParameterList>
"""
In [13]: source = Teuchos.StringInputSource(my_params)
In [14]: xmlObj = source.getObject()
In [15]: pList = reader.toParameterList(xmlObj)
In [16]: print pList
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-8444d27fed69> in <module>()
----> 1 print pList
/n/swdev/ats/trilinos/trilinos-12.2.1-install/lib/python2.7/site-packages/PyTrilinos/Teuchos.pyc in __str__(self, *args)
5433 an equivalent dictionary.
5434 """
-> 5435 return _Teuchos.ParameterList___str__(self, *args)
5436
5437
/n/swdev/packages/Ubuntu-14.04-x86_64/anaconda-python/2.1.0/lib/python2.7/site-packages/numpy/core/numeric.pyc in array_repr(arr, max_line_width, precision, suppress_small)
1651 if arr.size > 0 or arr.shape==(0,):
1652 lst = array2string(arr, max_line_width, precision, suppress_small,
-> 1653 ', ', "array(")
1654 else: # show zero-length shape unless it is (0,)
1655 lst = "[], shape=%s" % (repr(arr.shape),)
/n/swdev/packages/Ubuntu-14.04-x86_64/anaconda-python/2.1.0/lib/python2.7/site-packages/numpy/core/arrayprint.pyc in array2string(a, max_line_width, precision, suppress_small, separator, prefix, style, formatter)
447 x = _convert_arrays(x)
448 lst = style(x)
--> 449 elif reduce(product, a.shape) == 0:
450 # treat as a null array if any of shape elements == 0
451 lst = "[]"
ValueError: Parameter 'my_string_array' is of unsupported type
In [17]: my_params = """
<ParameterList name="Main" type="ParameterList">
<ParameterList name="Regions" type="ParameterList">
<Parameter name="my_bool" type="bool" value="true" />
<Parameter name="my_int" type="int" value="3" />
<Parameter name="my_double" type="double" value="3.1" />
<Parameter name="my_string" type="string" value="pi" />
<Parameter name="my_bool_array" type="Array(bool)" value="{true,false}" />
<Parameter name="my_int_array" type="Array(int)" value="{3,4}" />
<Parameter name="my_double_array" type="Array(double)" value="{3.1,3.14159}" />
<Parameter name="my_string_array" type="Array(string)" value="{pi,i like pie}" />
</ParameterList>
</ParameterList>
"""
In [18]: source = Teuchos.StringInputSource(my_params)
In [19]: xmlObj = source.getObject()
In [20]: pList = reader.toParameterList(xmlObj)
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
<ipython-input-20-f48bdc85f5fb> in <module>()
----> 1 pList = reader.toParameterList(xmlObj)
/n/swdev/ats/trilinos/trilinos-12.2.1-install/lib/python2.7/site-packages/PyTrilinos/Teuchos.pyc in toParameterList(self, *args)
5916 def toParameterList(self, *args):
5917 """toParameterList(XMLParameterListReader self, XMLObject xml) -> ParameterList"""
-> 5918 return _Teuchos.XMLParameterListReader_toParameterList(self, *args)
5919
5920
SystemError: /n/swdev/ats/trilinos/trilinos-12.2.1-source/packages/teuchos/parameterlist/src/Teuchos_ParameterEntryXMLConverterDB.cpp:85:
Throw number = 11
Throw test that evaluated to true: it == getConverterMap().end()
Can't find converter for parameter entry of type: Array(bool)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://trilinos.org/pipermail/trilinos-users/attachments/20150921/45074a28/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pytrilinos-test.py
Type: text/x-python-script
Size: 931 bytes
Desc: pytrilinos-test.py
URL: <https://trilinos.org/pipermail/trilinos-users/attachments/20150921/45074a28/attachment.bin>
More information about the Trilinos-Users
mailing list