Skip to content

Commit 21804f8

Browse files
authored
Merge pull request #1001 from JuliaRobotics/master
v0.20.2-rc1
2 parents d7b4fdc + 2fb816f commit 21804f8

File tree

10 files changed

+96
-46
lines changed

10 files changed

+96
-46
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"

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: 3 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
@@ -241,12 +241,12 @@ end
241241
deleteData!(
242242
dfg::AbstractDFG,
243243
blobstore::AbstractBlobStore,
244-
label::Symbol,
244+
vLbl::Symbol,
245245
entry::BlobEntry
246246
) = deleteBlob!(
247247
dfg,
248248
blobstore,
249-
label,
249+
vLbl,
250250
entry.label
251251
)
252252

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export hasBlobEntry,getBlobEntry,addBlobEntry!,updateBlobEntry!,deleteBlobEntry!
200200
export incrDataLabelSuffix
201201

202202
export getBlobEntries, listDataEntries, hasDataEntry, hasDataEntry
203+
export getBlobEntriesVariables
203204
export listDataEntrySequence
204205
# convenience wrappers
205206
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: 8 additions & 3 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

@@ -78,8 +84,7 @@ FunctionNodeData(args...; kw...) = FunctionNodeData{typeof(args[4])}(args...; kw
7884

7985
# Packed Factor
8086
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}
87+
id::Union{UUID, Nothing} = nothing
8388
label::Symbol
8489
tags::Vector{Symbol}
8590
_variableOrderSymbols::Vector{Symbol}
@@ -89,7 +94,7 @@ Base.@kwdef struct PackedFactor
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()

src/entities/DFGVariable.jl

Lines changed: 32 additions & 12 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:
@@ -179,19 +179,18 @@ getEstimateFields(::MeanMaxPPE) = [:suggested, :max, :mean]
179179

180180
# Packed Variable
181181
Base.@kwdef struct PackedVariable
182-
# NOTE: This has to match the order of the JSON deserializer as we're using OrderedStructs.
183-
id::Union{UUID, Nothing}
182+
id::Union{UUID, Nothing} = nothing
184183
label::Symbol
185-
tags::Vector{Symbol}
186-
timestamp::ZonedDateTime
187-
nstime::Int
188-
ppes::Vector{MeanMaxPPE}
189-
blobEntries::Vector{BlobEntry}
184+
tags::Vector{Symbol} = Symbol[]
185+
timestamp::ZonedDateTime = now(tz"UTC")
186+
nstime::Int = 0
187+
ppes::Vector{MeanMaxPPE} = MeanMaxPPE[]
188+
blobEntries::Vector{BlobEntry} = BlobEntry[]
190189
variableType::String
191-
_version::String
192-
metadata::String
193-
solvable::Int
194-
solverData::Vector{PackedVariableNodeData}
190+
_version::String = string(_getDFGVersion())
191+
metadata::String = "e30="
192+
solvable::Int = 1
193+
solverData::Vector{PackedVariableNodeData} = PackedVariableNodeData[]
195194
end
196195

197196
StructTypes.StructType(::Type{PackedVariable}) = StructTypes.UnorderedStruct()
@@ -344,6 +343,27 @@ Base.@kwdef struct DFGVariableSummary <: AbstractDFGVariable
344343
dataDict::Dict{Symbol, BlobEntry}
345344
end
346345

346+
function DFGVariableSummary(
347+
id,
348+
label,
349+
timestamp,
350+
tags,
351+
::Nothing,
352+
variableTypeName,
353+
::Nothing,
354+
)
355+
return DFGVariableSummary(
356+
id,
357+
label,
358+
timestamp,
359+
tags,
360+
Dict{Symbol, MeanMaxPPE}(),
361+
variableTypeName,
362+
Dict{Symbol, BlobEntry}(),
363+
)
364+
end
365+
366+
StructTypes.names(::Type{DFGVariableSummary}) = ((:variableTypeName, :variableType),)
347367

348368
##------------------------------------------------------------------------------
349369
## SkeletonDFGVariable.jl

src/services/DFGVariable.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ getPPEMean(fg::AbstractDFG, varlabel::Symbol, solveKey::Symbol=:default) =
1616

1717
"$(SIGNATURES)"
1818
getPPESuggested(est::AbstractPointParametricEst) = est.suggested
19-
getPPESuggested(fg::AbstractDFG, varlabel::Symbol, solveKey::Symbol=:default) =
20-
getPPE(fg, varlabel, solveKey) |> getPPESuggested
19+
getPPESuggested(var::DFGVariable, solveKey::Symbol=:default) = getPPE(var, solveKey) |> getPPESuggested
20+
getPPESuggested(dfg::AbstractDFG, varlabel::Symbol, solveKey::Symbol=:default) = getPPE(getVariable(dfg, varlabel), solveKey) |> getPPESuggested
2121

2222
"$(SIGNATURES)"
2323
getLastUpdatedTimestamp(est::AbstractPointParametricEst) = est.lastUpdatedTimestamp
@@ -570,7 +570,7 @@ Get variable solverdata for a given solve key.
570570
"""
571571
function getVariableSolverData(dfg::AbstractDFG, variablekey::Symbol, solvekey::Symbol=:default)
572572
v = getVariable(dfg, variablekey)
573-
!haskey(v.solverDataDict, solvekey) && error("Solve key '$solvekey' not found in variable '$variablekey'")
573+
!haskey(v.solverDataDict, solvekey) && throw(KeyError("Solve key '$solvekey' not found in variable '$variablekey'"))
574574
return v.solverDataDict[solvekey]
575575
end
576576

@@ -736,7 +736,7 @@ function deleteVariableSolverData!(dfg::AbstractDFG, variablekey::Symbol, solveK
736736
var = getVariable(dfg, variablekey)
737737

738738
if !haskey(var.solverDataDict, solveKey)
739-
error("VariableNodeData '$(solveKey)' does not exist")
739+
throw(KeyError("VariableNodeData '$(solveKey)' does not exist"))
740740
end
741741
vnd = pop!(var.solverDataDict, solveKey)
742742
return vnd
@@ -793,14 +793,13 @@ Notes
793793
- Defaults on keywords `solveKey` and `method`
794794
795795
Related
796-
getMeanPPE, getMaxPPE, getKDEMean, getKDEFit, getPPEs, getVariablePPEs
796+
[`getMeanPPE`](@ref), [`getMaxPPE`](@ref), [`updatePPE!`](@ref), getKDEMean, getKDEFit, getPPEs, getVariablePPEs
797797
"""
798-
function getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default)
799-
v = getVariable(dfg, variablekey)
800-
!haskey(v.ppeDict, ppekey) && error("PPE key '$ppekey' not found in variable '$variablekey'")
798+
function getPPE(v::DFGVariable, ppekey::Symbol=:default)
799+
!haskey(v.ppeDict, ppekey) && throw(KeyError("PPE key '$ppekey' not found in variable '$(getLabel(v))'"))
801800
return v.ppeDict[ppekey]
802801
end
803-
802+
getPPE(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:default) = getPPE(getVariable(dfg, variablekey), ppekey)
804803
# Not the most efficient call but it at least reuses above (in memory it's probably ok)
805804
getPPE(dfg::AbstractDFG, sourceVariable::VariableDataLevel1, ppekey::Symbol=:default) = getPPE(dfg, sourceVariable.label, ppekey)
806805

@@ -870,7 +869,7 @@ function deletePPE!(dfg::AbstractDFG, variablekey::Symbol, ppekey::Symbol=:defau
870869
var = getVariable(dfg, variablekey)
871870

872871
if !haskey(var.ppeDict, ppekey)
873-
error("VariableNodeData '$(ppekey)' does not exist")
872+
throw(KeyError("VariableNodeData '$(ppekey)' does not exist"))
874873
end
875874
vnd = pop!(var.ppeDict, ppekey)
876875
return vnd

test/testBlocks.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ function PPETestBlock!(fg, v1)
590590
@test_throws ErrorException addPPE!(fg, :a, ppe)
591591

592592
@test listPPEs(fg, :a) == [:default]
593-
# Get the data back - note that this is a reference to above.
594-
@test getPPE(fg, :a, :default) == ppe
595593

594+
# Get the data back - note that this is a reference to above.
595+
@test getPPE(getVariable(fg, :a), :default) == ppe
596596
@test getPPE(fg, :a, :default) == ppe
597597
@test getPPEMean(fg, :a, :default) == ppe.mean
598598
@test getPPEMax(fg, :a, :default) == ppe.max
@@ -601,7 +601,7 @@ function PPETestBlock!(fg, v1)
601601
# Delete it
602602
@test deletePPE!(fg, :a, :default) == ppe
603603

604-
@test_throws ErrorException getPPE(fg, :a, :default)
604+
@test_throws KeyError getPPE(fg, :a, :default)
605605
# Update add it
606606
@test @test_logs (:warn, Regex("'$(ppe.solveKey)' does not exist")) match_mode=:any updatePPE!(fg, :a, ppe) == ppe
607607
# Update update it
@@ -702,7 +702,7 @@ function VSDTestBlock!(fg, v1)
702702
# - `updateVariableSolverData!`
703703
# - `deleteVariableSolverData!`
704704
#
705-
# > - `getVariableSolverDataAll` #TODO Data is already plural so maybe Variables, All or Dict
705+
# > - `getVariableSolverDataAll` #TODO Data is already plural so maybe Variables, All or Dict, or use Datum for singular
706706
# > - `getVariablesSolverData`
707707
#
708708
# **Set like**
@@ -761,7 +761,7 @@ function VSDTestBlock!(fg, v1)
761761
# Delete parametric from v1
762762
@test deleteVariableSolverData!(fg, :a, :parametric) == vnd
763763

764-
@test_throws ErrorException getVariableSolverData(fg, :a, :parametric)
764+
@test_throws KeyError getVariableSolverData(fg, :a, :parametric)
765765

766766
#FIXME copied from lower
767767
@test getSolverData(v1) === v1.solverDataDict[:default]

0 commit comments

Comments
 (0)