Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-09-12 Thread Frédéric Bastien
Hi, When you tell 5x and 25x faster, what do you time? Fred On Wed, Sep 11, 2013 at 7:51 PM, Guy Parsey wrote: > Hello, > Due to an up coming conference and a need to get my code in a working > state, I have taken a brute force approach which seems to be working pretty > well (I am in the mid

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-09-12 Thread Guy Parsey
Hey Fred, It is probably an over simplified version of timing. I am using the iPython timeit routine while calling the numerically implemented functions (either the sympy.lambdify created function or my wrapped function) with some example numerical input. I am planning on using the created funct

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-09-11 Thread Guy Parsey
Hello, Due to an up coming conference and a need to get my code in a working state, I have taken a brute force approach which seems to be working pretty well (I am in the middle of testing it). I am very much interested in working with Matt's advice on building up the ODE function from Theano v

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-09-10 Thread Frédéric Bastien
Hi, I was in vacation. Have you been able to make this work? Fred Le 22 août 2013 18:30, "Matthew Rocklin" a écrit : > Looking at your code it's difficult for me to see what you're doing with > the cache. It looks like you're trying to fill it with a particular value > so that SymPy's theano_f

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Matthew Rocklin
Looking at your code it's difficult for me to see what you're doing with the cache. It looks like you're trying to fill it with a particular value so that SymPy's theano_function call latches onto something you've already built. Instead, I recommend that you use theano_code, to transform individu

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Guy Parsey
That is precisely what I don't understand. In your example we are neglecting to give the function all of its inputs and the error message: MissingInputError: ('An input of the graph, used to compute Elemwise{add,no_inplace}(x, y), was not provided and not given a value', y) is saying that we h

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Matthew Rocklin
Here is a printout of the error message: MissingInputError: ('An input of the graph, used to compute TheanoInterpWrapOp.theanointerp(y), was not provided and not given a value', y) What this says is that some nodes in your graph (TheanoInterpWrapOp.theanointerp(y),) weren't given access to all of

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Guy Parsey
Correction (independent of testing the theano op), 's' is a simple wrapper to the spline function, it is not the sympy wrapper. the sympy wrapper is K and can be evaluated as In [17]: K._imp_(4.0) Out[17]: array(16.0) On Thursday, August 22, 2013 5:44:35 PM UTC-4, Guy Parsey wrote: > > Hey Matt,

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Guy Parsey
Hey Matt, I am pretty sure that I have tested the theano Op separately from Sympy, but again, I am probably missing something silly. After running the test cases, or evaluating k = TestInterpOp() k.CreateSuite() from the SymPy_Theano_KGM_indep.py file, one can run the following lines In [2]:

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Matthew Rocklin
Have you tested your interpolation op in isolation from SymPy? A quick glance at the error (quick glance means I can easily be wrong) leads me to think that this particular issue is localized within the domain of Theano. If this is the case then I recommend asking about your spline op on the thea

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-22 Thread Guy Parsey
Hello again everyone, I thought I understood everything I needed to implement a theano Op wrapping a scipy spline function through theanocode, but have been promptly proven wrong (and was on a small family vacation). Firstly, many thanks for the modifications done to theanocode to allow for Pie

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-09 Thread Guy Parsey
Hey Matt et al., Between the responses (and code updates) from Fred, Jason and yourself, all of my present questions have been answered. Now I just need to get more familiar with Theano. I was quick to assume that I would understand all of the printer code, but at least now it is all beginning t

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-09 Thread Matthew Rocklin
Hi Guy, Thanks again for raising these issues. This is the status as I see it 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

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-09 Thread Matthew Rocklin
A draft for a SymPy CCode op is here https://github.com/Theano/Theano/pull/1486 On Thu, Aug 8, 2013 at 10:20 PM, Frédéric Bastien wrote: > For your codegen.py example, it is easy to reuse it manually in a Theano > Op. A good example is to look at the GpuEye op (and just pretend the the > GPU

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Frédéric Bastien
For your codegen.py example, it is easy to reuse it manually in a Theano Op. A good example is to look at the GpuEye op (and just pretend the the GPU kernel is a CPU one). I don't know of a simpler CPU example that demonstrate that: https://github.com/Theano/Theano/blob/master/theano/sandbox/cuda/

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Matthew Rocklin
@Fred, what easy things can we do on the Theano side to support performant scalar codes? Your two tricks above were impressive. How can we make this behavior default? Should this happen on the SymPy side or the Theano side (Theano side seems better if there is a place for it). On Thu, Aug 8, 2

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Aaron Meurer
On Thursday, August 8, 2013, Matthew Rocklin wrote: > > It should be simple to translate SymPy.Piecewise to a recursive >>> Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get >>> on this soon. Does this sound reasonable to you Fred? >>> >> >> It sound reasonable and is the f

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Matthew Rocklin
PR for Theano-Piecewise https://github.com/sympy/sympy/pull/2366 On Thu, Aug 8, 2013 at 3:54 PM, Matthew Rocklin wrote: > > It should be simple to translate SymPy.Piecewise to a recursive >>> Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get >>> on this soon. Does this s

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Matthew Rocklin
> It should be simple to translate SymPy.Piecewise to a recursive >> Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get >> on this soon. Does this sound reasonable to you Fred? >> > > It sound reasonable and is the first thing I suggest to try. > Working on this now. > SymPy

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Frédéric Bastien
On Thu, Aug 8, 2013 at 1:19 PM, Matthew Rocklin wrote: > Ok, Just went through this thread again. > > It should be simple to translate SymPy.Piecewise to a recursive > Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get > on this soon. Does this sound reasonable to you Fred?

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Frédéric Bastien
On Wed, Aug 7, 2013 at 11:37 AM, Guy Parsey wrote: > Hey Fred, > I am starting to play with making a theano.Op, and in principle, linking a > custom theano.Op to an implemented sympy function will solve all of my > problems (at least in the sense of getting my system running, not > necessarily sp

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Matthew Rocklin
After looking around I think I'm looking for the codegen routine. On Thu, Aug 8, 2013 at 2:28 PM, Ondřej Čertík wrote: > On Thu, Aug 8, 2013 at 11:24 AM, Aaron Meurer wrote: > > On Thu, Aug 8, 2013 at 11:19 AM, Matthew Rocklin > wrote: > >> Ok, Just went through this thread again. > >> > >> It

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Ondřej Čertík
On Thu, Aug 8, 2013 at 11:24 AM, Aaron Meurer wrote: > On Thu, Aug 8, 2013 at 11:19 AM, Matthew Rocklin wrote: >> Ok, Just went through this thread again. >> >> It should be simple to translate SymPy.Piecewise to a recursive >> Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll g

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Jason Moore
On Thu, Aug 8, 2013 at 1:19 PM, Matthew Rocklin wrote: > Ok, Just went through this thread again. > > It should be simple to translate SymPy.Piecewise to a recursive > Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get > on this soon. Does this sound reasonable to you Fred?

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Aaron Meurer
On Thu, Aug 8, 2013 at 11:19 AM, Matthew Rocklin wrote: > Ok, Just went through this thread again. > > It should be simple to translate SymPy.Piecewise to a recursive > Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get on > this soon. Does this sound reasonable to you Fred?

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-08 Thread Matthew Rocklin
Ok, Just went through this thread again. It should be simple to translate SymPy.Piecewise to a recursive Theano.switch (after translating SymPy.LT to theano.lt, etc.) I'll get on this soon. Does this sound reasonable to you Fred? Jason's PR allowing pass through of keyword arguments looks close

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-07 Thread Guy Parsey
Hey Fred, I am starting to play with making a theano.Op, and in principle, linking a custom theano.Op to an implemented sympy function will solve all of my problems (at least in the sense of getting my system running, not necessarily speed). My initial post spoke of both mapping Piecewise and i

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Matthew Rocklin
Thanks Guy and Jason for starting this conversation and thanks Fred for jumping in with Theano expertise. I'm out camping in Wisconsin this week but should be available starting Thursday. I'm excited to help contribute to this machinery. On Aug 6, 2013 12:36 PM, "Frédéric Bastien" wrote: > > >

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Frédéric Bastien
On Tue, Aug 6, 2013 at 11:04 AM, Guy Parsey wrote: > Hello, > > Theano/Sympy questions > Fred, in terms of replacing sympy.Pieceiwse with a Theano equivalent, > since sympy.Piecewise attempts each condition (from ExprCondPair) until one > is valid, I would think that the closest equivalent would

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Frédéric Bastien
Hi, I used 2 "tricks" to speed up the Theano version. I made a PR to your repo with this. First Theano is strongly typed. You where passed numpy scalar (numpy.float64) as input, but the theano variable where representing numpy.ndarray. Changing the input to pass numpy.ndarray (of 0 dimensions) cha

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Frédéric Bastien
You can just use the corresponding ndarray with its value. Theano will convert it to a constant. To explicitly make a constant, you can call theano.tensor.constant(a_ndarray_or_python_object). I don't know enought about theano_function(), but can you make a SymPy constant and maybe it will convert

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Jason Moore
How do you specify which values are constants and which aren't? I do pass in a lot of constants and they should be hard coded in C if possible (or some other way to make them available). Jason moorepants.info +01 530-601-9791 On Tue, Aug 6, 2013 at 11:53 AM, Frédéric Bastien wrote: > About t

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Frédéric Bastien
About the benchmark, the problem is a known one, Theano isn't very fast to parse Theano input. In your case, it is this parsing that take the most time in theano when n is small. But when n increase, Theano is faster then lambdify: n = 1 The derivation took 0.154258966446 seconds. Running with the

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Jason Moore
Guy, I don't know enough about the details of the codegen module, but theoretically there should be a mapping from sympy functions to a c-code equivalent that you can add and/or override. It is just a matter of getting real familiar with the code gen modules. You may want to check out https://git

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Guy Parsey
Addon to the Codegen section: With the example above of having an implemented function in some expression in sympy, assuming one can write the c-code equivalent, how would one link the c-code to the codegen process as opposed to having codegen generate it? Cheers, Guy On Tuesday, August 6, 2013

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Guy Parsey
Hello, Theano/Sympy questions Fred, in terms of replacing sympy.Pieceiwse with a Theano equivalent, since sympy.Piecewise attempts each condition (from ExprCondPair) until one is valid, I would think that the closest equivalent would be a recursive theano ifelse (ie. sympy.Piecewise((expr1,cond

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Jason Moore
You'll need this patch: https://github.com/sympy/sympy/pull/2358 to run my code and you need theano latest dev version. Jason moorepants.info +01 530-601-9791 On Tue, Aug 6, 2013 at 9:37 AM, Jason Moore wrote: > Fred, > > I think on_used_input=ignore should be a default in Matthew's theano >

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Jason Moore
Fred, I think on_used_input=ignore should be a default in Matthew's theano printing code or that arg needs to be pushed up to his layer. I hit that issue too. The code I have is here: https://github.com/PythonDynamics/pydy-code-gen See the results.txt file for basic speed comparisons. I'm genera

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-06 Thread Frédéric Bastien
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 co

Re: [sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-05 Thread Jason Moore
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 t

[sympy] Theano + Sympy for system of ODEs: Mapping dictionary issue and a few questions

2013-08-05 Thread Guy Parsey
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