Before anything, I think you’d want to check out DifferentialEquations.jl universe, if you haven’t.
A short answer for your question is that Tnrasducers.jl is not very beneficial for this type of computation, unless you need to do something very specific.
Having said that, it is certainly possible to use Transducers.jl for this
euler(dyn, y0, dt) = Scan(y0) do y, i
y + dyn(y, i * dt) * dt
end
# e.g., 1:10 |> euler(dyn, 1.0, 0.01) |> collect
or, if you want the input to be the sequence of times:
euler2(dyn, y0, t0) = ScanEmit((y0, t0)) do (y, t_prev), t
dt = t - t_prev
y_next = y + dyn(y, t) * dt
y_next, (y_next, t)
end
# e.g., 0.001:0.01:0.1 |> euler2(dyn, 1.0, 0.0) |> collect
(Side note: you can think of ScanEmit
as a “discrete dynamical system executor”. So, if you can express your simulator as a discrete dynamical system, you can always use ScanEmit
.)
However, I don’t think it is always a good idea to implement this kind of code with Trasudcers.jl, unless you have some specific technical requirements. For example:
- Fuse post-processing of the output of the system you are simulating; e.g., you are interested in a subset of the state variables or you want to filter out some outputs.
- Fuse event detection predicate functions in a very efficient manner.
- Simulating a system that is driven by input data (as in x(t) of dy/dt = f(y(t), x(t), t)) and the input data is stored in a complex data structure (e.g., nested array)
I’m probably the worst person to answer this question, since I designed the API for how I want to code.
But there are things very hard to express without transducers. For example, doing something like Transducers.Consecutive
in parallel without transducers is very tricky (= very slow coding speed).
Transducers.jl APIs are fast sometimes and slow sometimes. I’ve been trying to reduce the slow cases but there are always possible improvements.
I think parallelism is the strongest selling point. Check out [ANN] Folds.jl: threaded, distributed, and GPU-based high-level data-parallel interface for Julia