4949
5050const LibtaskTrace{R} = AdvancedPS. Trace{<: AdvancedPS.LibtaskModel ,R}
5151
52+ function Base. copy (trace:: LibtaskTrace )
53+ newtrace = AdvancedPS. Trace (copy (trace. model), deepcopy (trace. rng))
54+ set_other_global! (newtrace, newtrace)
55+ return newtrace
56+ end
57+
5258""" Get the RNG from a `LibtaskTrace`."""
5359function get_rng (trace:: LibtaskTrace )
5460 return trace. model. ctask. taped_globals. rng
@@ -75,7 +81,11 @@ get_other_global(trace::LibtaskTrace) = trace.model.ctask.taped_globals.other
7581function AdvancedPS. Trace (
7682 model:: AdvancedPS.AbstractGenericModel , rng:: Random.AbstractRNG , args...
7783)
78- return AdvancedPS. Trace (AdvancedPS. LibtaskModel (model, rng, args... ), rng)
84+ trace = AdvancedPS. Trace (AdvancedPS. LibtaskModel (model, rng, args... ), rng)
85+ # Set a backreference so that the TapedTask in `trace` stores the `trace` itself in its
86+ # taped globals.
87+ set_other_global! (trace, trace)
88+ return trace
7989end
8090
8191# step to the next observe statement and
@@ -88,22 +98,12 @@ function AdvancedPS.advance!(trace::LibtaskTrace, isref::Bool=false)
8898 return Libtask. consume (trace. model. ctask)
8999end
90100
91- """
92- Set a backreference so that the TapedTask in `trace` stores the `trace` itself in the
93- taped globals.
94- """
95- function AdvancedPS. addreference! (trace:: LibtaskTrace )
96- set_other_global! (trace, trace)
97- return trace
98- end
99-
100101# Task copying version of fork for Trace.
101102function AdvancedPS. fork (trace:: LibtaskTrace , isref:: Bool = false )
102103 newtrace = copy (trace)
103104 set_rng! (newtrace, deepcopy (get_rng (newtrace)))
104105 isref && AdvancedPS. delete_retained! (newtrace. model. f)
105106 isref && delete_seeds! (newtrace)
106- AdvancedPS. addreference! (newtrace)
107107 return newtrace
108108end
109109
0 commit comments