From a8e14be37b05299b8751faf58cd5df68cdb96bdc Mon Sep 17 00:00:00 2001 From: dehann Date: Sun, 15 Dec 2019 21:11:01 -0500 Subject: [PATCH 1/2] double fix for cases similar to #474 --- src/CliqStateMachine.jl | 18 +++++++++++++++--- src/JunctionTree.jl | 8 +++++--- src/SolverAPI.jl | 5 +++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/CliqStateMachine.jl b/src/CliqStateMachine.jl index 8add843db..15a20a466 100644 --- a/src/CliqStateMachine.jl +++ b/src/CliqStateMachine.jl @@ -525,8 +525,8 @@ 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 10 return determineCliqIfDownSolve_StateMachine end @@ -588,13 +588,25 @@ Notes 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 diff --git a/src/JunctionTree.jl b/src/JunctionTree.jl index d6a8ab68c..b4263b4e9 100644 --- a/src/JunctionTree.jl +++ b/src/JunctionTree.jl @@ -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", @@ -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 @@ -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 """ diff --git a/src/SolverAPI.jl b/src/SolverAPI.jl index 6950ca3bf..ce861a9be 100644 --- a/src/SolverAPI.jl +++ b/src/SolverAPI.jl @@ -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}() @@ -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" From 7aad1201e3d62622197353e123df0b70bfa038ff Mon Sep 17 00:00:00 2001 From: dehann Date: Mon, 16 Dec 2019 02:07:42 -0500 Subject: [PATCH 2/2] fix 474 --- src/CliqStateMachine.jl | 15 +++++++++++---- src/TreeBasedInitialization.jl | 5 +++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/CliqStateMachine.jl b/src/CliqStateMachine.jl index 15a20a466..ec800007c 100644 --- a/src/CliqStateMachine.jl +++ b/src/CliqStateMachine.jl @@ -527,8 +527,11 @@ function determineCliqNeedDownMsg_StateMachine(csmc::CliqStateMachineContainer) return attemptCliqInitDown_StateMachine # HALF DUPLICATED IN STEP 4 elseif cliqst == :marginalized + # go to 1 + return isCliqUpSolved_StateMachine + ## NOTE -- what about notifyCliqUpInitStatus! ?? # go to 10 - return determineCliqIfDownSolve_StateMachine + # return determineCliqIfDownSolve_StateMachine end # go to 8b @@ -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 @@ -583,7 +587,7 @@ end $SIGNATURES Notes -- State machine function nr. 4 +- State machine function nr.4 """ function isCliqNull_StateMachine(csmc::CliqStateMachineContainer) @@ -637,6 +641,7 @@ function doesCliqNeeddownmsg_StateMachine(csmc::CliqStateMachineContainer) if cliqst != :null if cliqst != :needdownmsg + # go to 6c return blockCliqSiblingsParentChildrenNeedDown_StateMachine end else @@ -661,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 diff --git a/src/TreeBasedInitialization.jl b/src/TreeBasedInitialization.jl index 7017767bd..a84a62f8a 100644 --- a/src/TreeBasedInitialization.jl +++ b/src/TreeBasedInitialization.jl @@ -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 @@ -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