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 ?

  • $\begingroup$ Are you using petsc4py? $\endgroup$ – Geoff Oxberry Apr 11 '12 at 17:48
  • $\begingroup$ 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? $\endgroup$ – Dan Apr 11 '12 at 18:59
  • $\begingroup$ 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. $\endgroup$ – Geoff Oxberry Apr 11 '12 at 19:05
  • $\begingroup$ 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? $\endgroup$ – Aron Ahmadia Apr 11 '12 at 21:56
  • 1
    $\begingroup$ 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. $\endgroup$ – Aron Ahmadia Apr 11 '12 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.