Skip to content

Commit a0d359b

Browse files
authored
Merge pull request #646 from JuliaRobotics/master
v0.10.2-rc1
2 parents e19587c + eaea68c commit a0d359b

File tree

9 files changed

+109
-68
lines changed

9 files changed

+109
-68
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.10.1"
3+
version = "0.10.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)
164164
error("Variable '$(variable.label)' already exists in the factor graph")
165165
end
166166

167-
ret = updateVariable!(dfg, variable, skipAddError=true)
167+
ret = updateVariable!(dfg, variable, warn_if_absent=false)
168168

169169
# Do a variable update
170170
return ret
171171
end
172172

173-
function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable; skipAddError::Bool=false)
173+
function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable; warn_if_absent::Bool=true)
174174
exist = exists(dfg, variable)
175-
!skipAddError && !exist && @warn "Variable label '$(variable.label)' does not exist in the factor graph, adding"
175+
warn_if_absent && !exist && @warn "Variable label '$(variable.label)' does not exist in the factor graph, adding"
176176

177177
# Create/update the base variable
178178
# NOTE: We are not merging the variable.tags into the labels anymore. We can index by that but not
@@ -196,7 +196,7 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable; skipAddErro
196196
# length(result.results[1]["data"][1]["row"]) != 1 && error("Cannot update or add variable '$(getLabel(variable))'")
197197

198198
# Merge the PPE's, SolverData, and BigData
199-
mergeVariableData!(dfg, variable; currentTransaction=tx, skipExistenceCheck=true)
199+
mergeVariableData!(dfg, variable; currentTransaction=tx, warn_if_absent=false)
200200

201201
commit(tx)
202202
catch ex
@@ -220,7 +220,7 @@ function addFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)
220220
end
221221

222222
# Do a variable update
223-
return updateFactor!(dfg, factor, skipAddError=true)
223+
return updateFactor!(dfg, factor, warn_if_absent=false)
224224
end
225225

226226
function getVariable(dfg::CloudGraphsDFG, label::Union{Symbol, String})
@@ -247,8 +247,8 @@ function getVariable(dfg::CloudGraphsDFG, label::Union{Symbol, String})
247247
return variable
248248
end
249249

250-
function mergeVariableData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing, skipExistenceCheck::Bool=false)
251-
if !skipExistenceCheck & !exists(dfg, sourceVariable, currentTransaction=currentTransaction)
250+
function mergeVariableData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing, warn_if_absent::Bool=true)
251+
if warn_if_absent && !exists(dfg, sourceVariable, currentTransaction=currentTransaction)
252252
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
253253
end
254254
for (k,v) in sourceVariable.ppeDict
@@ -273,9 +273,9 @@ function getFactor(dfg::CloudGraphsDFG, label::Union{Symbol, String})
273273
return rebuildFactorMetadata!(dfg, unpackFactor(dfg, props))
274274
end
275275

276-
function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor; skipAddError::Bool=false)
276+
function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor; warn_if_absent::Bool=true)
277277
exist = exists(dfg, factor)
278-
!skipAddError && !exist && @warn "Factor label '$(factor.label)' does not exist in the factor graph, adding"
278+
warn_if_absent && !exist && @warn "Factor label '$(factor.label)' does not exist in the factor graph, adding"
279279

280280
if exist
281281
# Check that the neighbors are the same
@@ -599,10 +599,11 @@ end
599599
function updatePPE!(
600600
dfg::CloudGraphsDFG,
601601
variablekey::Symbol,
602-
ppe::P;
603-
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::P where
604-
{P <: AbstractPointParametricEst}
605-
if !(ppe.solveKey in listPPEs(dfg, variablekey, currentTransaction=currentTransaction))
602+
ppe::AbstractPointParametricEst;
603+
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing,
604+
warn_if_absent::Bool=true)
605+
606+
if warn_if_absent && !(ppe.solveKey in listPPEs(dfg, variablekey, currentTransaction=currentTransaction))
606607
@warn "PPE '$(ppe.solveKey)' does not exist, adding"
607608
end
608609
softType = getSofttype(dfg, variablekey, currentTransaction=currentTransaction)
@@ -618,10 +619,13 @@ function updatePPE!(
618619
currentTransaction=currentTransaction))
619620
end
620621

621-
function updatePPE!(dfg::CloudGraphsDFG, sourceVariables::Vector{<:DFGVariable}, ppekey::Symbol=:default; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)
622+
function updatePPE!(dfg::CloudGraphsDFG, sourceVariables::Vector{<:DFGVariable}, ppekey::Symbol=:default;
623+
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing,
624+
warn_if_absent::Bool=true)
625+
622626
tx = currentTransaction == nothing ? transaction(dfg.neo4jInstance.connection) : currentTransaction
623627
for var in sourceVariables
624-
updatePPE!(dfg, var.label, getPPE(var, ppekey), currentTransaction=tx)
628+
updatePPE!(dfg, var.label, getPPE(var, ppekey), currentTransaction=tx, warn_if_absent=warn_if_absent)
625629
end
626630
if currentTransaction == nothing
627631
result = commit(tx)
@@ -694,8 +698,10 @@ function addDataEntry!(dfg::CloudGraphsDFG, label::Symbol, bde::BlobStoreEntry;
694698
packed)
695699
end
696700

697-
function updateDataEntry!(dfg::CloudGraphsDFG, label::Symbol, bde::BlobStoreEntry; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)
698-
if !(bde.label in listDataEntries(dfg, label, currentTransaction=currentTransaction))
701+
function updateDataEntry!(dfg::CloudGraphsDFG, label::Symbol, bde::BlobStoreEntry;
702+
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing,
703+
warn_if_absent::Bool=true)
704+
if warn_if_absent && !(bde.label in listDataEntries(dfg, label, currentTransaction=currentTransaction))
699705
@warn "Data label '$(bde.label)' does not exist, adding"
700706
end
701707
packed = _matchmergeVariableSubnode!(
@@ -773,8 +779,9 @@ function updateVariableSolverData!(dfg::CloudGraphsDFG,
773779
vnd::VariableNodeData,
774780
useCopy::Bool=true,
775781
fields::Vector{Symbol}=Symbol[];
782+
warn_if_absent::Bool=true,
776783
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
777-
if !(vnd.solveKey in listVariableSolverData(dfg, variablekey, currentTransaction=currentTransaction))
784+
if warn_if_absent && !(vnd.solveKey in listVariableSolverData(dfg, variablekey, currentTransaction=currentTransaction))
778785
@warn "Solver data '$(vnd.solveKey)' does not exist, adding rather than updating."
779786
end
780787
# TODO: Update this to use the selective parameters from fields.
@@ -847,10 +854,11 @@ function updateVariableSolverData!(dfg::CloudGraphsDFG,
847854
sourceVariables::Vector{<:DFGVariable},
848855
solvekey::Symbol=:default,
849856
useCopy::Bool=true,
850-
fields::Vector{Symbol}=Symbol[] )
857+
fields::Vector{Symbol}=Symbol[];
858+
warn_if_absent::Bool=true )
851859
#TODO: Do in bulk for speed.
852860
for var in sourceVariables
853-
updateVariableSolverData!(dfg, var.label, getSolverData(var, solvekey), solvekey, useCopy, fields)
861+
updateVariableSolverData!(dfg, var.label, getSolverData(var, solvekey), solvekey, useCopy, fields; warn_if_absent=warn_if_absent)
854862
end
855863
end
856864

src/Deprecated.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,24 @@ end
104104

105105
@deprecate setSmallData!(v::DFGVariable, smallData::Dict{String, String}) setSmallData!(v, createSymbolDict(smallData))
106106

107+
#update deprecation with warn_if_absent
108+
function updateVariableSolverData!(dfg::AbstractDFG,
109+
variablekey::Symbol,
110+
vnd::VariableNodeData,
111+
useCopy::Bool,
112+
fields::Vector{Symbol},
113+
verbose::Bool)
114+
Base.depwarn("updateVariableSolverData! argument verbose is deprecated in favor of keyword argument `warn_if_absent`, see #643", :updateVariableSolverData!)
115+
updateVariableSolverData!(dfg, variablekey, vnd, useCopy, fields; warn_if_absent = verbose)
116+
end
107117

108-
118+
function updateVariableSolverData!(dfg::AbstractDFG,
119+
variablekey::Symbol,
120+
vnd::VariableNodeData,
121+
solveKey::Symbol,
122+
useCopy::Bool,
123+
fields::Vector{Symbol},
124+
verbose::Bool)
125+
Base.depwarn("updateVariableSolverData! argument verbose is deprecated in favor of keyword argument `warn_if_absent`, see #643", :updateVariableSolverData!)
126+
updateVariableSolverData!(dfg, variablekey, vnd, solveKey, useCopy, fields; warn_if_absent = verbose)
127+
end

src/LightDFG/services/LightDFG.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,37 +90,37 @@ function addFactor!(dfg::LightDFG{<:AbstractParams, <:AbstractDFGVariable, F}, f
9090
end
9191

9292
function addFactor!(dfg::LightDFG{<:AbstractParams, <:AbstractDFGVariable, F},
93-
factor::AbstractDFGFactor)::F where F <: AbstractDFGFactor
93+
factor::AbstractDFGFactor) where F <: AbstractDFGFactor
9494
return addFactor!(dfg, F(factor))
9595
end
9696

97-
function getVariable(dfg::LightDFG, label::Symbol)::AbstractDFGVariable
97+
function getVariable(dfg::LightDFG, label::Symbol)
9898
if !haskey(dfg.g.variables, label)
9999
error("Variable label '$(label)' does not exist in the factor graph")
100100
end
101101

102102
return dfg.g.variables[label]
103103
end
104104

105-
function getFactor(dfg::LightDFG, label::Symbol)::AbstractDFGFactor
105+
function getFactor(dfg::LightDFG, label::Symbol)
106106
if !haskey(dfg.g.factors, label)
107107
error("Factor label '$(label)' does not exist in the factor graph")
108108
end
109109
return dfg.g.factors[label]
110110
end
111111

112-
function updateVariable!(dfg::LightDFG, variable::V)::V where V <: AbstractDFGVariable
112+
function updateVariable!(dfg::LightDFG, variable::AbstractDFGVariable; warn_if_absent::Bool=true)
113113
if !haskey(dfg.g.variables, variable.label)
114-
@warn "Variable label '$(variable.label)' does not exist in the factor graph, adding"
114+
warn_if_absent && @warn "Variable label '$(variable.label)' does not exist in the factor graph, adding"
115115
return addVariable!(dfg, variable)
116116
end
117117
dfg.g.variables[variable.label] = variable
118118
return variable
119119
end
120120

121-
function updateFactor!(dfg::LightDFG, factor::F)::F where F <: AbstractDFGFactor
121+
function updateFactor!(dfg::LightDFG, factor::AbstractDFGFactor; warn_if_absent::Bool=true)
122122
if !haskey(dfg.g.factors, factor.label)
123-
@warn "Factor label '$(factor.label)' does not exist in the factor graph, adding"
123+
warn_if_absent && @warn "Factor label '$(factor.label)' does not exist in the factor graph, adding"
124124
return addFactor!(dfg, factor)
125125
end
126126

src/services/AbstractDFG.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,16 +521,21 @@ Related
521521
listSupersolves, getSolverDataDict, listVariables
522522
"""
523523
function listSolveKeys(dfg::AbstractDFG,
524-
fltr::Union{Type{<:InferenceVariable},Regex, Nothing}=nothing;
524+
filterVariables::Union{Type{<:InferenceVariable},Regex, Nothing}=nothing;
525+
filterSolveKeys::Union{Regex,Nothing}=nothing,
525526
tags::Vector{Symbol}=Symbol[],
526527
solvable::Int=0 )
527528
#
528-
skeys = Set{Symbol}()
529-
varList = listVariables(dfg, fltr, tags=tags, solvable=solvable)
530-
for vs in varList, ky in keys(getSolverDataDict(getVariable(dfg, vs)))
531-
push!(skeys, ky)
532-
end
533-
return skeys
529+
skeys = Set{Symbol}()
530+
varList = listVariables(dfg, filterVariables, tags=tags, solvable=solvable)
531+
for vs in varList, ky in keys(getSolverDataDict(getVariable(dfg, vs)))
532+
push!(skeys, ky)
533+
end
534+
535+
#filter the solveKey set with filterSolveKeys regex
536+
!isnothing(filterSolveKeys) && return filter!(k -> occursin(filterSolveKeys, string(k)), skeys)
537+
538+
return skeys
534539
end
535540
const listSupersolves = listSolveKeys
536541

src/services/DFGVariable.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ DFG.@defVariable Pose2 3 (:Euclid, :Euclid, :Circular)
7777
macro defVariable(structname, dimension::Int, manifolds)#::Vararg{Symbol})#NTuple{dimension, Symbol})
7878
# :(struct $structname <: InferenceVariable end)
7979
return esc(quote
80-
struct $structname <: InferenceVariable end
80+
Base.@__doc__ struct $structname <: InferenceVariable end
8181
DistributedFactorGraphs.getDimension(::$structname) = $dimension
8282
DistributedFactorGraphs.getManifolds(::$structname) = $manifolds
8383
end)
@@ -345,9 +345,9 @@ end
345345
$(SIGNATURES)
346346
Update a small data pair `key=>value` for variable `label` in `dfg`
347347
"""
348-
function updateSmallData!(dfg::AbstractDFG, label::Symbol, pair::Pair{Symbol, <:SmallDataTypes})
348+
function updateSmallData!(dfg::AbstractDFG, label::Symbol, pair::Pair{Symbol, <:SmallDataTypes}; warn_if_absent::Bool=true)
349349
v = getVariable(dfg, label)
350-
!haskey(v.smallData, pair.first) && @warn("$(pair.first) does not exist, adding.")
350+
warn_if_absent && !haskey(v.smallData, pair.first) && @warn("$(pair.first) does not exist, adding.")
351351
push!(v.smallData, pair)
352352
updateVariable!(dfg, v)
353353
return v.smallData #or pair TODO
@@ -478,13 +478,12 @@ function updateVariableSolverData!(dfg::AbstractDFG,
478478
variablekey::Symbol,
479479
vnd::VariableNodeData,
480480
useCopy::Bool=true,
481-
fields::Vector{Symbol}=Symbol[],
482-
verbose::Bool=true )
481+
fields::Vector{Symbol}=Symbol[];
482+
warn_if_absent::Bool=true)
483483
#This is basically just setSolverData
484484
var = getVariable(dfg, variablekey)
485-
if verbose && !haskey(var.solverDataDict, vnd.solveKey)
486-
@warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding"
487-
end
485+
486+
warn_if_absent && !haskey(var.solverDataDict, vnd.solveKey) && @warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding"
488487

489488
# for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update.
490489
usevnd = useCopy ? deepcopy(vnd) : vnd
@@ -510,23 +509,22 @@ function updateVariableSolverData!(dfg::AbstractDFG,
510509
return var.solverDataDict[vnd.solveKey]
511510
end
512511

513-
514512
function updateVariableSolverData!(dfg::AbstractDFG,
515513
variablekey::Symbol,
516514
vnd::VariableNodeData,
517515
solveKey::Symbol,
518516
useCopy::Bool=true,
519-
fields::Vector{Symbol}=Symbol[],
520-
verbose::Bool=true)
517+
fields::Vector{Symbol}=Symbol[];
518+
warn_if_absent::Bool=true)
521519

522520
# TODO not very clean
523521
if vnd.solveKey != solveKey
524-
@warn "updateVariableSolverData with solveKey parameter might change in the future, see DFG #565"
522+
@warn("updateVariableSolverData with solveKey parameter might change in the future, see DFG #565. Future warnings are suppressed", maxlog=1)
525523
usevnd = useCopy ? deepcopy(vnd) : vnd
526524
usevnd.solveKey = solveKey
527-
return updateVariableSolverData!(dfg, variablekey, usevnd, useCopy, fields, verbose)
525+
return updateVariableSolverData!(dfg, variablekey, usevnd, useCopy, fields; warn_if_absent=warn_if_absent)
528526
else
529-
return updateVariableSolverData!(dfg, variablekey, vnd, useCopy, fields, verbose)
527+
return updateVariableSolverData!(dfg, variablekey, vnd, useCopy, fields; warn_if_absent=warn_if_absent)
530528
end
531529
end
532530

@@ -535,17 +533,19 @@ updateVariableSolverData!(dfg::AbstractDFG,
535533
sourceVariable::DFGVariable,
536534
solveKey::Symbol=:default,
537535
useCopy::Bool=true,
538-
fields::Vector{Symbol}=Symbol[] ) =
539-
updateVariableSolverData!(dfg, sourceVariable.label, getSolverData(sourceVariable, solveKey), useCopy, fields)
536+
fields::Vector{Symbol}=Symbol[];
537+
warn_if_absent::Bool=true ) =
538+
updateVariableSolverData!(dfg, sourceVariable.label, getSolverData(sourceVariable, solveKey), useCopy, fields; warn_if_absent=warn_if_absent)
540539

541540
function updateVariableSolverData!(dfg::AbstractDFG,
542541
sourceVariables::Vector{<:DFGVariable},
543542
solveKey::Symbol=:default,
544543
useCopy::Bool=true,
545-
fields::Vector{Symbol}=Symbol[] )
544+
fields::Vector{Symbol}=Symbol[];
545+
warn_if_absent::Bool=true)
546546
#I think cloud would do this in bulk for speed
547547
for var in sourceVariables
548-
updateVariableSolverData!(dfg, var.label, getSolverData(var, solveKey), useCopy, fields)
548+
updateVariableSolverData!(dfg, var.label, getSolverData(var, solveKey), useCopy, fields; warn_if_absent=warn_if_absent)
549549
end
550550
end
551551

@@ -563,7 +563,7 @@ function deepcopySolvekeys!(dfg::AbstractDFG,
563563
for x in labels
564564
sd = deepcopy(getSolverData(getVariable(dfg,x), src))
565565
sd.solveKey = dest
566-
updateVariableSolverData!(dfg, x, sd, true, Symbol[], verbose )
566+
updateVariableSolverData!(dfg, x, sd, true, Symbol[]; warn_if_absent=verbose )
567567
end
568568
end
569569
const deepcopySupersolve! = deepcopySolvekeys!
@@ -670,9 +670,9 @@ addPPE!(dfg::AbstractDFG, sourceVariable::DFGVariable, ppekey::Symbol=:default)
670670
$(SIGNATURES)
671671
Update PPE data if it exists, otherwise add it -- one call per `key::Symbol=:default`.
672672
"""
673-
function updatePPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::P)::P where {P <: AbstractPointParametricEst}
673+
function updatePPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::AbstractPointParametricEst; warn_if_absent::Bool=true)
674674
var = getVariable(dfg, variablekey)
675-
if !haskey(var.ppeDict, ppe.solveKey)
675+
if warn_if_absent && !haskey(var.ppeDict, ppe.solveKey)
676676
@warn "PPE '$(ppe.solveKey)' does not exist, adding"
677677
end
678678
#for InMemoryDFGTypes, cloud would update here
@@ -685,17 +685,17 @@ end
685685
Update PPE data if it exists, otherwise add it.
686686
NOTE: Copies the PPE data.
687687
"""
688-
updatePPE!(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=:default) =
689-
updatePPE!(dfg, sourceVariable.label, deepcopy(getPPE(sourceVariable, ppekey)))
688+
updatePPE!(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=:default; warn_if_absent::Bool=true) =
689+
updatePPE!(dfg, sourceVariable.label, deepcopy(getPPE(sourceVariable, ppekey)); warn_if_absent=warn_if_absent)
690690

691691
"""
692692
$(SIGNATURES)
693693
Update PPE data if it exists, otherwise add it.
694694
"""
695-
function updatePPE!(dfg::AbstractDFG, sourceVariables::Vector{<:VariableDataLevel1}, ppekey::Symbol=:default)
695+
function updatePPE!(dfg::AbstractDFG, sourceVariables::Vector{<:VariableDataLevel1}, ppekey::Symbol=:default; warn_if_absent::Bool=true)
696696
#I think cloud would do this in bulk for speed
697697
for var in sourceVariables
698-
updatePPE!(dfg, var.label, getPPE(dfg, var, ppekey))
698+
updatePPE!(dfg, var.label, getPPE(dfg, var, ppekey); warn_if_absent=warn_if_absent)
699699
end
700700
end
701701

0 commit comments

Comments
 (0)