# Some questions on Transducers.jl

**URL:** <https://discourse.julialang.org/t/some-questions-on-transducers-jl/55622>\
**Category:** General Usage\
**Created:** [February 19, 2021, 3:00pm UTC](https://discourse.julialang.org/t/some-questions-on-transducers-jl/55622 "2021-02-19T15:00:24Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [February 20, 2021, 1:05am UTC](https://discourse.julialang.org/t/some-questions-on-transducers-jl/55622/4 "2021-02-20T01:05:14Z")

</div>

Before anything, I think you’d want to check out [DifferentialEquations.jl](https://github.com/SciML/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

```julia
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:

```julia
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`](https://juliafolds.github.io/Transducers.jl/dev/reference/manual/#Transducers.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:

1. 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.
2. Fuse event detection predicate functions in a very efficient manner.
3. 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)

> [@iHany](#):
>
> 1. coding speed

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`](https://juliafolds.github.io/Transducers.jl/dev/reference/manual/#Transducers.Consecutive) in parallel without transducers is very tricky (= very slow coding speed).

> [@iHany](#):
>
> 1. performance of codes

Transducers.jl APIs are fast sometimes and slow sometimes. I’ve been trying to reduce the slow cases but there are always possible improvements.

> [@iHany](#):
>
> 1. advantages

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](https://discourse.julialang.org/t/ann-folds-jl-threaded-distributed-and-gpu-based-high-level-data-parallel-interface-for-julia/54701)

---

_[View the full topic](https://discourse.julialang.org/t/some-questions-on-transducers-jl/55622)._
