Skip to content

Commit f7e4db1

Browse files
authored
Merge branch 'master' into 23Q1/enh/pcktojustvar
2 parents 96df0f4 + 866808a commit f7e4db1

18 files changed

+208
-65
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.20.1"
3+
version = "0.20.2"
44

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

docs/src/variable_factor_serialization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ prior = addFactor!(dfg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Di
2626

2727
# Now serialize them:
2828
pVariable = packVariable(dfg, x0)
29-
pFactor = packFactor(dfg, prior)
29+
pFactor = packFactor(prior)
3030

3131
# And we can deserialize them
3232
upVariable = unpackVariable(dfg, pVariable)
@@ -60,7 +60,7 @@ for v in getVariables(dfg)
6060
end
6161
# Factors
6262
for f in getFactors(dfg)
63-
fPacked = packFactor(dfg, f)
63+
fPacked = packFactor(f)
6464
io = open("$folder/factors/$(f.label).json", "w")
6565
JSON3.write(io, fPacked)
6666
close(io)

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ StructTypes.StructType(::Type{BlobEntry}) = StructTypes.UnorderedStruct()
3030
StructTypes.idproperty(::Type{BlobEntry}) = :id
3131
StructTypes.omitempties(::Type{BlobEntry}) = (:id,)
3232

33-
34-
3533
_fixtimezone(cts::NamedTuple) = ZonedDateTime(cts.utc_datetime*"+00")

src/DataBlobs/services/BlobEntry.jl

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function assertHash(de::BlobEntry, db; hashfunction::Function = sha256)
4646
end
4747

4848

49-
function Base.show(io::IO, entry::BlobEntry)
49+
function Base.show(io::IO, ::MIME"text/plain", entry::BlobEntry)
5050
println(io, "_type=BlobEntry {")
5151
println(io, " id: ", entry.id)
5252
println(io, " blobId: ", entry.blobId)
@@ -62,10 +62,6 @@ function Base.show(io::IO, entry::BlobEntry)
6262
println(io, "}")
6363
end
6464

65-
Base.show(io::IO, ::MIME"text/plain", entry::BlobEntry) = show(io, entry)
66-
67-
68-
6965
##==============================================================================
7066
## BlobEntry - CRUD
7167
##==============================================================================
@@ -200,7 +196,8 @@ hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict,
200196

201197
"""
202198
$(SIGNATURES)
203-
Get data entries, Vector{BlobEntry}
199+
200+
Get blob entries, Vector{BlobEntry}
204201
"""
205202
function getBlobEntries(var::AbstractDFGVariable)
206203
#or should we return the iterator, Base.ValueIterator{Dict{Symbol,BlobEntry}}?
@@ -212,6 +209,36 @@ function getBlobEntries(dfg::AbstractDFG, label::Symbol)
212209
getBlobEntries(getVariable(dfg, label))
213210
end
214211

212+
"""
213+
$(SIGNATURES)
214+
215+
Get all blob entries matching a Regex pattern over variables
216+
217+
Notes
218+
- Use `dropEmpties=true` to not include empty lists in result.
219+
- Use keyword `varList` for which variables to search through.
220+
"""
221+
function getBlobEntriesVariables(
222+
dfg::AbstractDFG,
223+
bLblPattern::Regex;
224+
varList::AbstractVector{Symbol} = sort(listVariables(dfg); lt=natural_lt),
225+
dropEmpties::Bool = false
226+
)
227+
RETLIST = Vector{Vector{BlobEntry}}()
228+
@showprogress "Get entries matching $bLblPattern" for vl in varList
229+
bes = filter(
230+
s->occursin(bLblPattern,string(s.label)),
231+
listBlobEntries(dfg,vl)
232+
)
233+
# only push to list if there are entries on this variable
234+
(!dropEmpties || 0 < length(bes)) ? nothing : continue
235+
push!(RETLIST, bes)
236+
end
237+
238+
return RETLIST
239+
end
240+
241+
215242
"""
216243
$(SIGNATURES)
217244
List the blob entries associated with a particular variable.

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# NOTE this is the convenience wrappers for entry and blob.
77

88
"""
9-
Get the data entry and blob for the specified blobstore or dfg retured as a tuple.
9+
Get the blob entry and blob for the specified blobstore or dfg retured as a tuple.
1010
Related
1111
[`getBlobEntry`](@ref)
1212
@@ -156,6 +156,7 @@ addData!(
156156
kwargs...
157157
)
158158

159+
#FIXME id used wrong
159160
function addData!(
160161
dfg::AbstractDFG,
161162
blobstore::AbstractBlobStore,
@@ -241,12 +242,12 @@ end
241242
deleteData!(
242243
dfg::AbstractDFG,
243244
blobstore::AbstractBlobStore,
244-
label::Symbol,
245+
vLbl::Symbol,
245246
entry::BlobEntry
246247
) = deleteBlob!(
247248
dfg,
248249
blobstore,
249-
label,
250+
vLbl,
250251
entry.label
251252
)
252253

src/Deprecated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## ================================================================================
33
## Remove in v0.21
44
##=================================================================================
5-
5+
@deprecate packFactor(dfg::AbstractDFG, f::DFGFactor) packFactor(f::DFGFactor)
66

77
# #TODO check this one
88
# function addData!(

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export getPPEDict, getVariablePPEDict, getVariablePPE
173173

174174
# CRUD & SET
175175
export getPPE,
176+
getPPEs,
176177
getVariablePPE,
177178
addPPE!,
178179
updatePPE!,
@@ -200,6 +201,7 @@ export hasBlobEntry,getBlobEntry,addBlobEntry!,updateBlobEntry!,deleteBlobEntry!
200201
export incrDataLabelSuffix
201202

202203
export getBlobEntries, listDataEntries, hasDataEntry, hasDataEntry
204+
export getBlobEntriesVariables
203205
export listDataEntrySequence
204206
# convenience wrappers
205207
export mergeDataEntries!

src/FileDFG/services/FileDFG.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ function saveDFG(folder::AbstractString, dfg::AbstractDFG)
4040
map(f -> rm("$varFolder/$f"), readdir(varFolder))
4141
map(f -> rm("$factorFolder/$f"), readdir(factorFolder))
4242
# Variables
43-
for v in variables
43+
@showprogress "saving variables" for v in variables
4444
vPacked = packVariable(v)
4545
JSON3.write("$varFolder/$(v.label).json", vPacked)
4646
end
4747
# Factors
48-
for f in factors
48+
@showprogress "saving factors" for f in factors
4949
fPacked = packFactor(dfg, f)
5050
JSON3.write("$factorFolder/$(f.label).json", fPacked)
5151
end
@@ -56,9 +56,9 @@ function saveDFG(folder::AbstractString, dfg::AbstractDFG)
5656
destfile = joinpath(savedir, savename*".tar.gz")
5757
# FIXME, switch to Tar.jl and Transcode Zlib / Codec, see #351
5858
if length(savedir) != 0
59-
run( pipeline(`tar -zcf - -C $savedir $savename`, stdout="$destfile"))
59+
run( pipeline(`tar -zcf - -C $savedir $savename`, stdout="$destfile"))
6060
else
61-
run( pipeline(`tar -zcf - $savename`, stdout="$destfile"))
61+
run( pipeline(`tar -zcf - $savename`, stdout="$destfile"))
6262
end
6363
Base.rm(joinpath(savedir,savename), recursive=true)
6464
end

src/entities/DFGFactor.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Base.@kwdef mutable struct GenericFunctionNodeData{T<:Union{<:AbstractPackedFact
4848
inflation::Float64 = 0.0
4949
end
5050

51+
# TODO should we move non FactorOperationalMemory to DFGFactor:
52+
# fnc, multihypo, nullhypo, inflation ?
53+
# that way we split solverData <: FactorOperationalMemory and constants
54+
# TODO see if above ever changes?
55+
56+
5157
## Constructors
5258

5359

@@ -77,19 +83,18 @@ FunctionNodeData(args...; kw...) = FunctionNodeData{typeof(args[4])}(args...; kw
7783
# | DFGFactor | X | X | X | X | X |
7884

7985
# Packed Factor
80-
Base.@kwdef struct PackedFactor
81-
# NOTE: This has to match the order of the JSON deserializer as we're using OrderedStructs.
82-
id::Union{UUID, Nothing}
86+
Base.@kwdef struct PackedFactor <: AbstractDFGFactor
87+
id::Union{UUID, Nothing} = nothing
8388
label::Symbol
8489
tags::Vector{Symbol}
8590
_variableOrderSymbols::Vector{Symbol}
8691
timestamp::ZonedDateTime
87-
nstime::Int
92+
nstime::String
8893
fnctype::String
8994
solvable::Int
9095
data::String
9196
metadata::String
92-
_version::String
97+
_version::String = string(_getDFGVersion())
9398
end
9499

95100
StructTypes.StructType(::Type{PackedFactor}) = StructTypes.UnorderedStruct()
@@ -275,8 +280,8 @@ StructTypes.omitempties(::Type{SkeletonDFGFactor}) = (:id,)
275280
##==============================================================================
276281
## Define factor levels
277282
##==============================================================================
278-
const FactorDataLevel0 = Union{DFGFactor, DFGFactorSummary, SkeletonDFGFactor}
279-
const FactorDataLevel1 = Union{DFGFactor, DFGFactorSummary}
283+
const FactorDataLevel0 = Union{DFGFactor, DFGFactorSummary, PackedFactor, SkeletonDFGFactor}
284+
const FactorDataLevel1 = Union{DFGFactor, DFGFactorSummary, PackedFactor}
280285
const FactorDataLevel2 = Union{DFGFactor}
281286

282287
##==============================================================================

src/entities/DFGVariable.jl

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ VariableNodeData(variableType::InferenceVariable; kwargs...) = VariableNodeData{
9191

9292
"""
9393
$(TYPEDEF)
94-
Packed VariabeNodeData structure for serializing DFGVariables.
94+
Packed VariableNodeData structure for serializing DFGVariables.
9595
9696
---
9797
Fields:
@@ -177,27 +177,54 @@ getEstimateFields(::MeanMaxPPE) = [:suggested, :max, :mean]
177177
## DFG Variables
178178
##==============================================================================
179179

180+
180181
export Variable
181182

182183
"""
183184
$(TYPEDEF)
184185
185186
The Variable information packed in a way that accomdates multi-lang using json.
186187
"""
187-
Base.@kwdef struct Variable
188-
# NOTE: This has to match the order of the JSON deserializer as we're using OrderedStructs.
189-
id::Union{UUID, Nothing}
188+
Base.@kwdef struct Variable <: AbstractDFGVariable
189+
id::Union{UUID, Nothing} = nothing
190190
label::Symbol
191-
tags::Vector{Symbol}
192-
timestamp::ZonedDateTime
193-
nstime::Int
194-
ppes::Vector{MeanMaxPPE}
195-
blobEntries::Vector{BlobEntry}
191+
tags::Vector{Symbol} = Symbol[]
192+
timestamp::ZonedDateTime = now(tz"UTC")
193+
nstime::String = "0"
194+
ppes::Vector{MeanMaxPPE} = MeanMaxPPE[]
195+
blobEntries::Vector{BlobEntry} = BlobEntry[]
196196
variableType::String
197-
_version::String
198-
metadata::String
199-
solvable::Int
200-
solverData::Vector{PackedVariableNodeData}
197+
_version::String = string(_getDFGVersion())
198+
metadata::String = "e30="
199+
solvable::Int = 1
200+
solverData::Vector{PackedVariableNodeData} = PackedVariableNodeData[]
201+
end
202+
203+
#IIF like contruction helper for packed variable
204+
function PackedVariable(
205+
label::Symbol,
206+
variableType::String;
207+
tags::Vector{Symbol} = Symbol[],
208+
timestamp::ZonedDateTime = now(tz"UTC"),
209+
solvable::Int = 1,
210+
nanosecondtime::Int64 = 0,
211+
smalldata::Dict{Symbol, SmallDataTypes} = Dict{Symbol, SmallDataTypes}(),
212+
kwargs...
213+
)
214+
union!(tags, [:VARIABLE])
215+
216+
pacvar = PackedVariable(;
217+
label,
218+
variableType,
219+
nstime = string(nanosecondtime),
220+
solvable,
221+
tags,
222+
metadata = base64encode(JSON3.write(smalldata)),
223+
timestamp,
224+
kwargs...
225+
)
226+
227+
return pacvar
201228
end
202229
const PackedVariable = Variable
203230

@@ -273,7 +300,7 @@ DFGVariable(label::Symbol,
273300
solverDataDict::Dict{Symbol, VariableNodeData{T,P}}=Dict{Symbol, VariableNodeData{T,getPointType(T)}}(),
274301
kw...) where {T <: InferenceVariable, P} = DFGVariable(label, T; solverDataDict=solverDataDict, kw...)
275302
#
276-
@deprecate DFGVariable(label::Symbol, T_::Type{<:InferenceVariable},w...; timestamp::DateTime=now(),kw...) DFGVariable(label, T_, w...; timestamp=ZonedDateTime(timestamp), kw...)
303+
# @deprecate DFGVariable(label::Symbol, T_::Type{<:InferenceVariable},w...; timestamp::DateTime=now(),kw...) DFGVariable(label, T_, w...; timestamp=ZonedDateTime(timestamp), kw...)
277304
#
278305

279306

@@ -351,6 +378,27 @@ Base.@kwdef struct DFGVariableSummary <: AbstractDFGVariable
351378
dataDict::Dict{Symbol, BlobEntry}
352379
end
353380

381+
function DFGVariableSummary(
382+
id,
383+
label,
384+
timestamp,
385+
tags,
386+
::Nothing,
387+
variableTypeName,
388+
::Nothing,
389+
)
390+
return DFGVariableSummary(
391+
id,
392+
label,
393+
timestamp,
394+
tags,
395+
Dict{Symbol, MeanMaxPPE}(),
396+
variableTypeName,
397+
Dict{Symbol, BlobEntry}(),
398+
)
399+
end
400+
401+
StructTypes.names(::Type{DFGVariableSummary}) = ((:variableTypeName, :variableType),)
354402

355403
##------------------------------------------------------------------------------
356404
## SkeletonDFGVariable.jl
@@ -384,8 +432,8 @@ StructTypes.omitempties(::Type{SkeletonDFGVariable}) = (:id,)
384432
##==============================================================================
385433
# Define variable levels
386434
##==============================================================================
387-
const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, SkeletonDFGVariable}
388-
const VariableDataLevel1 = Union{DFGVariable, DFGVariableSummary}
435+
const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, PackedVariable, SkeletonDFGVariable}
436+
const VariableDataLevel1 = Union{DFGVariable, DFGVariableSummary, PackedVariable}
389437
const VariableDataLevel2 = Union{DFGVariable}
390438

391439
##==============================================================================

0 commit comments

Comments
 (0)