Skip to content

Commit

Permalink
Merge pull request #482 from JuliaRobotics/fix/4Q19/474
Browse files Browse the repository at this point in the history
missing notification in parent recycling and pass variable order
  • Loading branch information
dehann authored Dec 16, 2019
2 parents 17d73b1 + 7aad120 commit e72fb29
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
33 changes: 26 additions & 7 deletions src/CliqStateMachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,13 @@ function determineCliqNeedDownMsg_StateMachine(csmc::CliqStateMachineContainer)
if cliqst == :needdownmsg && !isCliqParentNeedDownMsg(csmc.tree, csmc.cliq, csmc.logger)
# go to 8a
return attemptCliqInitDown_StateMachine
# HALF DUPLICATED IN STEP 4
elseif cliqst == :marginalized
## Add case for IIF issue #474
# go to 1
return isCliqUpSolved_StateMachine
## NOTE -- what about notifyCliqUpInitStatus! ??
# go to 10
return determineCliqIfDownSolve_StateMachine
# return determineCliqIfDownSolve_StateMachine
end

# go to 8b
Expand All @@ -550,6 +553,7 @@ function blockCliqSiblingsParentChildrenNeedDown_StateMachine(csmc::CliqStateMac
infocsm(csmc, "6c, check/block sibl&prnt :needdownmsg")
blockCliqSiblingsParentNeedDown(csmc.tree, csmc.cliq, logger=csmc.logger)

# go to 7
return determineCliqNeedDownMsg_StateMachine
end

Expand Down Expand Up @@ -583,18 +587,30 @@ end
$SIGNATURES
Notes
- State machine function nr. 4
- State machine function nr.4
"""
function isCliqNull_StateMachine(csmc::CliqStateMachineContainer)

prnt = getParent(csmc.tree, csmc.cliq)
infocsm(csmc, "4, isCliqNull_StateMachine, csmc.incremental=$(csmc.incremental), len(prnt)=$(length(prnt))")
cliqst = getCliqStatus(csmc.oldcliqdata)
infocsm(csmc, "4, isCliqNull_StateMachine, $cliqst, len(prnt)=$(length(prnt)), csmc.incremental=$(csmc.incremental)")

if cliqst in [:marginalized;]
# if cliqst == :marginalized || cliqst in [:downsolved; :uprecycled] && ( length(prnt) == 0 ) # ||
# 0 < length(prnt) && getCliqStatus(prnt) in [:downsolved; :uprecycled; :marginalized;] )
# go to 10 -- Add case for IIF issue #474
return determineCliqIfDownSolve_StateMachine
end

#must happen before if :null
stdict = blockCliqUntilChildrenHaveUpStatus(csmc.tree, csmc.cliq, csmc.logger)
csmc.forceproceed = false

# if clique is marginalized, then no reason to continue here
# if no parent or parent will not update

# for recycle computed clique values case
if csmc.incremental && getCliqStatus(csmc.oldcliqdata) == :downsolved
if csmc.incremental && cliqst == :downsolved
csmc.incremental = false
# might be able to recycle the previous clique solve, go to 0b
return checkChildrenAllUpRecycled_StateMachine
Expand Down Expand Up @@ -625,6 +641,7 @@ function doesCliqNeeddownmsg_StateMachine(csmc::CliqStateMachineContainer)

if cliqst != :null
if cliqst != :needdownmsg
# go to 6c
return blockCliqSiblingsParentChildrenNeedDown_StateMachine
end
else
Expand All @@ -649,9 +666,11 @@ function doesCliqNeeddownmsg_StateMachine(csmc::CliqStateMachineContainer)
return blockCliqSiblingsParentChildrenNeedDown_StateMachine
end # != :null

areChildDown = areCliqChildrenNeedDownMsg(csmc.tree, csmc.cliq)
infocsm(csmc, "4b, areCliqChildrenNeedDownMsg(csmc.tree, csmc.cliq)=$(areChildDown)")
# if cliqst == :needdownmsg
if areCliqChildrenNeedDownMsg(csmc.tree, csmc.cliq)
infocsm(csmc, "4, must deal with child :needdownmsg")
if areChildDown
infocsm(csmc, "4b, must deal with child :needdownmsg")
csmc.forceproceed = true
else
# go to 5
Expand Down
8 changes: 5 additions & 3 deletions src/JunctionTree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ Notes
"""
function prepBatchTree!(dfg::AbstractDFG;
ordering::Symbol=:qr,
variableOrder::Union{Nothing, Vector{Symbol}}=nothing,
drawpdf::Bool=false,
show::Bool=false,
filepath::String="/tmp/caesar/bt.pdf",
Expand All @@ -449,7 +450,7 @@ function prepBatchTree!(dfg::AbstractDFG;
drawbayesnet::Bool=false,
maxparallel::Int=50 )
#
p = getEliminationOrder(dfg, ordering=ordering)
p = variableOrder != nothing ? variableOrder : getEliminationOrder(dfg, ordering=ordering)

# for debuggin , its useful to have the variable ordering
if drawpdf
Expand Down Expand Up @@ -534,10 +535,11 @@ function wipeBuildNewTree!(dfg::G;
filepath::String="/tmp/caesar/bt.pdf",
viewerapp::String="evince",
imgs::Bool=false,
maxparallel::Int=50 )::BayesTree where G <: AbstractDFG
maxparallel::Int=50,
variableOrder::Union{Nothing, Vector{Symbol}}=nothing )::BayesTree where G <: AbstractDFG
#
resetFactorGraphNewTree!(dfg);
return prepBatchTree!(dfg, ordering=ordering, drawpdf=drawpdf, show=show, filepath=filepath, viewerapp=viewerapp, imgs=imgs, maxparallel=maxparallel);
return prepBatchTree!(dfg, variableOrder=variableOrder, ordering=ordering, drawpdf=drawpdf, show=show, filepath=filepath, viewerapp=viewerapp, imgs=imgs, maxparallel=maxparallel);
end

"""
Expand Down
5 changes: 3 additions & 2 deletions src/SolverAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ function solveTree!(dfgl::G,
delaycliqs::Vector{Symbol}=Symbol[],
recordcliqs::Vector{Symbol}=Symbol[],
skipcliqids::Vector{Symbol}=Symbol[],
maxparallel::Int=50 ) where G <: DFG.AbstractDFG
maxparallel::Int=50,
variableOrder::Union{Nothing, Vector{Symbol}}=nothing ) where G <: DFG.AbstractDFG
#
@info "Solving over the Bayes (Junction) tree."
smtasks=Vector{Task}()
Expand All @@ -38,7 +39,7 @@ function solveTree!(dfgl::G,
end

# current incremental solver builds a new tree and matches against old tree for recycling.
tree = wipeBuildNewTree!(dfgl, drawpdf=opt.drawtree, show=opt.showtree, maxparallel=maxparallel, filepath=joinpath(getSolverParams(dfgl).logpath,"bt.pdf"))
tree = wipeBuildNewTree!(dfgl, variableOrder=variableOrder, drawpdf=opt.drawtree, show=opt.showtree, maxparallel=maxparallel, filepath=joinpath(getSolverParams(dfgl).logpath,"bt.pdf"))
# setAllSolveFlags!(tree, false)

@info "Do tree based init-inference on tree"
Expand Down
5 changes: 5 additions & 0 deletions src/TreeBasedInitialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ function blockCliqUntilParentDownSolved(prnt::Graphs.ExVertex; logger=ConsoleLog
with_logger(logger) do
@info "blockCliqUntilParentDownSolved, prntcliq=$(prnt.index) | $lbl | going to fetch initdownchannel..."
end
flush(logger.stream)
while fetch(getData(prnt).initDownChannel) != :downsolved
# @sync begin
# @async begin
Expand Down Expand Up @@ -355,8 +356,12 @@ function blockCliqUntilChildrenHaveUpStatus(tree::BayesTree,
with_logger(logger) do
@info "cliq $(prnt.index), child $(ch.index) status is $(chst), isready(initUpCh)=$(isready(getData(ch).initUpChannel))."
end
flush(logger.stream)
ret[ch.index] = fetch(getData(ch).initUpChannel)
end
with_logger(logger) do
@info "cliq $(prnt.index), fetched all."
end
return ret
end

Expand Down

0 comments on commit e72fb29

Please sign in to comment.