1
1
2
2
function solveTree_X! (dfgl:: AbstractDFG ,
3
3
oldtree:: AbstractBayesTree = emptyBayesTree ();
4
+ timeout:: Union{Nothing, <:Real} = nothing ,
4
5
storeOld:: Bool = false ,
5
6
verbose:: Bool = false ,
7
+ verbosefid= stdout ,
6
8
delaycliqs:: Vector{Symbol} = Symbol[],
7
9
recordcliqs:: Vector{Symbol} = Symbol[],
8
10
limititercliqs:: Vector{Pair{Symbol, Int}} = Pair{Symbol, Int}[],
11
+ injectDelayBefore:: Union {Nothing,Vector{<: Pair{Int,<:Pair{<:Function, <:Real}} }}= nothing ,
9
12
skipcliqids:: Vector{Symbol} = Symbol[],
10
13
maxparallel:: Union{Nothing, Int} = nothing ,
11
14
variableOrder:: Union{Nothing, Vector{Symbol}} = nothing ,
12
15
variableConstraints:: Vector{Symbol} = Symbol[],
13
16
smtasks:: Vector{Task} = Task[],
17
+ dotreedraw = Int[1 ;],
14
18
runtaskmonitor:: Bool = true ,
19
+ algorithm:: Symbol = :default ,
15
20
multithread:: Bool = false )
16
21
#
17
- global dotreedraw
18
22
# workaround in case isolated variables occur
19
23
ensureSolvable! (dfgl)
20
24
opt = getSolverParams (dfgl)
@@ -24,25 +28,28 @@ function solveTree_X!(dfgl::AbstractDFG,
24
28
25
29
# depcrecation
26
30
if maxparallel != = nothing
27
- @warn " maxparallel keyword is deprecated, use getSolverParams(fg).maxincidence instead."
31
+ @warn " ` maxparallel` keyword is deprecated, use ` getSolverParams(fg).maxincidence` instead."
28
32
opt. maxincidence = maxparallel
29
33
end
30
34
31
35
# update worker pool incase there are more or less
32
36
setWorkerPool! ()
33
37
if opt. multiproc && nprocs () == 1
34
- @warn " Cannot use multiproc with only one process, setting `.multiproc=false`. "
38
+ @info " Setting `.multiproc=false` since `Distributed.nprocs() == 1` "
35
39
opt. multiproc = false
36
40
end
37
41
38
42
if opt. graphinit
39
- @info " ensure all initialized (using graphinit)"
43
+ @info " Ensure variables are all initialized (graphinit)"
40
44
ensureAllInitialized! (dfgl)
45
+ if algorithm== :parametric
46
+ @warn " Parametric is using default graphinit"
47
+ initParametricFrom (dfgl)
48
+ end
41
49
end
42
-
43
50
# construct tree
44
51
@info " Solving over the Bayes (Junction) tree."
45
-
52
+
46
53
hist = Dict {Int, Vector{Tuple{DateTime, Int, Function, CliqStateMachineContainer}}} ()
47
54
48
55
if opt. isfixedlag
@@ -66,25 +73,45 @@ function solveTree_X!(dfgl::AbstractDFG,
66
73
orderMethod = 0 < length (variableConstraints) ? :ccolamd : :qr
67
74
68
75
# current incremental solver builds a new tree and matches against old tree for recycling.
69
- tree = wipeBuildNewTree ! (dfgl, variableOrder= variableOrder, drawpdf= opt. drawtree, show= opt. showtree,ensureSolvable= false ,filepath= joinpath (opt. logpath," bt.pdf" ), variableConstraints= variableConstraints, ordering= orderMethod)
76
+ tree = resetBuildTree ! (dfgl, variableOrder= variableOrder, drawpdf= opt. drawtree, show= opt. showtree,ensureSolvable= false ,filepath= joinpath (opt. logpath," bt.pdf" ), variableConstraints= variableConstraints, ordering= orderMethod)
70
77
# setAllSolveFlags!(tree, false)
71
78
72
79
initTreeMessageChannels! (tree)
73
80
74
81
# if desired, drawtree in a loop
75
- treetask, dotreedraw = drawTreeAsyncLoop (tree, opt)
82
+ treetask, _dotreedraw = drawTreeAsyncLoop (tree, opt; dotreedraw = dotreedraw )
76
83
77
84
@info " Do tree based init-inference on tree"
78
- if opt. async
79
- error (" not implemented" )
80
- smtasks = asyncTreeInferUp! (dfgl, tree, oldtree= oldtree, N= opt. N, verbose= verbose, drawtree= opt. drawtree, recordcliqs= recordcliqs, limititers= opt. limititers, downsolve= opt. downsolve, incremental= opt. incremental, skipcliqids= skipcliqids, delaycliqs= delaycliqs, limititercliqs= limititercliqs )
81
- @info " Tree based init-inference progressing asynchronously, check all CSM clique tasks for completion."
82
- else
83
- # smtasks, hist = taskSolveTree_X!(dfgl, tree; alltasks=smtasks, oldtree=oldtree, N=opt.N, verbose=verbose, drawtree=opt.drawtree, recordcliqs=recordcliqs, limititers=opt.limititers, downsolve=opt.downsolve, incremental=opt.incremental, skipcliqids=skipcliqids, delaycliqs=delaycliqs, limititercliqs=limititercliqs, runtaskmonitor=runtaskmonitor )
84
- smtasks, hist = taskSolveTree_X! (dfgl, tree; multithread= multithread, alltasks= smtasks, oldtree= oldtree, verbose= verbose, drawtree= opt. drawtree, recordcliqs= recordcliqs, limititers= opt. limititers, downsolve= opt. downsolve, incremental= opt. incremental, skipcliqids= skipcliqids, delaycliqs= delaycliqs )
85
- @info " Finished tree based init-inference"
85
+
86
+ # choose algorithm
87
+ if algorithm == :parametric
88
+ @error " Under development, do not use, see #539"
89
+ storeOld && @error (" parametric storeOld keyword not wired up yet." )
90
+ initTreeMessageChannels! (tree)
91
+ alltasks, hist = taskSolveTreeParametric! (dfgl, tree; smtasks= smtasks, oldtree= tree, verbose= verbose, drawtree= opt. drawtree, recordcliqs= recordcliqs, limititers= opt. limititers, incremental= opt. incremental, skipcliqids= skipcliqids, delaycliqs= delaycliqs, multithread= multithread )
92
+ @info " Finished tree based Parametric inference"
93
+ elseif true # algorithm == :experimental
94
+ if opt. async
95
+ error (" not implemented" )
96
+ else
97
+ # smtasks, hist = taskSolveTree_X!(dfgl, tree; alltasks=smtasks, oldtree=oldtree, N=opt.N, verbose=verbose, drawtree=opt.drawtree, recordcliqs=recordcliqs, limititers=opt.limititers, downsolve=opt.downsolve, incremental=opt.incremental, skipcliqids=skipcliqids, delaycliqs=delaycliqs, limititercliqs=limititercliqs, runtaskmonitor=runtaskmonitor )
98
+ smtasks, hist = taskSolveTree_X! (dfgl, tree ; multithread= multithread, alltasks= smtasks, oldtree= oldtree, verbose= verbose, drawtree= opt. drawtree, recordcliqs= recordcliqs, limititers= opt. limititers, downsolve= opt. downsolve, incremental= opt. incremental, skipcliqids= skipcliqids, delaycliqs= delaycliqs)
99
+ # smtasks, hist = initInferTreeUp!(dfgl, tree, timeout; alltasks=smtasks, oldtree=oldtree, N=opt.N, verbose=verbose, verbosefid=verbosefid, drawtree=opt.drawtree, recordcliqs=recordcliqs, limititers=opt.limititers, downsolve=opt.downsolve, incremental=opt.incremental, skipcliqids=skipcliqids, delaycliqs=delaycliqs, limititercliqs=limititercliqs, injectDelayBefore=injectDelayBefore, runtaskmonitor=runtaskmonitor)
100
+ @info " Finished tree based init-inference"
101
+ end
102
+ else # fall back is :default
103
+ if opt. async
104
+ smtasks = asyncTreeInferUp! (dfgl, tree, timeout, oldtree= oldtree, N= opt. N, verbose= verbose, verbosefid= verbosefid, drawtree= opt. drawtree, recordcliqs= recordcliqs, limititers= opt. limititers, downsolve= opt. downsolve, incremental= opt. incremental, skipcliqids= skipcliqids, delaycliqs= delaycliqs, limititercliqs= limititercliqs, injectDelayBefore= injectDelayBefore )
105
+ @info " Tree based init-inference progressing asynchronously, check all CSM clique tasks for completion."
106
+ else
107
+
108
+ smtasks, hist = initInferTreeUp! (dfgl, tree, timeout; alltasks= smtasks, oldtree= oldtree, N= opt. N, verbose= verbose, verbosefid= verbosefid, drawtree= opt. drawtree, recordcliqs= recordcliqs, limititers= opt. limititers, downsolve= opt. downsolve, incremental= opt. incremental, skipcliqids= skipcliqids, delaycliqs= delaycliqs, limititercliqs= limititercliqs, injectDelayBefore= injectDelayBefore, runtaskmonitor= runtaskmonitor)
109
+
110
+ @info " Finished tree based init-inference"
111
+ end
86
112
end
87
-
113
+
114
+
88
115
# NOTE copy of data from new tree in to replace outisde oldtree
89
116
oldtree. bt = tree. bt
90
117
oldtree. btid = tree. btid
@@ -104,8 +131,7 @@ function solveTree_X!(dfgl::AbstractDFG,
104
131
105
132
# if debugging and not async then also print the CSMHistory
106
133
if opt. dbg && ! opt. async
107
- # FIXME
108
- # printCliqHistorySequential(hist, joinLogPath(dfgl,"HistoryCSMAll.txt") )
134
+ printCliqHistorySequential (hist, nothing , joinLogPath (dfgl," HistoryCSMAll.txt" ) )
109
135
end
110
136
111
137
return oldtree, smtasks, hist
@@ -127,10 +153,7 @@ function taskSolveTree_X!(dfg::AbstractDFG,
127
153
alltasks = Task[])
128
154
#
129
155
# revert :downsolved status to :initialized in preparation for new upsolve
130
- # TODO JT die ene lyk reg
131
156
resetTreeCliquesForUpSolve! (treel)
132
- # TODO JT needs to be updated
133
- # setTreeCliquesMarginalized!(dfg, treel)
134
157
135
158
drawtree ? drawTree (treel, show= true , filepath= joinpath (getSolverParams (dfg). logpath," bt.pdf" )) : nothing
136
159
@@ -140,6 +163,9 @@ function taskSolveTree_X!(dfg::AbstractDFG,
140
163
141
164
resize! (alltasks, getNumCliqs (treel))
142
165
166
+ approx_iters = getNumCliqs (treel)* 20
167
+ solve_progressbar = ProgressUnknown (" Solve Progress: approx max $approx_iters , at iter" )
168
+
143
169
if ! isTreeSolved (treel, skipinitialized= true )
144
170
@sync begin
145
171
monitortask = IIF. monitorCSMs (treel, alltasks)
@@ -148,9 +174,9 @@ function taskSolveTree_X!(dfg::AbstractDFG,
148
174
scsym = getCliqFrontalVarIds (getClique (treel, i))
149
175
if length (intersect (scsym, skipcliqids)) == 0
150
176
if multithread
151
- alltasks[i] = Threads. @spawn tryCliqStateMachineSolve_X! (dfg, treel, i, oldtree= oldtree, verbose= verbose, drawtree= drawtree, limititers= limititers, downsolve= downsolve, incremental= incremental, delaycliqs= delaycliqs, recordcliqs= recordcliqs)
177
+ alltasks[i] = Threads. @spawn tryCliqStateMachineSolve_X! (dfg, treel, i, oldtree= oldtree, verbose= verbose, drawtree= drawtree, limititers= limititers, downsolve= downsolve, incremental= incremental, delaycliqs= delaycliqs, recordcliqs= recordcliqs, solve_progressbar = solve_progressbar )
152
178
else
153
- alltasks[i] = @async tryCliqStateMachineSolve_X! (dfg, treel, i, oldtree= oldtree, verbose= verbose, drawtree= drawtree, limititers= limititers, downsolve= downsolve, incremental= incremental, delaycliqs= delaycliqs, recordcliqs= recordcliqs)
179
+ alltasks[i] = @async tryCliqStateMachineSolve_X! (dfg, treel, i, oldtree= oldtree, verbose= verbose, drawtree= drawtree, limititers= limititers, downsolve= downsolve, incremental= incremental, delaycliqs= delaycliqs, recordcliqs= recordcliqs, solve_progressbar = solve_progressbar )
154
180
end
155
181
end # if
156
182
end # for
@@ -159,6 +185,8 @@ function taskSolveTree_X!(dfg::AbstractDFG,
159
185
160
186
# if record cliques is in use, else skip computational delay
161
187
0 == length (recordcliqs) ? nothing : fetchCliqHistoryAll! (alltasks, cliqHistories)
188
+
189
+ finish! (solve_progressbar)
162
190
163
191
return alltasks, cliqHistories
164
192
end
@@ -174,7 +202,8 @@ function tryCliqStateMachineSolve_X!(dfg::G,
174
202
downsolve:: Bool = false ,
175
203
incremental:: Bool = false ,
176
204
delaycliqs:: Vector{Symbol} = Symbol[],
177
- recordcliqs:: Vector{Symbol} = Symbol[]) where G <: AbstractDFG
205
+ recordcliqs:: Vector{Symbol} = Symbol[],
206
+ solve_progressbar= nothing ) where G <: AbstractDFG
178
207
#
179
208
clst = :na
180
209
cliq = getClique (treel, cliqKey) # treel.cliques[cliqKey]
@@ -195,7 +224,7 @@ function tryCliqStateMachineSolve_X!(dfg::G,
195
224
drawtree= drawtree, verbose= verbose,
196
225
limititers= limititers, downsolve= downsolve,
197
226
recordhistory= recordthiscliq, incremental= incremental,
198
- delay= delaythiscliq, logger= logger )
227
+ delay= delaythiscliq, logger= logger, solve_progressbar = solve_progressbar )
199
228
#
200
229
# cliqHistories[cliqKey] = history
201
230
if length (history) >= limititers && limititers != - 1
0 commit comments