# Is there an easy way to read a PetscBag into a python dict?

I'm using a PetscBag to store the input parameters of my program. At some point, I'm going to need to use python to plot these parameters against some output parameters, and dicts along with matplotlib seem to be the way to go with this.

Basically, I want to use PetscBagView() or something like it to write a petsc bag to a file, and then use some python thing (built-in part of the standard library, external package especially for this purpose, whatever works) to read it into a dict. The idea is to make it easy to write matplotlib code that plots various input parameters against certain output parameters.

If dicts are the wrong thing to use for plotting the inputs of several simulations against their outputs, what should I use?

Is there an easy way to read a (binary or ascii) serialized PetscBag into python as a dict ?

-
Are you using petsc4py? –  Geoff Oxberry Apr 11 '12 at 17:48
No, I'm just using the C bindings. Does using petsc4py require you to do everything in python, or is it just a python interface in addition to the c/c++/fortran interfaces? –  Dan Apr 11 '12 at 18:59
I think it's a Python API. I don't think it requires you to do everything in Python, although I believe you could use that package to do everything in Python if you wanted to. You'd have to check the web site. AronAhmadia knows more about it than I do. –  Geoff Oxberry Apr 11 '12 at 19:05
There's no Bag object in petsc4py, and it sounds like a rather complicated object to write an interface for. How complicated are your input parameters? –  Aron Ahmadia Apr 11 '12 at 21:56
Lisandro points at the struct module the in the Python standard library. You can check the source code for PetscBagView to get an idea of how to unpack it. I think Matt implemented this functionality so he might have a more complete answer. –  Aron Ahmadia Apr 11 '12 at 22:09