TuringLang / Libtask.jl

Tape based task copying in Turing
MIT License
17 stars 9 forks source link

Make a CTask struct #64

Closed devmotion closed 4 years ago

devmotion commented 4 years ago

As discussed in https://github.com/TuringLang/Turing.jl/pull/1237, it would be nice to implement the iteration interface for CTask since then it would be possible to use alternatives such as resumable functions in the particle filter implementations in Turing in a straightforward way (currently produce and consume statements are hardcoded). However, currently CTask is just a function that returns a Task for which stack copying has been enabled. Implementing the iteration interface for Task would be pretty bad type piracy (BTW Base.copy(::Task) in the current code is also type piracy). To avoid this I suggest adding a CTask struct that is defined as

struct CTask
    task::Task
end

Then Base.copy and Base.iterate could be implemented without committing type piracy. The downside would be that one would probably have to forward a bunch of methods defined for Task (such istaskstarted etc.) to task.

Do you think I should give it a try, or are there any other suggestions?

yebai commented 4 years ago

yes, I think this is doable, and would be a nice improvement to both Libtask and Turing.

yebai commented 4 years ago

closed by #65