Skip to content

Commit e2e6151

Browse files
authored
Standardize Variable and Factor Levels (#1109)
* better progress in loadDFG! * rn SkeletonDFGVariable -> VariableSkeleton * rn DFGVariableSummary -> VariableSummary * rn DFGVariable -> VariableCompute * rn PackedVariable/Variable -> VariableDFG * rn SkeletonDFGFactor -> FactorSkeleton * rn DFGFactorSummary -> FactorSummary * rn DFGFactor -> FactorCompute * rn PackedFactor/Factor -> FactorDFG
1 parent b0ae00c commit e2e6151

27 files changed

+468
-404
lines changed

NEWS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
1010
UserLabel -> AgentLabel
1111
RobotLabel -> AgentLabel
1212
SessionLabel -> GraphLabel
13+
14+
Variables and Factors are renamed and aliased to the old names, see #1109.
15+
- Factor-level noun-adjectives
16+
SkeletonDFGFactor -> FactorSkeleton
17+
DFGFactorSummary -> FactorSummary
18+
DFGFactor -> FactorCompute
19+
PackedFactor/Factor -> FactorDFG
20+
21+
- Variable-level noun-adjectives
22+
SkeletonDFGVariable -> VariableSkeleton
23+
DFGVariableSummary -> VariableSummary
24+
DFGVariable -> VariableCompute
25+
PackedVariable/Variable -> VariableDFG
26+
1327
- v0.24 FileDFGs can be loaded with v0.25 with the exception of the User[Label/Data/BlobEntries]
1428

1529
# v0.24

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Graphs = "1.4"
5656
InteractiveUtils = "1.10"
5757
JSON3 = "1"
5858
LinearAlgebra = "1.10"
59-
Manifolds = "0.9"
59+
Manifolds = "0.9, 0.10"
6060
ManifoldsBase = "0.14, 0.15"
6161
OrderedCollections = "1.4"
6262
Pkg = "1.4, 1.5"

attic/SerializationOld.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ end
238238
##==============================================================================
239239
## Variable Packing and unpacking
240240
##==============================================================================
241-
function packVariable(v::DFGVariable)
241+
function packVariable(v::VariableCompute)
242242
props = Dict{String, Any}()
243243
props["label"] = string(v.label)
244244
props["timestamp"] = v.timestamp
@@ -286,7 +286,7 @@ end
286286

287287
"""
288288
$SIGNATURES
289-
Returns a DFGVariable.
289+
Returns a VariableCompute.
290290
291291
DevNotes
292292
- v0.19 packVariable fixed nested JSON bug on these fields, see #867:
@@ -404,11 +404,11 @@ function unpackVariable(
404404
else
405405
Dict{Symbol, VariableNodeData{variableType, pointType}}()
406406
end
407-
# Rebuild DFGVariable using the first solver variableType in solverData
407+
# Rebuild VariableCompute using the first solver variableType in solverData
408408
# @info "dbg Serialization 171" variableType Symbol(packedProps["label"]) timestamp nstime ppeDict solverData smallData Dict{Symbol,AbstractBlobEntry}() Ref(packedProps["solvable"])
409-
# variable = DFGVariable{variableType}(Symbol(packedProps["label"]), timestamp, nstime, Set(tags), ppeDict, solverData, smallData, Dict{Symbol,AbstractBlobEntry}(), Ref(packedProps["solvable"]))
409+
# variable = VariableCompute{variableType}(Symbol(packedProps["label"]), timestamp, nstime, Set(tags), ppeDict, solverData, smallData, Dict{Symbol,AbstractBlobEntry}(), Ref(packedProps["solvable"]))
410410

411-
variable = DFGVariable{variableType}(;
411+
variable = VariableCompute{variableType}(;
412412
id,
413413
label = Symbol(packedProps["label"]),
414414
# variableType = variableType,
@@ -562,7 +562,7 @@ end
562562
## Factor Packing and unpacking
563563
##==============================================================================
564564

565-
function _packSolverData(f::DFGFactor, fnctype::AbstractFactor)
565+
function _packSolverData(f::FactorCompute, fnctype::AbstractFactor)
566566
#
567567
packtype = convertPackedType(fnctype)
568568
try
@@ -579,7 +579,7 @@ function _packSolverData(f::DFGFactor, fnctype::AbstractFactor)
579579
end
580580

581581
# returns ::Dict{String, <:Any}
582-
function packFactor(dfg::AbstractDFG, f::DFGFactor)
582+
function packFactor(dfg::AbstractDFG, f::FactorCompute)
583583
# Construct the properties to save
584584
props = Dict{String, Any}()
585585
props["id"] = f.id !== nothing ? string(f.id) : nothing
@@ -692,7 +692,7 @@ function fncStringToData(fncType::String, data::Union{String, <:NamedTuple})
692692
return fncStringToData(packtype, data)
693693
end
694694

695-
# Returns `::DFGFactor`
695+
# Returns `::FactorCompute`
696696
function unpackFactor(
697697
dfg::G,
698698
packedProps::Dict{String, Any};
@@ -753,9 +753,9 @@ function unpackFactor(
753753
Dict{Symbol, SmallDataTypes}()
754754
end
755755

756-
# Rebuild DFGFactor
756+
# Rebuild FactorCompute
757757
#TODO use constuctor to create factor
758-
factor = DFGFactor(
758+
factor = FactorCompute(
759759
Symbol(label),
760760
timestamp,
761761
nstime,

docs/src/DataStructure.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,37 @@ Accessible properties for each of the variable structures:
1515

1616
| | Label | Timestamp | Tags | Estimates | Soft Type | Solvable | Solver Data | Metadata | Blob Entries |
1717
|---------------------|-------|-----------|------|-----------|-----------|----------|-------------|----------|--------------|
18-
| SkeletonDFGVariable | X | | X | | | | | | |
19-
| DFGVariableSummary | X | X | X | X | Symbol | | | | X |
20-
| DFGVariable | X | X | X | X | X | X | X | X | X |
18+
| VariableSkeleton | X | | X | | | | | | |
19+
| VariableSummary | X | X | X | X | Symbol | | | | X |
20+
| VariableCompute | X | X | X | X | X | X | X | X | X |
2121

2222
Accessible properties for each of the factor structures:
2323

2424
| | Label | Timestamp | Tags | Factor Type | Solvable | Solver Data |
2525
|-------------------|-------|-----------|------|-------------|----------|-------------|
26-
| SkeletonDFGFactor | X | | X | | | |
27-
| DFGFactorSummary | X | X | X | | | |
28-
| DFGFactor | X | X | X | X | X | X |
26+
| FactorSkeleton | X | | X | | | |
27+
| FactorSummary | X | X | X | | | |
28+
| FactorCompute | X | X | X | X | X | X |
2929

3030
## DFG Skeleton types
3131

32-
- [`SkeletonDFGVariable`](@ref)
33-
- [`SkeletonDFGFactor`](@ref)
32+
- [`VariableSkeleton`](@ref)
33+
- [`FactorSkeleton`](@ref)
3434

3535
## DFG Summary types
3636

37-
- [`DFGVariableSummary`](@ref)
38-
- [`DFGFactorSummary`](@ref)
37+
- [`VariableSummary`](@ref)
38+
- [`FactorSummary`](@ref)
3939

4040
## DFG Portable and Storeable types
4141

42-
- [`Variable`](@ref)
43-
- [`PackedFactor`](@ref)
42+
- [`VariableDFG`](@ref)
43+
- [`FactorDFG`](@ref)
4444

4545
## DFG Full solvable types
4646

47-
- [`DFGVariable`](@ref)
48-
- [`DFGFactor`](@ref)
47+
- [`VariableCompute`](@ref)
48+
- [`FactorCompute`](@ref)
4949

5050
## Additional Offloaded Data
5151

src/DataBlobs/services/BlobEntry.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function getBlobEntry(var::AbstractDFGVariable, key::Symbol)
7777
return var.dataDict[key]
7878
end
7979

80-
function getBlobEntry(var::PackedVariable, key::Symbol)
80+
function getBlobEntry(var::VariableDFG, key::Symbol)
8181
if !hasBlobEntry(var, key)
8282
throw(
8383
KeyError(
@@ -116,7 +116,7 @@ function getBlobEntryFirst(var::AbstractDFGVariable, key::Regex)
116116
)
117117
end
118118

119-
function getBlobEntryFirst(var::Variable, key::Regex)
119+
function getBlobEntryFirst(var::VariableDFG, key::Regex)
120120
firstIdx = findfirst(x -> contains(string(x.label), key), var.blobEntries)
121121
if isnothing(firstIdx)
122122
throw(KeyError("$key"))
@@ -129,7 +129,7 @@ function getBlobEntryFirst(dfg::AbstractDFG, label::Symbol, key::Regex)
129129
end
130130

131131
# TODO Consider autogenerating all methods of the form:
132-
# verbNoun(dfg::DFGVariable, label::Symbol, args...; kwargs...) = verbNoun(getVariable(dfg, label), args...; kwargs...)
132+
# verbNoun(dfg::VariableCompute, label::Symbol, args...; kwargs...) = verbNoun(getVariable(dfg, label), args...; kwargs...)
133133
# with something like:
134134
# getvariablemethod = [
135135
# :getBlobEntryFirst,
@@ -160,7 +160,7 @@ function addBlobEntry!(var::AbstractDFGVariable, entry::BlobEntry;)
160160
return entry
161161
end
162162

163-
function addBlobEntry!(var::PackedVariable, entry::BlobEntry)
163+
function addBlobEntry!(var::VariableDFG, entry::BlobEntry)
164164
entry.label in getproperty.(var.blobEntries, :label) &&
165165
error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
166166
push!(var.blobEntries, entry)
@@ -205,7 +205,7 @@ function deleteBlobEntry!(var::AbstractDFGVariable, key::Symbol)
205205
return pop!(var.dataDict, key)
206206
end
207207

208-
function deleteBlobEntry!(var::PackedVariable, key::Symbol)
208+
function deleteBlobEntry!(var::VariableDFG, key::Symbol)
209209
if !hasBlobEntry(var, key)
210210
throw(
211211
KeyError(
@@ -238,7 +238,7 @@ Does a blob entry (element) exist with `blobLabel`.
238238
"""
239239
hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict, blobLabel)
240240

241-
function hasBlobEntry(var::PackedVariable, label::Symbol)
241+
function hasBlobEntry(var::VariableDFG, label::Symbol)
242242
return label in getproperty.(var.blobEntries, :label)
243243
end
244244

@@ -252,7 +252,7 @@ function getBlobEntries(var::AbstractDFGVariable)
252252
return collect(values(var.dataDict))
253253
end
254254

255-
function getBlobEntries(var::PackedVariable)
255+
function getBlobEntries(var::VariableDFG)
256256
return var.blobEntries
257257
end
258258

@@ -311,7 +311,7 @@ function listBlobEntries(var::AbstractDFGVariable)
311311
return collect(keys(var.dataDict))
312312
end
313313

314-
function listBlobEntries(var::PackedVariable)
314+
function listBlobEntries(var::VariableDFG)
315315
return getproperty.(var.blobEntries, :label)
316316
end
317317

src/DistributedFactorGraphs.jl

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ export getSummaryGraph
135135
export DFGNode, AbstractDFGVariable, AbstractDFGFactor
136136

137137
# Variables
138-
export DFGVariable, DFGVariableSummary, SkeletonDFGVariable, PackedVariable
138+
export VariableCompute, VariableSummary, VariableSkeleton, VariableDFG
139139

140140
# Factors
141-
export DFGFactor, DFGFactorSummary, SkeletonDFGFactor, PackedFactor, Factor
141+
export FactorCompute, FactorSummary, FactorSkeleton, FactorDFG
142142

143143
# Common
144144
export getSolvable, setSolvable!, isSolvable
@@ -330,6 +330,7 @@ export plotDFG
330330

331331
## TODO maybe move to DFG
332332
# addAgent!
333+
# deleteAgent!
333334
# listAgents
334335
# addGraph!
335336
# deleteGraph!
@@ -393,4 +394,35 @@ include("Common.jl")
393394

394395
include("weakdeps_prototypes.jl")
395396

397+
#TODO start off as just an alias before deprecating
398+
# Starting Variable-level nouns-adjective standardisation
399+
export SkeletonDFGVariable
400+
const SkeletonDFGVariable = VariableSkeleton
401+
402+
export DFGVariableSummary
403+
const DFGVariableSummary = VariableSummary
404+
405+
export DFGVariable
406+
const DFGVariable = VariableCompute
407+
408+
export PackedVariable
409+
const PackedVariable = VariableDFG
410+
export Variable
411+
const Variable = VariableDFG
412+
413+
# Starting Factor-level noun-adjective standardisation
414+
export SkeletonDFGFactor
415+
const SkeletonDFGFactor = FactorSkeleton
416+
417+
export DFGFactorSummary
418+
const DFGFactorSummary = FactorSummary
419+
420+
export DFGFactor
421+
const DFGFactor = FactorCompute
422+
423+
export PackedFactor
424+
const PackedFactor = FactorDFG
425+
export Factor
426+
const Factor = FactorDFG
427+
396428
end

src/FileDFG/services/FileDFG.jl

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function loadDFG!(
146146
end
147147

148148
# extract the factor graph from fileDFG folder
149-
factors = DFGFactor[]
149+
factors = FactorCompute[]
150150
varFolder = "$folder/variables"
151151
factorFolder = "$folder/factors"
152152
# Folder preparations
@@ -155,45 +155,53 @@ function loadDFG!(
155155
!isdir(factorFolder) &&
156156
error("Can't load DFG graph - folder '$factorFolder' doesn't exist")
157157

158-
varFiles = sort(readdir(varFolder; sort = false); lt = natural_lt)
159-
factorFiles = sort(readdir(factorFolder; sort = false); lt = natural_lt)
158+
# varFiles = sort(readdir(varFolder; sort = false); lt = natural_lt)
159+
# factorFiles = sort(readdir(factorFolder; sort = false); lt = natural_lt)
160+
varFiles = readdir(varFolder; sort = false)
161+
factorFiles = readdir(factorFolder; sort = false)
160162

161-
packedvars = @showprogress 1 "loading variables" asyncmap(varFiles) do varFile
162-
jstr = read("$varFolder/$varFile", String)
163-
return JSON3.read(jstr, PackedVariable)
164-
end
165163
# FIXME, why is this treated different from VariableSkeleton, VariableSummary?
166-
# FIXME, still creates type instability on `variables` as either `::Variable` or `::DFGVariable`
167-
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGVariables(dfgLoadInto) == Variable
168-
variables = packedvars
169-
else
170-
variables = unpackVariable.(packedvars)
164+
165+
usePackedVariable =
166+
isa(dfgLoadInto, GraphsDFG) && getTypeDFGVariables(dfgLoadInto) == VariableDFG
167+
# type instability on `variables` as either `::Vector{Variable}` or `::Vector{VariableCompute{<:}}` (vector of abstract)
168+
variables = @showprogress 1 "loading variables" asyncmap(varFiles) do varFile
169+
jstr = read("$varFolder/$varFile", String)
170+
packedvar = JSON3.read(jstr, VariableDFG)
171+
if usePackedVariable
172+
return packedvar
173+
else
174+
return unpackVariable(packedvar)
175+
end
171176
end
172177

173178
@info "Loaded $(length(variables)) variables"#- $(map(v->v.label, variables))"
174179
@info "Inserting variables into graph..."
175180
# Adding variables
176181
map(v -> addVariable!(dfgLoadInto, v), variables)
177182

178-
packedfacts = @showprogress 1 "loading factors" asyncmap(factorFiles) do factorFile
183+
usePackedFactor =
184+
isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) == FactorDFG
185+
186+
# `factors` is not type stable `::Vector{Factor}` or `::Vector{FactorCompute{<:}}` (vector of abstract)
187+
factors = @showprogress 1 "loading factors" asyncmap(factorFiles) do factorFile
179188
jstr = read("$factorFolder/$factorFile", String)
180-
return JSON3.read(jstr, PackedFactor)
181-
end
182-
# FIXME, still creates type instability on `variables` as either `::Factor` or `::DFGFactor{<:}`
183-
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) == PackedFactor
184-
factors = packedfacts
185-
else
186-
factors = unpackFactor.(dfgLoadInto, packedfacts)
189+
packedfact = JSON3.read(jstr, FactorDFG)
190+
if usePackedFactor
191+
return packedfact
192+
else
193+
return unpackFactor(dfgLoadInto, packedfact)
194+
end
187195
end
188196

189197
@info "Loaded $(length(factors)) factors"# - $(map(f->f.label, factors))"
190198
@info "Inserting factors into graph..."
191199
# # Adding factors
192200
map(f -> addFactor!(dfgLoadInto, f), factors)
193201

194-
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) != PackedFactor
202+
if isa(dfgLoadInto, GraphsDFG) && getTypeDFGFactors(dfgLoadInto) != FactorDFG
195203
# Finally, rebuild the CCW's for the factors to completely reinflate them
196-
# NOTE CREATES A NEW DFGFactor IF CCW TYPE CHANGES
204+
# NOTE CREATES A NEW FactorCompute IF CCW TYPE CHANGES
197205
@info "Rebuilding CCW's for the factors..."
198206
@showprogress 1 "build factor operational memory" for factor in factors
199207
rebuildFactorMetadata!(dfgLoadInto, factor)

0 commit comments

Comments
 (0)