49
49
50
50
const LibtaskTrace{R} = AdvancedPS. Trace{<: AdvancedPS.LibtaskModel ,R}
51
51
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
+
52
58
""" Get the RNG from a `LibtaskTrace`."""
53
59
function get_rng (trace:: LibtaskTrace )
54
60
return trace. model. ctask. taped_globals. rng
@@ -75,7 +81,11 @@ get_other_global(trace::LibtaskTrace) = trace.model.ctask.taped_globals.other
75
81
function AdvancedPS. Trace (
76
82
model:: AdvancedPS.AbstractGenericModel , rng:: Random.AbstractRNG , args...
77
83
)
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
79
89
end
80
90
81
91
# step to the next observe statement and
@@ -88,22 +98,12 @@ function AdvancedPS.advance!(trace::LibtaskTrace, isref::Bool=false)
88
98
return Libtask. consume (trace. model. ctask)
89
99
end
90
100
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
-
100
101
# Task copying version of fork for Trace.
101
102
function AdvancedPS. fork (trace:: LibtaskTrace , isref:: Bool = false )
102
103
newtrace = copy (trace)
103
104
set_rng! (newtrace, deepcopy (get_rng (newtrace)))
104
105
isref && AdvancedPS. delete_retained! (newtrace. model. f)
105
106
isref && delete_seeds! (newtrace)
106
- AdvancedPS. addreference! (newtrace)
107
107
return newtrace
108
108
end
109
109
0 commit comments