Skip to content

Commit

Permalink
Merge pull request #911 from JuliaRobotics/maint/3Q20/general
Browse files Browse the repository at this point in the history
general code cleanup
  • Loading branch information
dehann authored Sep 23, 2020
2 parents 104112b + e0cbe8f commit 3a41031
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 102 deletions.
74 changes: 37 additions & 37 deletions src/CanonicalGraphExamples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ Notes
"""
function generateCanonicalFG_CaesarRing1D(;graphinit::Bool=false)

fg = initfg()

addVariable!(fg, :x0, ContinuousScalar)
addVariable!(fg, :x1, ContinuousScalar)
addVariable!(fg, :x2, ContinuousScalar)
addVariable!(fg, :x3, ContinuousScalar)
addVariable!(fg, :x4, ContinuousScalar)
addVariable!(fg, :x5, ContinuousScalar)
addVariable!(fg, :x6, ContinuousScalar)

addFactor!(fg, [:x0], Prior(Normal()), graphinit=graphinit)
addFactor!(fg, [:x0;:x1], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x1;:x2], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x2;:x3], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x3;:x4], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x4;:x5], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x5;:x6], LinearConditional(Normal()), graphinit=graphinit)
fg = initfg()

addVariable!(fg, :x0, ContinuousScalar)
addVariable!(fg, :x1, ContinuousScalar)
addVariable!(fg, :x2, ContinuousScalar)
addVariable!(fg, :x3, ContinuousScalar)
addVariable!(fg, :x4, ContinuousScalar)
addVariable!(fg, :x5, ContinuousScalar)
addVariable!(fg, :x6, ContinuousScalar)

addFactor!(fg, [:x0], Prior(Normal()), graphinit=graphinit)
addFactor!(fg, [:x0;:x1], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x1;:x2], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x2;:x3], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x3;:x4], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x4;:x5], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x5;:x6], LinearConditional(Normal()), graphinit=graphinit)

addVariable!(fg, :l1, ContinuousScalar)
addFactor!(fg, [:x0;:l1], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x6;:l1], LinearConditional(Normal()), graphinit=graphinit)

addVariable!(fg, :l1, ContinuousScalar)
addFactor!(fg, [:x0;:l1], LinearConditional(Normal()), graphinit=graphinit)
addFactor!(fg, [:x6;:l1], LinearConditional(Normal()), graphinit=graphinit)

return fg
return fg
end


Expand All @@ -111,21 +111,21 @@ end
Continuous, linear scalar and multivariate test graph generation. Follows a line
with the pose id equal to the ground truth.
"""
function generateCanonicalFG_lineStep(lineLength::Int;
poseEvery::Int=2,
landmarkEvery::Int=4,
posePriorsAt = Int[0],
landmarkPriorsAt = Int[],
sightDistance::Int=4,
vardims = 1,
noisy = false,
graphinit = false,
σ_pose_prior = 0.1,
σ_lm_prior = 0.1,
σ_pose_pose = 0.1,
σ_pose_lm = 0.1,
solverParams=SolverParams())
# solverParams=SolverParams(algorithms=[:default, :parametric]))
function generateCanonicalFG_lineStep( lineLength::Int;
poseEvery::Int=2,
landmarkEvery::Int=4,
posePriorsAt = Int[0],
landmarkPriorsAt = Int[],
sightDistance::Int=4,
vardims = 1,
noisy = false,
graphinit = false,
σ_pose_prior = 0.1,
σ_lm_prior = 0.1,
σ_pose_pose = 0.1,
σ_pose_lm = 0.1,
solverParams=SolverParams())
# solverParams=SolverParams(algorithms=[:default, :parametric]))

vtype = (vardims == 1) ? ContinuousScalar() : ContinuousEuclid(vardims)

Expand Down
4 changes: 2 additions & 2 deletions src/CliqStateMachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,13 @@ function checkUpsolveFinished_StateMachine(csmc::CliqStateMachineContainer)

# remove any solvable upward cached data -- TODO will have to be changed for long down partial chains
# assuming maximally complte up solved cliq at this point
lockUpStatus!(csmc.cliq, csmc.cliq.index, true, csmc.logger, true, "9.finishCliqSolveCheck")
# lockUpStatus!(csmc.cliq, csmc.cliq.index, true, csmc.logger, true, "9.finishCliqSolveCheck")
sdims = Dict{Symbol,Float64}()
for varid in getCliqAllVarIds(csmc.cliq)
sdims[varid] = 0.0
end
updateCliqSolvableDims!(csmc.cliq, sdims, csmc.logger)
unlockUpStatus!(csmc.cliq)
# unlockUpStatus!(csmc.cliq)

# go to 10
return canCliqDownSolve_StateMachine # IncrementalInference.exitStateMachine
Expand Down
34 changes: 0 additions & 34 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,11 @@ messages(clique::TreeClique) = getCliqueData(clique).messages

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

# # lockUpStatus!(cdat::BayesTreeNodeData, idx::Int=1, verbose::Bool=false, logger=SimpleLogger(stdout), flushLogger::Bool=false, msg::AbstractString="") = put!(cdat.lockUpStatus, idx)
# # lockUpStatus!(cliq::TreeClique, idx::Int=1, verbose::Bool=false, logger=SimpleLogger(stdout), flushLogger::Bool=false, msg::AbstractString="") = lockUpStatus!(getCliqueData(cliq), idx, verbose, logger, flushLogger, msg)
# function lockUpStatus!( cdat::BayesTreeNodeData,
# owner::Int=1,
# idx::Int=1,
# verbose::Bool=false,
# logger=SimpleLogger(stdout),
# flushLogger::Bool=false,
# msg::AbstractString="")
# #
# with_logger(logger) do
# tt = now()
# verbose ? @info("$(tt) -- Lock $owner, UP from $idx | $msg") : nothing
# verbose && isready(cdat.lockUpStatus) ? @info("$(tt) -- Lock $owner, UP from $idx blocked by $(fetch(cdat.lockUpStatus))") : nothing
# end
# flushLogger ? (flush(logger.stream); sleep(0.01)) : nothing
# put!(cdat.lockUpStatus, idx)
# end
# lockUpStatus!(cliq::TreeClique, idx::Int=cliq.index, verbose::Bool=false, logger=SimpleLogger(stdout), flushLogger::Bool=false, msg::AbstractString="") = lockUpStatus!(getCliqueData(cliq), cliq.index, idx, verbose, logger, flushLogger, msg)

@deprecate unlockUpStatus!(cdat::BayesTreeNodeData) ()->nothing
# unlockUpStatus!(cdat::BayesTreeNodeData) = take!(cdat.lockUpStatus)
unlockUpStatus!(cliq::TreeClique) = unlockUpStatus!(getCliqueData(cliq))

# function lockDwnStatus!(cdat::BayesTreeNodeData, idx::Int=1; logger=ConsoleLogger())
# with_logger(logger) do
# @info "lockDwnStatus! isready=$(isready(cdat.lockDwnStatus)) with data $(cdat.lockDwnStatus.data)"
# end
# flush(logger.stream)
# stf = put!(cdat.lockDwnStatus, idx)
# with_logger(logger) do
# @info "lockDwnStatus! DONE: isready=$(isready(cdat.lockDwnStatus)) with data $(cdat.lockDwnStatus.data)"
# end
# flush(logger.stream)
# stf
# end
@deprecate lockDwnStatus!(cdat::BayesTreeNodeData, idx::Int=1; logger=ConsoleLogger()) ()->nothing

# unlockDwnStatus!(cdat::BayesTreeNodeData) = take!(cdat.lockDwnStatus)
@deprecate unlockDwnStatus!(cdat::BayesTreeNodeData) ()->nothing


Expand Down
11 changes: 0 additions & 11 deletions src/IncrementalInference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ export *,
animateCliqStateMachines,
csmAnimate,
makeCsmMovie,
lockUpStatus!,
unlockUpStatus!,
lockDwnStatus!,
unlockDwnStatus!,
# getSiblingsDelayOrder,
areSiblingsRemaingNeedDownOnly,

# general types for softtyping of variable nodes
Expand Down Expand Up @@ -169,14 +164,12 @@ export *,
listFactors,
exists,
sortDFG,
# getVariableIds,
getVariableOrder,
getPPE,
getPPEDict,
getVariablePPE,
isVariable,
isFactor,
# from dfg
getFactorType,
getSofttype,
getVariableType,
Expand Down Expand Up @@ -274,7 +267,6 @@ export *,
doCliqInitDown!,
cycleInitByVarOrder!,
prepCliqInitMsgsUp,
# prepCliqInitMsgsDown!, # obsolete
getOutNeighbors,
BayesTree,
TreeBelief,
Expand Down Expand Up @@ -326,7 +318,6 @@ export *,
drawCliqSubgraphUpMocking,
drawTree,
drawTreeAsyncLoop,
# printgraphmax,

# Bayes (Junction) Tree
evalFactor2,
Expand Down Expand Up @@ -359,7 +350,6 @@ export *,
CommonConvWrapper,

getCliqVarInitOrderUp,
# getCliqInitVarOrderDown,
fetchChildrenStatusUp,
getCliqNumAssocFactorsPerVar,

Expand Down Expand Up @@ -417,7 +407,6 @@ export *,

#internal dev functions for recycling cliques on tree
attemptTreeSimilarClique,
# getCliqSiblingsPartialNeeds,

# some utils
compare,
Expand Down
21 changes: 6 additions & 15 deletions src/JunctionTreeTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function MetaBayesTree(tree::BayesTree)
set_prop!(mtree.bt, v.index, :clique, deepcopy(v))
end

## FIXME: Use common location for channels #675 (DF, asking for BTND)
## TODO: placeholder for edge stored Channels
## set message passing properties,
# for e in MetaGraphs.edges(mtree.bt)
Expand Down Expand Up @@ -339,10 +340,6 @@ mutable struct BayesTreeNodeData
# keep the Condition and Channel{Int}'s for now
solveCondition::Condition

# FIXME evaluate if the locks are still necessary -- likely not.
# lockUpStatus::Channel{Int}
# lockDwnStatus::Channel{Int}

# FIXME consolidate Dict with LikelihoodMessage, (pull model #674)
solvableDims::Channel{Dict{Symbol, Float64}}

Expand Down Expand Up @@ -378,8 +375,6 @@ function BayesTreeNodeData(;frontalIDs=Symbol[],
downsolved=false,
isCliqReused=false,
solveCondition=Condition(),
# lockUpStatus=Channel{Int}(1),
# lockDwnStatus=Channel{Int}(1),
solvableDims=Channel{Dict{Symbol,Float64}}(1),
upMsgChannel=Channel{LikelihoodMessage}(1),
dwnMsgChannel=Channel{LikelihoodMessage}(1),
Expand Down Expand Up @@ -408,8 +403,6 @@ function BayesTreeNodeData(;frontalIDs=Symbol[],
downsolved,
isCliqReused,
solveCondition,
# lockUpStatus,
# lockDwnStatus,
solvableDims,
upMsgChannel,
dwnMsgChannel,
Expand Down Expand Up @@ -451,8 +444,6 @@ function compare( c1::BayesTreeNodeData,
TP = TP && c1.isCliqReused == c2.isCliqReused
TP = TP && getMsgUpThis(c1) == getMsgUpThis(c2)
# TP = TP && c1.solveCondition == c2.solveCondition
# TP = TP && c1.lockUpStatus == c2.lockUpStatus
# TP = TP && c1.lockDwnStatus == c2.lockDwnStatus
TP = TP && c1.solvableDims == c2.solvableDims
TP = TP && getMsgUpChannel(c1) == getMsgUpChannel(c2)
TP = TP && c1.dwnMsgChannel == c2.dwnMsgChannel
Expand Down Expand Up @@ -546,11 +537,11 @@ const ExploreTreeType{T} = FullExploreTreeType{T, BayesTree}
const ExploreTreeTypeLight{T} = FullExploreTreeType{T, Nothing}


function ExploreTreeType(fgl::G,
btl::AbstractBayesTree,
vertl::TreeClique,
prt::T,
msgs::Array{LikelihoodMessage,1} ) where {G <: AbstractDFG, T}
function ExploreTreeType( fgl::G,
btl::AbstractBayesTree,
vertl::TreeClique,
prt::T,
msgs::Array{LikelihoodMessage,1} ) where {G <: AbstractDFG, T}
#
ExploreTreeType{T}(fgl, btl, vertl, prt, msgs)
end
6 changes: 3 additions & 3 deletions src/TreeMsgDwnConsolidation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function notifyCliqDownInitStatus!( cliq::TreeClique,
end

# take lock for atomic transaction
lockDwnStatus!(cdat, cliq.index, logger=logger)
# lockDwnStatus!(cdat, cliq.index, logger=logger)

setCliqueStatus!(cdat, status)

Expand All @@ -165,8 +165,8 @@ function notifyCliqDownInitStatus!( cliq::TreeClique,


# unlock for others to proceed
unlockDwnStatus!(cdat)
with_logger(logger) do
# unlockDwnStatus!(cdat)
with_logger(logger) do
@info "$(now()), cliq=$(cliq.index), notifyCliqDownInitStatus! -- unlocked, $(getCliqueStatus(cliq))"
end

Expand Down

0 comments on commit 3a41031

Please sign in to comment.