Closed
Description
Hi,
Was trying to do something like this with Libtask
:
using Random, Libtask, Distributions
mutable struct Model
t::TArray
n::Int
Model(n::Int) = new(TArray(Float64,n), n)
end
function (model::Model)(rng)
for i in 1:model.n
model.t[i] = rand(rng, Normal())
Libtask.produce(model.t[i])
end
end
Libtask.tape_copy(model::Model) = deepcopy(model)
mode = Model(4)
rng = Random.MersenneTwister()
ttask = Libtask.TapedTask(mode, rng)
new_ttask = copy(ttask)
Libtask.consume(ttask)
Libtask.consume(new_ttask)
but this breaks on a MethodError
MethodError(rand, (nothing, Normal{Float64}(μ=0.0, σ=1.0)), 0x0000000000007a7f)Union{Ptr{Nothing}, Base.InterpreterIP}[Ptr{Nothing} @0x00007f54074c98dc, Ptr{Nothing} @0x00007f54074cfc74, Ptr{Nothing} @0x00007f54074d12d1, Ptr{Nothing} @0x00007f53ad58ff4a, Ptr{Nothing} @0x00007f53ad59004f, Ptr{Nothing} @0x00007f54074d0e59, Ptr{Nothing} @0x00007f53ad59262b, Ptr{Nothing} @0x00007f53ad59289e, Ptr{Nothing} @0x00007f53ad592b7a, Ptr{Nothing} @0x00007f53ad592b8f, Ptr{Nothing} @0x00007f54074d0e59, Ptr{Nothing} @0x00007f54074f529e]
ERROR: LoadError: MethodError: no method matching rand(::Nothing, ::Normal{Float64})
It seems the rng
is not properly populated in new_ttask
. There is no issue if I run the task once before copying:
Libtask.consume(ttask)
new_ttask = copy(ttask)
Libtask.consume(ttask)
Libtask.consume(new_ttask) # The rng error goes away
Am I doing something wrong ? Seems like the copy
shouldn't depend on consume
but again, might be missing something
Metadata
Metadata
Assignees
Labels
No labels