New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrapper class 'integrate.complex_ode' does not accept function parameters (Trac #1451) #1976
Comments
trac user borishim wrote on 2012-03-20 After a quick reading of the source code, I think that to fix this, a major lifting in the f2py interface is required, and all integrators needs to be fixed separately. For example, for the dopri5 integrator, additional arguments will not work even for real valued problems. For the workaround, functools.partial or lambda can be used in place of the generator, although performance hits might be experienced:
I actually am starting to think that the entire rewritting of set_f_params() method in terms of functools.partial could be a better design decision, considering that the target function is a python function after all. |
Another report, on stackoverflow: http://stackoverflow.com/questions/34577870/using-scipy-integrate-complex-ode-instead-of-scipy-integrate-ode |
It seems like this issue is still not fixed! Why is the wrapper implemented in such a complicated way? All that should be needed here is This approach also avoids unnessecary copying of input arrays. Error messeges could also be more helpful. In two different use-cases I got:
Edit: Minimally |
This behaviour seems like it could be integrated into If someone more experienced with scipy development could give their thoughts, I'm happy to make a PR. Depending on feedback this would be:
|
I am pretty sure the Since def real_func(t,y,complex_func,args):
return complex_func(t,y.view(np.complex128),*args).view(np.float64) I forget the order of the arguments, but this hopefully is clear. Also, do not forget to switch the access to the solution of the solver from |
Looking at this, it actually seems to be a f2py bug. It does not appear
to correctly handle the `f(t, y, *args)` variable-argument construction
in callbacks with extra arguments, as you can see also with `ode`:
```
from scipy import integrate
def f(t, y, *args):
return 0*y
solver = integrate.ode(f)
solver.set_integrator('vode')
solver.set_f_params(1) # <- works, if you comment this out
solver.set_initial_value([0, 0], 0)
while solver.successful() and solver.t < 1:
solver.integrate(1, step=1)
```
It's possible to work around this in complex_ode by hooking
`complex_ode.set_f_params` to set an attribute on `self`, and not use `*args` in
the wrapper routines. The f2py bug itself is a bit nastier to fix.
Adding the workaround would be fine.
Regarding using `np.asarray(x, np.complex128).view(np.float64)` for
unraveling, and more extensive refactoring --- the former is simple
change that can be made. The latter probably changes the API, and can't
be made.
|
Agreed complex_ode doesn't really do much and isn't really essential. However, unfamiliar users may well decide to use
They are? Where can I see this?
I'll submit a PR for |
Original ticket http://projects.scipy.org/scipy/ticket/1451 on 2011-06-01 by trac user gideon, assigned to unknown.
Hi,
I have tried to use 'integrate.complex_ode' in conjunction with integrator.set_f_params(*args). I consistently get the message:
"'float' object is not subscriptable" (or 'int' or 'complex' depending on the parameters passed). This happens whether *args is one parameter or a list. Error seems to be in :
The wrapper complex_ode seems to work fine without trying to pass any additional function parameters.
Code to show problem:
I am running:[[BR]]
*IPython 0.10.1
Thanks[[BR]]
-Gideon
The text was updated successfully, but these errors were encountered: