Skip to content

Commit f6061a1

Browse files
authored
Update to use filters for DFG v1 (#1899)
1 parent c360a66 commit f6061a1

14 files changed

Lines changed: 36 additions & 46 deletions

IncrementalInference/src/CliqueStateMachine/services/CliqueStateMachine.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function preUpSolve_StateMachine(csmc::CliqStateMachineContainer)
287287
logCSM(
288288
csmc,
289289
"CSM-2a messages for up";
290-
upmsg = lsf(csmc.cliqSubFg; tags = [:__LIKELIHOODMESSAGE__]),
290+
upmsg = lsf(csmc.cliqSubFg; tagsFilter = ([:__LIKELIHOODMESSAGE__])),
291291
)
292292

293293
# store the cliqSubFg for later debugging
@@ -762,7 +762,7 @@ function tryDownInit_StateMachine(csmc::CliqStateMachineContainer)
762762
# structure for all up message densities computed during this initialization procedure.
763763
# XXX
764764
dwnkeys_ =
765-
lsf(csmc.cliqSubFg; tags = [:__DOWNWARD_COMMON__;]) .|> x -> ls(csmc.cliqSubFg, x)[1]
765+
lsf(csmc.cliqSubFg; tagsFilter = ([:__DOWNWARD_COMMON__;])) .|> x -> ls(csmc.cliqSubFg, x)[1]
766766
initorder = getCliqInitVarOrderDown(csmc.cliqSubFg, csmc.cliq, dwnkeys_)
767767
# initorder = getCliqVarInitOrderUp(csmc.tree, csmc.cliq)
768768

IncrementalInference/src/ExportAPI.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export AbstractDFG,
2020
isSolved,
2121
setSolvedCount!,
2222
listSupersolves,
23-
listSolveKeys,
23+
listStates,
2424
diagm,
2525
listBlobEntries,
2626
FolderStore,

IncrementalInference/src/services/AnalysisTools.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function shrinkFactorGraph(fg; upto::Int = 6)
1919
fgs = deepcopy(fg)
2020

2121
delVars = filter(x -> isSolvable(getVariable(fgs, x)) == 0, ls(fgs))
22-
todel = setdiff(lsf(fgs; solvable = 0), lsf(fgs; solvable = 1))
22+
todel = setdiff(lsf(fgs; solvableFilter = >=(0)), lsf(fgs; solvableFilter = >=(1)))
2323
delFcts = intersect(lsf(fgs), todel)
2424
allMags = filter(x -> :MAGNETOMETER in listTags(getFactor(fgs, x)), lsfPriors(fgs))
2525
union!(delFcts, filter(x -> length(ls(fgs, x)) == 0, allMags))

IncrementalInference/src/services/BayesNet.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ function buildBayesNet!(dfg::AbstractDFG, elimorder::Vector{Symbol}; solvable::I
149149
gm = FactorCompute[]
150150

151151
vert = DFG.getVariable(dfg, v)
152-
for fctId in listNeighbors(dfg, vert; solvable = solvable)
152+
for fctId in listNeighbors(dfg, vert; solvableFilter = >=(solvable))
153153
fct = DFG.getFactor(dfg, fctId)
154154
if (fct.state.eliminated != true)
155155
push!(fi, fctId)
156-
for sepNode in listNeighbors(dfg, fct; solvable = solvable)
156+
for sepNode in listNeighbors(dfg, fct; solvableFilter = >=(solvable))
157157
# TODO -- validate !(sepNode.index in Si) vs. older !(sepNode in Si)
158158
if sepNode != v && !(sepNode in Si) # Symbol comparison!
159159
push!(Si, sepNode)

IncrementalInference/src/services/DeconvUtils.jl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,7 @@ function approxDeconv(
120120
ccw::CommonConvWrapper = _getCCW(fcto);
121121
N::Int = 100,
122122
measurement::AbstractVector = sampleFactor(ccw, N),
123-
retries=nothing,
124123
)
125-
if !isnothing(retries)
126-
Base.depwarn(
127-
"approxDeconv kwarg retries is not used",
128-
:approxDeconv,
129-
)
130-
end
131124
# but what if this is a partial factor -- is that important for general cases in deconv?
132125
_setCCWDecisionDimsConv!(ccw, 0)
133126

@@ -188,15 +181,12 @@ function approxDeconv(
188181
dfg::AbstractDFG,
189182
fctsym::Symbol,
190183
solveKey::Symbol = :default;
191-
retries::Int = 3,
192184
)
193-
#
194-
195185
# which factor
196186
fct = getFactor(dfg, fctsym)
197187
pts = getPoints(getBelief(dfg, getVariableOrder(fct)[1], solveKey))
198188
N = length(pts)
199-
pts = approxDeconv(fct; N = N, retries = retries)
189+
pts = approxDeconv(fct; N = N)
200190
return pts
201191
end
202192

@@ -206,10 +196,7 @@ function approxDeconv(
206196
factorType::AbstractRelativeObservation,
207197
solveKey::Symbol = :default;
208198
tfg::AbstractDFG = initfg(),
209-
retries::Int = 3,
210199
)
211-
#
212-
213200
# build a local temporary graph copy containing the same values but user requested factor type.
214201
fct = getFactor(dfg, fctlbl)
215202
fctT = getObservation(fct)
@@ -223,7 +210,7 @@ function approxDeconv(
223210
f_ = addFactor!(tfg, lbls, factorType; graphinit = false)
224211

225212
# peform the deconvolution operation on the temporary graph with user desired factor instead.
226-
return approxDeconv(tfg, getLabel(f_); retries = retries)
213+
return approxDeconv(tfg, getLabel(f_))
227214
end
228215

229216
# try default constructor

IncrementalInference/src/services/GraphInit.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ See also: [`doautoinit!`](@ref), [`initAll!`](@ref)
2121
function makeSolverData!(
2222
dfg::AbstractDFG;
2323
solvable = 1,
24-
varList::AbstractVector{Symbol} = ls(dfg; solvable),
24+
varList::AbstractVector{Symbol} = ls(dfg; solvableFilter = >=(solvable)),
2525
solveKey::Symbol=:default
2626
)
2727
count = 0
@@ -475,8 +475,8 @@ function ensureSolvable!(
475475
solvableFallback::Int = 0,
476476
)
477477
# workaround in case isolated variables occur
478-
solvVars = ls(dfg; solvable = solvableTarget)
479-
varHasFact = (x -> length(ls(dfg, x; solvable = solvableTarget)) == 0).(solvVars)
478+
solvVars = ls(dfg; solvableFilter = >=(solvableTarget))
479+
varHasFact = (x -> length(listNeighbors(dfg, x; solvableFilter = >=(solvableTarget))) == 0).(solvVars)
480480
blankVars = solvVars[findall(varHasFact)]
481481
if 0 < length(blankVars)
482482
@warn(
@@ -504,7 +504,7 @@ function initAll!(
504504
)
505505
#
506506
# allvarnodes = getVariables(dfg)
507-
syms = intersect(DFG.getAddHistory(dfg), ls(dfg; solvable = solvable))
507+
syms = intersect(DFG.getAddHistory(dfg), ls(dfg; solvableFilter = >=(solvable)))
508508
# syms = ls(dfg, solvable=solvable) # |> sortDFG
509509

510510
# May have to first add the solveKey VNDs if they are not yet available

IncrementalInference/src/services/JunctionTreeUtils.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ function buildTreeFromOrdering!(
778778
# copy required for both remote and local graphs
779779
DFG.deepcopyGraph!(fge, dfg)
780780

781-
println("Building Bayes net...")
781+
@info "Building Bayes net..."
782782
buildBayesNet!(fge, elimOrder; solvable = solvable)
783783

784784
tree = BayesTree()
@@ -793,7 +793,7 @@ function buildTreeFromOrdering!(
793793
close(fid)
794794
end
795795

796-
println("Find potential functions for each clique")
796+
@info "Find potential functions for each clique"
797797
for cliqIds in getCliqueIds(tree)
798798
# start at the root, of which there could be multiple disconnected trees
799799
if isRoot(tree, cliqIds)
@@ -999,7 +999,7 @@ function getCliqFactorsFromFrontals(
999999
for fctid in ls(fgl, frsym)
10001000
fct = getFactor(fgl, fctid)
10011001
if !unused || !fct.state.potentialused
1002-
loutn = ls(fgl, fctid; solvable = solvable)
1002+
loutn = listNeighbors(fgl, fctid; solvableFilter = >=(solvable))
10031003
# deal with unary factors
10041004
if length(loutn) == 1
10051005
union!(usefcts, Symbol[Symbol(fct.label);])
@@ -1194,9 +1194,9 @@ function getCliqVarsWithFrontalNeighbors(
11941194
union!(syms, Symbol.(cond))
11951195

11961196
# TODO Can we trust factors are frontal connected?
1197-
ffcs = union(map(x -> ls(fgl, x; solvable = solvable), frtl)...)
1197+
ffcs = union(map(x -> listNeighbors(fgl, x; solvableFilter = >=(solvable)), frtl)...)
11981198
# @show ffcs = getCliqueData(cliq).potentials
1199-
neig = union(map(x -> ls(fgl, x; solvable = solvable), ffcs)...)
1199+
neig = union(map(x -> listNeighbors(fgl, x; solvableFilter = >=(solvable)), ffcs)...)
12001200
union!(syms, Symbol.(neig))
12011201
return syms
12021202
end

IncrementalInference/src/services/SolverAPI.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function taskSolveTree!(
4343

4444
approx_iters = getNumCliqs(treel) * 24
4545
solve_progressbar =
46-
verbose ? nothing : ProgressUnknown("Solve Progress: approx max $approx_iters, at iter")
46+
verbose ? nothing : ProgressUnknown(; desc = "Solve Progress: approx max $approx_iters, at iter")
4747

4848
# queue all the tasks/threads
4949
if !isTreeSolved(treel; skipinitialized = true)
@@ -387,13 +387,16 @@ function solveTree!(
387387

388388
# perhaps duplicate current value
389389
if storeOld || opt.dbg
390-
ss = listSolveKeys(dfgl) .|> string
390+
ss = listStates(dfgl) .|> string
391391
ss_ = ss[occursin.(r"default_", ss)] .|> x -> x[9:end]
392392
filter!(x -> occursin(r"^\d+$", x), ss_) # ss_ = ss_[occursin.(r"^\d$",ss_)]
393393
allk = parse.(Int, ss_)
394394
nextk = length(allk) == 0 ? 0 : maximum(allk) + 1
395395
newKey = Symbol(:default_, nextk)
396-
DFG.cloneSolveKey!(dfgl, newKey, :default; solvable = 1)
396+
# DFG.cloneStates!(dfgl, newKey, :default; solvableFilter = >=(1))
397+
for vlabel in ls(dfgl; solvableFilter = >=(1))
398+
DFG.copytoState!(dfgl, vlabel, newKey, getState(dfgl, vlabel, :default))
399+
end
397400
# foreach(x->updateVariableSolverData!(dfgl, x, getState(getVariable(dfgl,x), :default), newKey, true, Symbol[]), ls(dfgl, solvable=1))
398401
@info "storeOld=true, previous :default deepcopied into $newKey for solvable==1 variables."
399402
end

IncrementalInference/src/services/SolverUtilities.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function _buildGraphByFactorAndTypes!(
157157
newFactor::Bool = true,
158158
destPattern::Regex = r"x\d+",
159159
destPrefix::Symbol = match(r"[a-zA-Z_]+", destPattern.pattern).match |> Symbol,
160-
_allVars::AbstractVector{Symbol} = sortDFG(ls(dfg, destPattern)),
160+
_allVars::AbstractVector{Symbol} = sortDFG(ls(dfg; labelFilter=contains(destPattern))),
161161
currLabel::Symbol = 0 < length(_allVars) ? _allVars[end] : Symbol(destPrefix, 0),
162162
currNumber::Integer = reverse(match(r"\d+", reverse(string(currLabel))).match) |>
163163
x -> parse(Int, x),

IncrementalInference/src/services/TreeMessageUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ function deleteMsgFactors!(
618618
tags::Vector{Symbol} = [:__LIKELIHOODMESSAGE__],
619619
)
620620
# remove msg factors that were added to the subfg
621-
facs = lsf(subfg; tags = tags)
621+
facs = lsf(subfg; tagsFilter = !isdisjoint(tags))
622622
deleteFactor!.(subfg, facs)
623623
return facs
624624
end

0 commit comments

Comments
 (0)