Hi, I don't know what is sympy.functions.elementary.piecewise. Do Jason answered that part? If not, I'll look into it to know how to make Theano reproduce it. About converting any Sympy symbol to Theano symbol, when there isn't a one to one matching, you can create a one to a full Theano graph conversion. When this is possible, it is probably the best, as if you make a new Theano op, it work work on the GPU. But if you make a Theano graph, there is good change that the graph will already work on the GPU.
If it is not possible to make a Theano graph for a sympy symbol, it is possible to make a new Theano op that just wrap the sympy implementation. Also, if this is a bottleneck, I recently added an example that show how to use numba with Theano so speed up the python code in a Theano op. Theano do not parallelize on the CPU, except for the call to BLAS, when the BLAS library is parallel. On the GPU, it is parallel. Having on_unused_input=ignore is normal for complicated generated code. That is why it was added. But when the code is simpler and not generated, but all user manually coded, most of time it mean the user didn't do what he wanted. If you know it is normal that you have unused input, there is no problem to use that flag. Jason, about the case where Theano is slower, can you send me the Theano code? I would like to look at it. I'm very surprised that Theano is slower then Sympy in this case and would like to know why it is like this. Fred On Mon, Aug 5, 2013 at 9:03 PM, Jason Moore <[email protected]> wrote: > Guy, > > We're working on the same problem for sympy.physics.mechanics. Matthew > Rocklin added support for matrix conversions in the theano code that is in > SymPy and I used that, but found that theano was slower that lambdify for > most of my cases (I only have two cores, so I'm not taking advantage of the > Theano parallel stuff). I think writing specific code gen for ode > integration is going to be the best bet. I'm happy to collaborate on this > with you. > > > Jason > moorepants.info > +01 530-601-9791 > > > On Mon, Aug 5, 2013 at 3:13 PM, Guy Parsey <[email protected]> wrote: > >> Hello Everyone, >> Thank you in advance for reading through my problem and for any input you >> may have. I must say that I still feel like a novice programmer and my >> problems may be easily solvable from a different mindset. My present >> project entails time-integration of extremely stiff and non-linear ODEs >> with regards to chemical kinetics (one derivative equation for each >> variable species) and energy equations. Initially we were planning on using >> the sympy.lambdify function to create callable functions for the main >> function along with the jacobian and passing said functions to >> scipy.integrate.odeint, however this method only works for easier test >> cases (fewer species and/or no energy equations) before being limited by >> either the list recursion limit or segfaulting due to the limited stack >> size. I know that both of these limits can be edited, but that fact that I >> am reaching them makes me feel as though I am doing something extremely >> inefficiently. Outside of the documentation of SymPy and Theano, I have >> also been heavily using the BlogPost by Matthew Rocklin >> http://matthewrocklin.com/blog/work/2013/03/19/SymPy-Theano-part-1/ . >> >> Presently I am trying to use the mapping between Theano and SymPy >> (sympy.printing.theanocode theano_function) to make my callable functions >> and take advantage of the optimization routines. I have two major problems >> and a few questions: >> >> 1st major problem: Though piecewise functions exist in SymPy >> (sympy.functions.elementary.piecewise) there is no counterpart in Theano. >> Looking at the source of the inspiration for theanocode ( >> https://github.com/nouiz/theano_sympy/ graph_translation.py) I see >> that some of the SymPy equivalents were defined as lambda functions. Is >> there an equivalent way to add Theano conditional expressions wrapped into >> a function to add to the mapping dictionary in theanocode.py? >> >> 2nd major problem: Similar to the problem above in that I am not sure >> that the Theano counterpart is; some of the terms that I use are >> interpolated functions (with one ODE variable as input) that we have >> wrapped symbolically while providing a numerical implementation (so that >> symbolic derivatives can be made, resulting in their own interpolations). >> Is it possible to recreate the interpolation function as a Theano operation >> for use within the system of ODEs? >> >> Remain questions: >> I presently have to flatten my input to theano_function to a list of >> expressions and then wrap to return to a form (Jacobian is a matrix not a >> vector); is it possible to have a matrix of different expressions as an >> input to theano_function with a vector output? >> >> I know that a huge amount of Theano speed up is due to parallelization of >> matrix operations (which I do not have), should I be focusing on SymPy >> Autowrap/Ufuncify or my own code generation instead of trying to get Theano >> to play nicely? >> >> Stupid questions: >> Does sympy.printing.theanocode.theano_function automatically optimize the >> compiled graph? >> >> Minor comment: >> Perhaps unnecessary for most uses of the theano_function, but I needed to >> modify function inputs so as to be able to use the keyword argument >> 'on_unused_input=ignore' as opposed to 'raise' so that I did not need to >> have all symbols in all equations. This may be avoided by having the unused >> symbols somehow (I don't know how) included in each expression. >> >> Thank you again for your time in reading my problems and any potential >> help you may think of. I can attach code if necessary, I just didn't want >> to make my post more confusing. >> Have an excellent day. >> Sincerely, >> Guy Parsey >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/sympy. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
