Great to hear.

Aaron Meurer

On Mon, Oct 28, 2013 at 3:55 AM, Federico Vaggi
<[email protected]> wrote:
> Hey - I'm working on a PR now.  I'll write up some tests too.
>
> Fede
>
> On Friday, 25 October 2013 10:07:46 UTC+2, Øyvind Jensen wrote:
>>
>>
>>
>> On Thursday, October 24, 2013 4:48:36 PM UTC+2, Federico Vaggi wrote:
>>>
>>> Got it.  Thanks for the suggestion.
>>
>>
>> Great! How did you fix it? Would you mind to place pull request?
>>
>>>
>>>
>>> As to the second point - is there a way to determine the order in which
>>> the parameters are referenced in the function?
>>
>>
>> I think you are looking for the 'args' argument of autowrap:
>>
>> >>> help(autowrap)
>> Help on function autowrap in module sympy.utilities.autowrap:
>>
>> autowrap(expr, language='F95', backend='f2py', tempdir=None, args=None,
>> flags=[], verbose=False, helpers=[])
>> <snip>
>>
>>     args
>>         Sequence of the formal parameters of the generated code, if
>> ommited the
>>         function signature is determined by the code generator.
>>
>> Hope this helps.
>>
>> Øyvind
>>
>>
>>>
>>>
>>> The problem I'm dealing with is something like this:
>>>
>>> where sympy_equations are a series of symbolic sympy expressions, that
>>> have a number of parameters and variables.  At each loop iteration, the
>>> underlying optimization routine passes a new parameter vector to the
>>> objective function, so I have to bind the new parameter values to the
>>> equation, create a new lambda, and then pass that to the scipy.odeint
>>> routine
>>>
>>> Pseudocode 1:
>>>
>>> def objective_function(parameter_values):
>>>    bound_equations = sympy_equation.subs(parameter_names,
>>> parameter_values)
>>>    binary_equations = lambdify(variables, bound_equations)
>>>    timeseries_data = scipy.odeint(binary_equations, y0, timesteps)
>>> # binary equation gets called at least 1000 times here
>>>    error = calculate_leastsquares(timeseries_data, experimental_data)
>>> return error
>>>
>>> The issue I ran into is that lambdifying at every cycle iteration is a
>>> huge performance overhead, so it's more efficient to create an executable
>>> function outside of the loop, which takes as input all the variable and
>>> parameters.
>>> Pseudocode 2:
>>>
>>> pars_vars = parameters + variables
>>> binary_equation = lambdify(pars_vars, bound_equations) # Binary function
>>> with all parameters and variables open
>>>
>>> def objective_function(parameter_values):
>>>    partial_bound_fcn = lambda x : binary_equation(*(parameter_vector+x))
>>> # The binary equation called with the parameter vector values for the
>>> parameters
>>>    timeseries_data = scipy.odeint(partial_bound_fcn, y0, timesteps)
>>> # binary equation gets called at least 1000 times here
>>>    error = calculate_leastsquares(timeseries_data, experimental_data)
>>> return error
>>>
>>> This is much faster - but it has obvious speed improvements, since the
>>> parameter values could be bound prior to evaluating the function 1000 values
>>> or so within the integration routine.
>>>
>>> If anyone has advice to speed it up, it's very welcome.
>>>
>>> Did that make much sense?
>>>
>>>
>>>
>>> On Thursday, 24 October 2013 15:14:02 UTC+2, Øyvind Jensen wrote:
>>>>
>>>>
>>>> On Thursday, October 24, 2013 9:45:43 AM UTC+2, Federico Vaggi wrote:
>>>>>
>>>>> https://gist.github.com/FedericoV/7132880 here you go.
>>>>
>>>>
>>>> It looks like the function statment line needs to be continued on
>>>> several lines, and it should be quite easy to fix.
>>>>
>>>> If you look at line 693 of the file sympy/utilities/codegen.py, you'll
>>>> see the method that generates the function/subroutine declaration.
>>>> The fortran printer in sympy/printers/fcode.py has some functionality
>>>> for line wrapping. I'd suggest that you see if you can wrap
>>>> the line by a inserting a function call somewhere in FCodeGen.
>>>>
>>>> Øyvind
>>>>
> --
> 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.

Reply via email to