<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 10, 2015 at 3:47 PM, Brian Merchant <span dir="ltr"><<a href="mailto:bhmerchant@gmail.com" target="_blank">bhmerchant@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi Emil:<br><br></div>I had a look at odeint's output --
it seems that while Adams is used initially, bdf is used most often
overall (especially in later timesteps), some 80% of the timesteps in
total.<br><br></div><div>This is likely because I ran the test on the full problem, which includes interactions between multiple amoebas -- contact between amoebas turns certain parameters on temporarily.<br></div><div><br></div><div>Matt: is this the getArray method of petsc4py? It converts a PETSc array to a NumPy array? How did the PETSc array (let's say from a C program) get loaded by petsc4py in the first place -- is there some sort of a "load" function? I am sure there are straightforward answers to this question, but these are the sorts of things I don't know right now. </div></div></div></blockquote><div><br></div><div>The memory is always in one place. The PETSc Vec and NumPy array are just two ways of looking into it.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Kind regards,<br></div>Brian</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 12:55 PM, Emil Constantinescu <span dir="ltr"><<a href="mailto:emconsta@mcs.anl.gov" target="_blank">emconsta@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Brian,<br>
<br>
Can you take a look at what odeint returns? Specifically, at:<br>
<br>
‘mused’ a vector of method indicators for each successful time step: 1: adams (nonstiff), 2: bdf (stiff)<br>
<br>
I suspect it's using Adams all the way, which means it's doesn't need a Jacobian.<span><font color="#888888"><br>
<br>
Emil</font></span><div><div><br>
<br>
<br>
On 12/10/15 1:51 PM, Barry Smith wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Brian,<br>
<br>
I see two distinct issues here<br>
<br>
1) being apply to apply your right hand side efficiently and<br>
<br>
2) what type of ODE integrators, if any, can work well for your problem with its funky, possibly discontinuous right hand side?<br>
<br>
1) Looking at the simplicity of your data structure and function evaluation I think you should just write your right hand side functions in C. The code would be no more complicated than it is now, from what you showed me. Even with "just in time" compilation likely you lose at least a factor of 10 by coding in python, maybe 100? I don't know. It looks to me like an easy translation of your current routines to C.<br>
<br>
2) This is tricky. You a) cannot compute derivatives? and b) the function and derivatives may not be smooth?<br>
<br>
If the function was well behaved you could use finite differences to compute the Jacobian (reasonably efficiently, the cost is just some number of function evaluations) but with a flaky right hand side function the finite differences can produce garbage.<br>
<br>
You could use explicit schemes with a small enough timestep to satisfy any stability condition and forget about using implicit schemes. Then it becomes crucial to have a very fast right hand side function (since you will need many time steps). If you are lucky you can use something like a 4th order RK scheme (but again maybe with a non smooth right hand side may you can't).<br>
<br>
I am no expert. Perhaps Emil who is far more knowledgable about these things has questions?<br>
<br>
Barry<br>
<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Dec 10, 2015, at 12:52 PM, Brian Merchant <<a href="mailto:bhmerchant@gmail.com" target="_blank">bhmerchant@gmail.com</a>> wrote:<br>
<br>
Hi Barry,<br>
<br>
Here's some non-trivial example code: <a href="https://gist.github.com/bmer/2af429f88b0b696648a8" rel="noreferrer" target="_blank">https://gist.github.com/bmer/2af429f88b0b696648a8</a><br>
<br>
I have still made some simplifications by removing some phase variables, expanding on variable names in general, and so on.<br>
<br>
The rhs function itself is defined on line 578. The functions referred to within it should be all defined above, so you can have a peek at them as necessary.<br>
<br>
Starting from line 634 I show how I use the rhs function. In particular, note the "disjointed" evaluation of the integral -- I don't just evaluate from 0 to t all at one go, but rather evaluate the integral in pieces (let's call the time spent between the end of one integral evaluation, and the start of the next integral evaluation a "pause"). This is so that if there were multiple amoebas, during the "pause", I can take into account changes in some of the parameters due to contact between one amoeba and another -- poor man's simplification.<br>
<br>
Please let me know if this is what you were looking for. I wouldn't be surprised if it wasn't, but instead would be happy to try to rework what I've got so it's more in line with what would be meaningful to you.<br>
<br>
Kind regards,<br>
Brian<br>
<br>
On Wed, Dec 9, 2015 at 2:18 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
<br>
I prefer the actual code, not the mathematics or the explanation<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Dec 9, 2015, at 3:42 PM, Brian Merchant <<a href="mailto:bhmerchant@gmail.com" target="_blank">bhmerchant@gmail.com</a>> wrote:<br>
<br>
Hi Barry,<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Could send an example of your "rhs" function; not a totally trivial example<br>
</blockquote>
<br>
Sure thing! Although, did you check out the exam I tried to build up in this stackexchange question, along with a picture: <a href="http://scicomp.stackexchange.com/questions/21501/is-it-worth-switching-to-timesteppers-provided-by-petsc-if-i-cant-write-down-a" rel="noreferrer" target="_blank">http://scicomp.stackexchange.com/questions/21501/is-it-worth-switching-to-timesteppers-provided-by-petsc-if-i-cant-write-down-a</a><br>
<br>
I ask because that's probably the best I can do without using as little math as possible.<br>
<br>
Otherwise, what I'll do is take a couple of days to carefully look at my work, and write up a non-trivial example of a difficult-to-differentiate RHS, that still is a simplification of the whole mess -- expect a one or two page PDF?<br>
<br>
Kind regards,<br>
Brian<br>
<br>
On Mon, Dec 7, 2015 at 12:45 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>> wrote:<br>
<br>
Brian,<br>
<br>
Could send an example of your "rhs" function; not a totally trivial example<br>
<br>
Barry<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Dec 7, 2015, at 11:21 AM, Brian Merchant <<a href="mailto:bhmerchant@gmail.com" target="_blank">bhmerchant@gmail.com</a>> wrote:<br>
<br>
Hi all,<br>
<br>
I am considering using petsc4py instead of scipy.integrate.odeint (which is a wrapper for Fortran solvers) for a problem involving the solution of a system of ODEs. The problem has the potential to be stiff. Writing down its Jacobian is very hard.<br>
<br>
So far, I have been able to produce reasonable speed gains by writing the RHS functions in "something like C" (using either numba or Cython). I'd like to get even more performance out, hence my consideration of PETSc.<br>
<br>
Due to the large number of equations involved, it is already tedious to think about writing down a Jacobian. Even worse though, is that some of the functions governing a particular interaction do not have neat analytical forms (let alone whether or not their derivatives have neat analytical forms), so we might have a mess of piecewise functions needed to approximate them if we were to go about still trying to produce a Jacobian...<br>
<br>
All the toy examples I see of PETSc time stepping problems have Jacobians defined, so I wonder if I would even get a speed gain going from switching to it, if perhaps one of the reasons why I have a high computational cost is due to not being able to provide a Jacobian function?<br>
<br>
I described the sort of problem I am working with in more detail in this scicomp.stackexchange question, which is where most of this question is copied from, except it also comes with a toy version of the problem I am dealing with: <a href="http://scicomp.stackexchange.com/questions/21501/is-it-worth-switching-to-timesteppers-provided-by-petsc-if-i-cant-write-down-a" rel="noreferrer" target="_blank">http://scicomp.stackexchange.com/questions/21501/is-it-worth-switching-to-timesteppers-provided-by-petsc-if-i-cant-write-down-a</a><br>
<br>
All your advice would be most helpful :)<br>
<br>
Kind regards,Brian<br>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</blockquote>
</div></div></blockquote></div><br></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div>
</div></div>