Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code maintenance toward #913 #921

Merged
merged 3 commits into from
Sep 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions src/CliqStateMachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1654,65 +1654,6 @@ end



## ==============================================================================================
# Launch the FSM
## ==============================================================================================

"""
$SIGNATURES

Perform upward inference using a state machine solution approach.

Notes:
- will call on values from children or parent cliques
- can be called multiple times
- Assumes all cliques in tree are being solved simultaneously and in similar manner.
- State machine rev.1 -- copied from first TreeBasedInitialization.jl.
- Doesn't do partial initialized state properly yet.
"""
function cliqInitSolveUpByStateMachine!(dfg::G,
tree::AbstractBayesTree,
cliq::TreeClique,
timeout::Union{Nothing, <:Real}=nothing;
N::Int=100,
verbose::Bool=false,
verbosefid=stdout,
oldcliqdata::BayesTreeNodeData=BayesTreeNodeData(),
drawtree::Bool=false,
show::Bool=false,
incremental::Bool=true,
limititers::Int=-1,
upsolve::Bool=true,
downsolve::Bool=true,
recordhistory::Bool=false,
delay::Bool=false,
injectDelayBefore::Union{Nothing,Pair{<:Function, <:Real}}=nothing,
store_in_task::Bool=false,
logger::SimpleLogger=SimpleLogger(Base.stdout)) where {G <: AbstractDFG, AL <: AbstractLogger}
#
children = getChildren(tree, cliq)#Graphs.out_neighbors(cliq, tree.bt)

prnt = getParent(tree, cliq)

destType = (G <: InMemoryDFGTypes) ? G : InMemDFGType

csmc = CliqStateMachineContainer(dfg, initfg(destType, solverParams=getSolverParams(dfg)), tree, cliq, prnt, children, incremental, drawtree, downsolve, delay, getSolverParams(dfg), Dict{Symbol,String}(), oldcliqdata, logger)

nxt = upsolve ? canCliqMargRecycle_StateMachine : (downsolve ? canCliqMargRecycle_StateMachine : error("must attempt either up or down solve"))

csmiter_cb = getSolverParams(dfg).drawCSMIters ? ((st::StateMachine)->(cliq.attributes["xlabel"] = st.iter)) : ((st)->())

statemachine = StateMachine{CliqStateMachineContainer}(next=nxt, name="cliq$(cliq.index)")

# store statemachine and csmc in task
if store_in_task
task_local_storage(:statemachine, statemachine)
task_local_storage(:csmc, csmc)
end

while statemachine(csmc, timeout, verbose=verbose, verbosefid=verbosefid, verboseXtra=getCliqueStatus(csmc.cliq), iterlimit=limititers, recordhistory=recordhistory, housekeeping_cb=csmiter_cb, injectDelayBefore=injectDelayBefore); end
statemachine.history
end



Expand Down
90 changes: 85 additions & 5 deletions src/CliqStateMachineUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,86 @@
export setVariablePosteriorEstimates!
export attachCSM!




"""
$SIGNATURES

Set all up `upsolved` and `downsolved` cliq data flags `to::Bool=false`.
"""
function setAllSolveFlags!(treel::AbstractBayesTree, to::Bool=false)::Nothing
for (id, cliq) in getCliques(treel)
cliqdata = getCliqueData(cliq)
setCliqueStatus!(cliqdata, :null)
cliqdata.upsolved = to
cliqdata.downsolved = to
end
nothing
end

"""
$SIGNATURES

Return true or false depending on whether the tree has been fully initialized/solved/marginalized.
"""
function isTreeSolved(treel::AbstractBayesTree; skipinitialized::Bool=false)
acclist = Symbol[:upsolved; :downsolved; :marginalized]
skipinitialized ? nothing : push!(acclist, :initialized)
for (clid, cliq) in getCliques(treel)
if !(getCliqueStatus(cliq) in acclist)
return false
end
end
return true
end

function isTreeSolvedUp(treel::AbstractBayesTree)
for (clid, cliq) in getCliques(treel)
if getCliqueStatus(cliq) != :upsolved
return false
end
end
return true
end


"""
$SIGNATURES

Return `::Bool` on whether all variables in this `cliq` are marginalzed.
"""
function isCliqMarginalizedFromVars(subfg::AbstractDFG, cliq::TreeClique)
for vert in getCliqVars(subfg, cliq)
if !isMarginalized(vert)
return false
end
end
return true
end


"""
$SIGNATURES

Reset the Bayes (Junction) tree so that a new upsolve can be performed.

Notes
- Will change previous clique status from `:downsolved` to `:initialized` only.
- Sets the color of tree clique to `lightgreen`.
"""
function resetTreeCliquesForUpSolve!(treel::AbstractBayesTree)::Nothing
acclist = Symbol[:downsolved;]
for (clid, cliq) in getCliques(treel)
if getCliqueStatus(cliq) in acclist
setCliqueStatus!(cliq, :initialized)
setCliqDrawColor(cliq, "sienna")
end
end
nothing
end


"""
$SIGNATURES

Expand Down Expand Up @@ -1083,11 +1163,11 @@ Special function to add a few variables and factors to the clique sub graph requ
Dev Notes
- There is still some disparity on whether up and down solves of tree should use exactly the same subgraph... 'between for up and frontal connected for down'
"""
function addDownVariableFactors!(dfg::G1,
subfg::G2,
cliq::TreeClique,
logger=ConsoleLogger();
solvable::Int=1 ) where {G1 <: AbstractDFG, G2 <: InMemoryDFGTypes}
function addDownVariableFactors!( dfg::G1,
subfg::G2,
cliq::TreeClique,
logger=ConsoleLogger();
solvable::Int=1 ) where {G1 <: AbstractDFG, G2 <: InMemoryDFGTypes}
#
# determine which variables and factors needs to be added
currsyms = ls(subfg)
Expand Down
61 changes: 44 additions & 17 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,49 @@ end


##==============================================================================
## Delete when tree message consolidation is complete
## Delete at end v0.16.x
##==============================================================================


function messages(btnd::BayesTreeNodeData)
@warn("btnd.messages will be deprecated")
btnd.messages
#global pidx
global pidx = 1
global pidl = 1
global pidA = 1
global thxl = nprocs() > 4 ? floor(Int,nprocs()*0.333333333) : 1

# upploc to control processes done local to this machine and separated from other
# highly loaded processes. upploc() should be used for dispatching short and burst
# of high bottle neck computations. Use upp2() for general multiple dispatch.
function upploc()
@warn "upploc is deprecated, use WorkerPool instead"
global pidl, thxl
N = nprocs()
pidl = (thxl > 1 ? ((pidl < thxl && pidl != 0 && thxl > 2) ? (pidl+1)%(thxl+1) : 2) : (N == 1 ? 1 : 2))
return pidl
end

# upp2() may refer to processes on a different machine. Do not associate upploc()
# with processes on a separate computer -- this will be become more complicated when
# remote processes desire their own short fast 'local' burst computations. We
# don't want all the data traveling back and forth for shorter jobs
function upp2()
@warn "upploc is deprecated, use WorkerPool instead"
global pidx, thxl
N = nprocs()
pidx = (N > 1 ? ((pidx < N && pidx != 0) ? (pidx+1)%(N+1) : thxl+1) : 1) #2 -- thxl+1
return pidx
end

function uppA()
@warn "upploc is deprecated, use WorkerPool instead"
global pidA
N = nprocs()
pidA = (N > 1 ? ((pidA < N && pidA != 0) ? (pidA+1)%(N+1) : 2) : 1) #2 -- thxl+1
return pidA
end

messages(clique::TreeClique) = getCliqueData(clique).messages


##==============================================================================
## Delete at end v0.16.x
##==============================================================================

@deprecate wipeBuildNewTree!(dfg::AbstractDFG; kwargs...) resetBuildTree!(dfg; kwargs...)

Expand All @@ -57,9 +85,8 @@ messages(clique::TreeClique) = getCliqueData(clique).messages



## =============================================================================
## Clique condition locks
## =============================================================================
# =============================================================================
# Clique condition locks

@deprecate lockUpStatus!(x...) ()->nothing

Expand Down Expand Up @@ -117,13 +144,11 @@ function Base.setproperty!(obj::BayesTreeNodeData, sym::Symbol, val)
end


## ============================================================================
## .initDownChannel, MUST BE REMOVED
## ============================================================================
# ============================================================================
# .initDownChannel, MUST BE REMOVED

## ============================================================================
## .downInitMsg, MUST BE REMOVED
## ============================================================================
# ============================================================================
# .downInitMsg, MUST BE REMOVED


@deprecate putMsgDwnInitChannel!(btnd::BayesTreeNodeData, msg::LikelihoodMessage) putDwnMsgConsolidated!(btnd, msg)
Expand Down Expand Up @@ -560,6 +585,8 @@ function updateTreeCliquesAsMarginalizedFromVars!(fgl::AbstractDFG, tree::Abstra
end




##==============================================================================
## Delete at end v0.15.x
##==============================================================================
Expand Down
3 changes: 1 addition & 2 deletions src/IncrementalInference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ export *,
getNumCliqs,
getBelief, getKDE,
CliqStateMachineContainer,
solveTree!,
solveGraph!,

solveCliq!,
fifoFreeze!,

Expand Down
16 changes: 16 additions & 0 deletions src/JunctionTreeTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,22 @@ end




##==============================================================================
## Must consolideate tree message
##==============================================================================


function messages(btnd::BayesTreeNodeData)
@warn("btnd.messages will be deprecated")
btnd.messages
end

messages(clique::TreeClique) = getCliqueData(clique).messages




## ===========================================================================================
## MUST DEPRECATE BELOW
## ===========================================================================================
Expand Down
Loading