Skip to content

Commit 56af037

Browse files
authored
Merge branch 'master' into feat/20Q3/modul_softtype
2 parents 727dd83 + 60ba70f commit 56af037

File tree

10 files changed

+141
-130
lines changed

10 files changed

+141
-130
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ function getVariable(dfg::CloudGraphsDFG, label::Union{Symbol, String})
236236
for ppe in listPPEs(dfg, label)
237237
variable.ppeDict[ppe] = getPPE(dfg, label, ppe)
238238
end
239-
for solverKey in listVariableSolverData(dfg, label)
240-
variable.solverDataDict[solverKey] = getVariableSolverData(dfg, label, solverKey)
239+
for solveKey in listVariableSolverData(dfg, label)
240+
variable.solverDataDict[solveKey] = getVariableSolverData(dfg, label, solveKey)
241241
end
242242
dataDict = getDataEntries(dfg, label)
243243
for (k,v) in dataDict
@@ -543,7 +543,7 @@ function _unpackPPE(dfg::G, packedPPE::Dict{String, Any})::AbstractPointParametr
543543
end
544544

545545
function listPPEs(dfg::CloudGraphsDFG, variablekey::Symbol; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::Vector{Symbol}
546-
return _listVarSubnodesForType(dfg, variablekey, MeanMaxPPE, "solverKey"; currentTransaction=currentTransaction)
546+
return _listVarSubnodesForType(dfg, variablekey, MeanMaxPPE, "solveKey"; currentTransaction=currentTransaction)
547547
end
548548

549549
function getPPE(dfg::CloudGraphsDFG, variablekey::Symbol, ppekey::Symbol=:default; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::AbstractPointParametricEst
@@ -578,8 +578,8 @@ function addPPE!(dfg::CloudGraphsDFG,
578578
ppe::P;
579579
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::AbstractPointParametricEst where
580580
{P <: AbstractPointParametricEst}
581-
if ppe.solverKey in listPPEs(dfg, variablekey, currentTransaction=currentTransaction)
582-
error("PPE '$(ppe.solverKey)' already exists")
581+
if ppe.solveKey in listPPEs(dfg, variablekey, currentTransaction=currentTransaction)
582+
error("PPE '$(ppe.solveKey)' already exists")
583583
end
584584
softType = getSofttype(dfg, variablekey)
585585
# Add additional properties for the PPE
@@ -600,8 +600,8 @@ function updatePPE!(
600600
ppe::P;
601601
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::P where
602602
{P <: AbstractPointParametricEst}
603-
if !(ppe.solverKey in listPPEs(dfg, variablekey, currentTransaction=currentTransaction))
604-
@warn "PPE '$(ppe.solverKey)' does not exist, adding"
603+
if !(ppe.solveKey in listPPEs(dfg, variablekey, currentTransaction=currentTransaction))
604+
@warn "PPE '$(ppe.solveKey)' does not exist, adding"
605605
end
606606
softType = getSofttype(dfg, variablekey, currentTransaction=currentTransaction)
607607
# Add additional properties for the PPE
@@ -727,20 +727,20 @@ function _unpackVariableNodeData(dfg::G, packedDict::Dict{String, Any})::Variabl
727727
end
728728

729729
function listVariableSolverData(dfg::CloudGraphsDFG, variablekey::Symbol; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::Vector{Symbol}
730-
return _listVarSubnodesForType(dfg, variablekey, VariableNodeData, "solverKey"; currentTransaction=currentTransaction)
730+
return _listVarSubnodesForType(dfg, variablekey, VariableNodeData, "solveKey"; currentTransaction=currentTransaction)
731731
end
732732

733-
function getVariableSolverData(dfg::CloudGraphsDFG, variablekey::Symbol, solverKey::Symbol=:default; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
734-
properties = _getVarSubnodeProperties(dfg, variablekey, VariableNodeData, solverKey; currentTransaction=currentTransaction)
733+
function getVariableSolverData(dfg::CloudGraphsDFG, variablekey::Symbol, solveKey::Symbol=:default; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
734+
properties = _getVarSubnodeProperties(dfg, variablekey, VariableNodeData, solveKey; currentTransaction=currentTransaction)
735735
return _unpackVariableNodeData(dfg, properties)
736736
end
737737

738738
function addVariableSolverData!(dfg::CloudGraphsDFG,
739739
variablekey::Symbol,
740740
vnd::VariableNodeData;
741741
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
742-
if vnd.solverKey in listVariableSolverData(dfg, variablekey, currentTransaction=currentTransaction)
743-
error("Solver data '$(vnd.solverKey)' already exists")
742+
if vnd.solveKey in listVariableSolverData(dfg, variablekey, currentTransaction=currentTransaction)
743+
error("Solver data '$(vnd.solveKey)' already exists")
744744
end
745745
retPacked = _matchmergeVariableSubnode!(
746746
dfg,
@@ -758,8 +758,8 @@ function updateVariableSolverData!(dfg::CloudGraphsDFG,
758758
useCopy::Bool=true,
759759
fields::Vector{Symbol}=Symbol[];
760760
currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
761-
if !(vnd.solverKey in listVariableSolverData(dfg, variablekey, currentTransaction=currentTransaction))
762-
@warn "Solver data '$(vnd.solverKey)' does not exist, adding rather than updating."
761+
if !(vnd.solveKey in listVariableSolverData(dfg, variablekey, currentTransaction=currentTransaction))
762+
@warn "Solver data '$(vnd.solveKey)' does not exist, adding rather than updating."
763763
end
764764
# TODO: Update this to use the selective parameters from fields.
765765
retPacked = _matchmergeVariableSubnode!(
@@ -772,13 +772,13 @@ function updateVariableSolverData!(dfg::CloudGraphsDFG,
772772
return _unpackVariableNodeData(dfg, retPacked)
773773
end
774774

775-
function deleteVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, solverKey::Symbol=:default; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
775+
function deleteVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, solveKey::Symbol=:default; currentTransaction::Union{Nothing, Neo4j.Transaction}=nothing)::VariableNodeData
776776
retPacked = _deleteVarSubnode!(
777777
dfg,
778778
variablekey,
779779
:SOLVERDATA,
780780
_getLabelsForType(dfg, VariableNodeData, parentKey=variablekey),
781-
solverKey,
781+
solveKey,
782782
currentTransaction=currentTransaction)
783783
return _unpackVariableNodeData(dfg, retPacked)
784784
end
@@ -839,12 +839,12 @@ function updateVariableSolverData!(dfg::CloudGraphsDFG,
839839
end
840840

841841
function mergeVariableSolverData!(dfg::CloudGraphsDFG, sourceVariable::DFGVariable)
842-
for solverKey in listVariableSolverData(dfg, sourceVariable.label)
842+
for solveKey in listVariableSolverData(dfg, sourceVariable.label)
843843
updateVariableSolverData!(
844844
dfg,
845845
sourceVariable.label,
846-
getVariableSolverData(dfg, sourceVariable, solverKey),
847-
solverKey)
846+
getVariableSolverData(dfg, sourceVariable, solveKey),
847+
solveKey)
848848
end
849849
end
850850

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ function _getLabelsForInst(dfg::CloudGraphsDFG,
250250
labels = _getLabelsForType(dfg, typeof(inst), parentKey=parentKey)
251251
typeof(inst) <: DFGVariable && push!(labels, String(getLabel(inst)))
252252
typeof(inst) <: DFGFactor && push!(labels, String(getLabel(inst)))
253-
typeof(inst) <: AbstractPointParametricEst && push!(labels, String(inst.solverKey))
254-
typeof(inst) <: VariableNodeData && push!(labels, String(inst.solverKey))
253+
typeof(inst) <: AbstractPointParametricEst && push!(labels, String(inst.solveKey))
254+
typeof(inst) <: VariableNodeData && push!(labels, String(inst.solveKey))
255255
typeof(inst) <: AbstractDataEntry && push!(labels, String(inst.label))
256256
return labels
257257
end
@@ -317,8 +317,8 @@ function _matchmergeVariableSubnode!(
317317
result = commit(tx)
318318
end
319319
length(result.errors) > 0 && error(string(result.errors))
320-
length(result.results[1]["data"]) != 1 && error("Cannot find subnode '$(ppe.solverKey)' for variable '$variablekey'")
321-
length(result.results[1]["data"][1]["row"]) != 1 && error("Cannot find subnode '$(ppe.solverKey)' for variable '$variablekey'")
320+
length(result.results[1]["data"]) != 1 && error("Cannot find subnode '$(ppe.solveKey)' for variable '$variablekey'")
321+
length(result.results[1]["data"][1]["row"]) != 1 && error("Cannot find subnode '$(ppe.solveKey)' for variable '$variablekey'")
322322
return result.results[1]["data"][1]["row"][1]
323323
end
324324

src/Deprecated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
##==============================================================================
66
## Remove in 0.11
77
##==============================================================================
8-
@deprecate addVariableSolverData!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableNodeData, solverKey::Symbol) addVariableSolverData!(dfg, variablekey, vnd)
8+
@deprecate addVariableSolverData!(dfg::AbstractDFG, variablekey::Symbol, vnd::VariableNodeData, solveKey::Symbol) addVariableSolverData!(dfg, variablekey, vnd)
99

1010
@deprecate updatePPE!(dfg::AbstractDFG, variablekey::Symbol, ppe::AbstractPointParametricEst, ppekey::Symbol) updatePPE!(dfg, variablekey, ppe)
1111

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ export findClosestTimestamp, findVariableNearTimestamp
223223
# Serialization
224224
export packVariable, unpackVariable, packFactor, unpackFactor
225225
export rebuildFactorMetadata!
226+
export @defVariable
226227

227228
# File import and export
228-
export saveDFG, loadDFG!
229+
export saveDFG, loadDFG!, loadDFG
229230
export toDot, toDotFile
230231

231232
# Comparisons

src/FileDFG/services/FileDFG.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE], solvable=0)
1717
saveDFG(dfg, "/tmp/saveDFG.tar.gz")
1818
```
1919
"""
20-
function saveDFG( dfg::AbstractDFG, folder::AbstractString )
20+
function saveDFG(folder::AbstractString, dfg::AbstractDFG)
2121

22-
# TODO: Deprecate the folder functionality in v0.6.1
22+
# TODO: Deprecate the folder functionality
2323

2424
# Clean up save path if a file is specified
2525
savepath = folder[end] == '/' ? folder[1:end-1] : folder
@@ -65,6 +65,8 @@ function saveDFG( dfg::AbstractDFG, folder::AbstractString )
6565
end
6666
Base.rm(joinpath(savedir,savename), recursive=true)
6767
end
68+
# support both argument orders, #581
69+
saveDFG(dfg::AbstractDFG, folder::AbstractString) = saveDFG(folder, dfg)
6870

6971
"""
7072
$(SIGNATURES)
@@ -77,17 +79,16 @@ using DistributedFactorGraphs, IncrementalInference
7779
# Create a DFG - can make one directly, e.g. LightDFG{NoSolverParams}() or use IIF:
7880
dfg = initfg()
7981
# Load the graph
80-
loadDFG("/tmp/savedgraph.tar.gz", IncrementalInference, dfg)
82+
loadDFG!(dfg, "/tmp/savedgraph.tar.gz")
8183
# Use the DFG as you do normally.
8284
ls(dfg)
8385
```
8486
"""
8587
function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
8688

87-
8889
#
8990
# loaddir gets deleted so needs to be unique
90-
loaddir=joinpath("/","tmp","caesar","random", string(uuid1()))
91+
loaddir=split(joinpath("/","tmp","caesar","random", string(uuid1())), '-')[1]
9192
# Check if zipped destination (dst) by first doing fuzzy search from user supplied dst
9293
folder = dst # working directory for fileDFG variable and factor operations
9394
dstname = dst # path name could either be legacy FileDFG dir or .tar.gz file of FileDFG files.
@@ -111,7 +112,7 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
111112
@show sfolder = split(dstname, '.')
112113
Base.mkpath(loaddir)
113114
folder = joinpath(loaddir, filename) #splitpath(string(sfolder[end-2]))[end]
114-
@info "loadDFG detected a gzip $dstname -- unpacking via $loaddir now..."
115+
@info "loadDFG! detected a gzip $dstname -- unpacking via $loaddir now..."
115116
Base.rm(folder, recursive=true, force=true)
116117
# unzip the tar file
117118
run(`tar -zxf $dstname -C $loaddir`)
@@ -158,10 +159,13 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
158159

159160
# remove the temporary unzipped file
160161
if unzip
161-
@info "DFG.loadDFG is deleting a temp folder created during unzip, $loaddir"
162+
@info "DFG.loadDFG! is deleting a temp folder created during unzip, $loaddir"
162163
# need this because the number of files created in /tmp/caesar/random is becoming redonkulous.
163164
Base.rm(loaddir, recursive=true, force=true)
164165
end
165166

166167
return dfgLoadInto
167168
end
169+
170+
# to be extended by users with particular choices in dispatch.
171+
function loadDFG end

src/entities/DFGVariable.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ mutable struct VariableNodeData{T<:InferenceVariable}
3232
dontmargin::Bool
3333
solveInProgress::Int
3434
solvedCount::Int
35-
solverKey::Symbol
35+
solveKey::Symbol
3636
events::Dict{Symbol,Threads.Condition}
37-
VariableNodeData{T}(; solverKey::Symbol=:default) where {T <:InferenceVariable} =
38-
new{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0, 0, solverKey, Dict{Symbol,Threads.Condition}())
37+
VariableNodeData{T}(; solveKey::Symbol=:default) where {T <:InferenceVariable} =
38+
new{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0, 0, solveKey, Dict{Symbol,Threads.Condition}())
3939
VariableNodeData{T}(val::Array{Float64,2},
4040
bw::Array{Float64,2},
4141
BayesNetOutVertIDs::Array{Symbol,1},
@@ -50,12 +50,12 @@ mutable struct VariableNodeData{T<:InferenceVariable}
5050
dontmargin::Bool,
5151
solveInProgress::Int=0,
5252
solvedCount::Int=0,
53-
solverKey::Symbol=:default,
53+
solveKey::Symbol=:default,
5454
events::Dict{Symbol,Threads.Condition}=Dict{Symbol,Threads.Condition}()) where T <: InferenceVariable =
5555
new{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,
5656
eliminated,BayesNetVertID,separator,
5757
softtype::T,initialized,inferdim,ismargin,
58-
dontmargin, solveInProgress, solvedCount, solverKey, events)
58+
dontmargin, solveInProgress, solvedCount, solveKey, events)
5959
end
6060

6161
##------------------------------------------------------------------------------
@@ -75,17 +75,17 @@ VariableNodeData(val::Array{Float64,2},
7575
dontmargin::Bool,
7676
solveInProgress::Int=0,
7777
solvedCount::Int=0,
78-
solverKey::Symbol=:default
78+
solveKey::Symbol=:default
7979
) where T <: InferenceVariable =
8080
VariableNodeData{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,
8181
eliminated,BayesNetVertID,separator,
8282
softtype::T,initialized,inferdim,ismargin,
8383
dontmargin, solveInProgress, solvedCount,
84-
solverKey)
84+
solveKey)
8585

8686

87-
VariableNodeData(softtype::T; solverKey::Symbol=:default) where T <: InferenceVariable =
88-
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0, 0, solverKey)
87+
VariableNodeData(softtype::T; solveKey::Symbol=:default) where T <: InferenceVariable =
88+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0, 0, solveKey)
8989

9090
##==============================================================================
9191
## PackedVariableNodeData.jl
@@ -117,7 +117,7 @@ mutable struct PackedVariableNodeData
117117
dontmargin::Bool
118118
solveInProgress::Int
119119
solvedCount::Int
120-
solverKey::Symbol
120+
solveKey::Symbol
121121
PackedVariableNodeData() = new()
122122
PackedVariableNodeData(x1::Vector{Float64},
123123
x2::Int,
@@ -136,7 +136,7 @@ mutable struct PackedVariableNodeData
136136
x15::Bool,
137137
x16::Int,
138138
solvedCount::Int,
139-
solverKey::Symbol) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16, solvedCount, solverKey)
139+
solveKey::Symbol) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16, solvedCount, solveKey)
140140
# More permissive constructor needed for unmarshalling
141141
PackedVariableNodeData(x1::Vector,
142142
x2::Int,
@@ -155,12 +155,12 @@ mutable struct PackedVariableNodeData
155155
x15::Bool,
156156
x16::Int,
157157
solvedCount::Int,
158-
solverKey::Symbol) = new(
158+
solveKey::Symbol) = new(
159159
convert(Vector{Float64},x1),x2,
160160
convert(Vector{Float64},x3),x4,
161161
convert(Vector{Symbol},x5),
162162
convert(Vector{Int},x6),x7,x8,x9,
163-
convert(Vector{Symbol},x10),x11,x12,x13,x14,x15,x16, solvedCount, solverKey)
163+
convert(Vector{Symbol},x10),x11,x12,x13,x14,x15,x16, solvedCount, solveKey)
164164
end
165165

166166
##==============================================================================
@@ -182,7 +182,7 @@ abstract type AbstractPointParametricEst end
182182
Data container to store Parameteric Point Estimate (PPE) for mean and max.
183183
"""
184184
struct MeanMaxPPE <: AbstractPointParametricEst
185-
solverKey::Symbol #repeated because of Sam's request
185+
solveKey::Symbol #repeated because of Sam's request
186186
suggested::Vector{Float64}
187187
max::Vector{Float64}
188188
mean::Vector{Float64}
@@ -192,7 +192,7 @@ end
192192
##------------------------------------------------------------------------------
193193
## Constructors
194194

195-
MeanMaxPPE(solverKey::Symbol, suggested::Vector{Float64}, max::Vector{Float64}, mean::Vector{Float64}) = MeanMaxPPE(solverKey, suggested, max, mean, now(UTC))
195+
MeanMaxPPE(solveKey::Symbol, suggested::Vector{Float64}, max::Vector{Float64}, mean::Vector{Float64}) = MeanMaxPPE(solveKey, suggested, max, mean, now(UTC))
196196

197197
## Metadata
198198
"""

0 commit comments

Comments
 (0)