I have a model for which I want to wrap some PyMC around. However, the only way to interface with this model (written in Fortran) is with txt files - I need to write a specific txt file and then have the fortran call that, the ouputs of which get called by my Python (I realize this is not efficient and it is not my final product, but I wanted to get the MCMC figured out before I started dissecting the fortran). I have a lot of experience with pymc2 but am starting brand new with pymc3 and its Theano structures. I have realized that I currently don’t have a good way to write out the value of pymc variables in an individual realization in a string. How would I get that information? Chopped up code of what I want to do can be found below:
rinf = pymc3.Lognormal('rinf',mu = np.log(self.rinf), sd = 0.5*np.log(10)) #
rinf_send = T.cast(rinf,dtype='float64').eval() #not correct, but roughly what I think I am supposed to do
%0.3f RINF """ %(rinf_send)
Can someone help me figure out what that second line is actually supposed to be? I have not had much luck in my searches thus far…
Thank you in advance.
You can have a look at this post: Error in the sampling process, 'sd' not taken in account in Metropolis.py
where @viiv is calling an external code and writing the output to a text file.
Warning: communicating and computing with external code within
pm.Model() could be slow.
Okay, so I see that the the line in their code
is probably what helps with this. I am still getting an error, however, and a more complex use case than this that requires some more follow up. I have the whole MCMC process wrapped up in a Python class (because I have lots of parameters that aren’t part of the MCMC that have to go into the model). I have no intuition as to how this wrapper function can be written to handle other non-Theano inputs. If Theano makes it so difficult to simply print out an individual realization of the tensor values, then I should probably just do what I know needs to be done - decouple the Fortran from txt I/O and get that working as its own module in Python before trying the MCMC.
Okay, so after some investigations into the Fortran code it is going to be way larger and more problematic than I initially anticipated to decouple it from txt I/O. So I need to worry about this again.
New question: The @theano.compile.ops.as_op module requires all inputs to be Theano tensor variables. However, my txt write function needs to send off other non-Theano variables as well. How can I work with this? Mainly what I need is a function that takes both PyMC realization variables and other arguments as inputs to write all of the instantaneous values to a txt file.
Thank you for your help thus far.