Skip to content

Commit 785231d

Browse files
authored
Merge pull request #924 from JuliaRobotics/master
v0.18.9-rc1
2 parents 14a5258 + b193629 commit 785231d

File tree

9 files changed

+117
-19
lines changed

9 files changed

+117
-19
lines changed

Project.toml

Lines changed: 3 additions & 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.18.8"
3+
version = "0.18.9"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -17,6 +17,7 @@ ManifoldsBase = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
1717
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1818
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1919
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
20+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
2021
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
2122
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2223
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -40,6 +41,7 @@ ManifoldsBase = "0.11, 0.12, 0.13"
4041
Neo4j = "2"
4142
OrderedCollections = "1.4"
4243
Pkg = "1.4, 1.5"
44+
ProgressMeter = "1"
4345
RecursiveArrayTools = "2"
4446
Reexport = "1"
4547
Requires = "1"

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,25 @@ function getDataEntry(var::AbstractDFGVariable, blobId::UUID)
4141
return v
4242
end
4343
end
44-
error("No dataEntry with blobId $(blobId) found in variable $(getLabel(var))")
44+
throw(
45+
KeyError("No dataEntry with blobId $(blobId) found in variable $(getLabel(var))")
46+
)
4547
end
48+
function getDataEntry(var::AbstractDFGVariable, key::Regex)
49+
for (k,v) in var.dataDict
50+
if occursin(key, string(v.label))
51+
return v
52+
end
53+
end
54+
throw(
55+
KeyError("No dataEntry with label matching regex $(key) found in variable $(getLabel(var))")
56+
)
57+
end
58+
getDataEntry(var::AbstractDFGVariable, key::AbstractString) = getDataEntry(var,Regex(key))
59+
4660

47-
getDataEntry(dfg::AbstractDFG, label::Symbol, key::UUID) = getDataEntry(getVariable(dfg, label), key)
48-
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getDataEntry(getVariable(dfg, label), key)
61+
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:AbstractString, Regex}) = getDataEntry(getVariable(dfg, label), key)
62+
# getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getDataEntry(getVariable(dfg, label), key)
4963

5064

5165
"""
@@ -196,8 +210,11 @@ function mergeDataEntries!(
196210
des = _makevec(des_)
197211
# don't add data entries that already exist
198212
dde = listDataEntries(dst, dlbl)
199-
uids = (s->s.id).(dde)
200-
filter!(s -> !(s.id in uids), des)
213+
# HACK, verb list should just return vector of Symbol. NCE36
214+
_getid(s) = s
215+
_getid(s::AbstractDataEntry) = s.id
216+
uids = _getid.(dde) # (s->s.id).(dde)
217+
filter!(s -> !(_getid(s) in uids), des)
201218
# add any data entries not already in the destination variable, by uuid
202219
addDataEntry!.(dst, dlbl, des)
203220
end
@@ -212,9 +229,67 @@ function mergeDataEntries!(
212229
des = listDataEntries(src, slbl)
213230
# don't add data entries that already exist
214231
dde = listDataEntries(dst, dlbl)
215-
uids = (s->s.id).(dde)
216-
filter!(s -> !(s.id in uids), des)
232+
# HACK, verb list should just return vector of Symbol. NCE36
233+
_getid(s) = s
234+
_getid(s::AbstractDataEntry) = s.id
235+
uids = _getid.(dde) # (s->s.id).(dde)
236+
filter!(s -> !(_getid(s) in uids), des)
217237
if 0 < length(des)
218238
union(((s->mergeDataEntries!(dst, dlbl, src, slbl, s.id)).(des))...)
219239
end
220-
end
240+
end
241+
242+
function mergeDataEntries!(
243+
dest::AbstractDFG,
244+
src::AbstractDFG,
245+
w...;
246+
varList::AbstractVector = listVariables(dest) |> sortDFG
247+
)
248+
@showprogress 1 "merging data entries" for vl in varList
249+
mergeDataEntries!(dest, vl, src, vl, w...)
250+
end
251+
varList
252+
end
253+
254+
"""
255+
$SIGNATURES
256+
257+
If the blob label `datalabel` already exists, then this function will return the name `datalabel_1`.
258+
If the blob label `datalabel_1` already exists, then this function will return the name `datalabel_2`.
259+
"""
260+
function incrDataLabelSuffix(
261+
dfg::AbstractDFG,
262+
vla,
263+
bllb::S;
264+
datalabel=Ref("")
265+
) where {S <: Union{Symbol, <:AbstractString}}
266+
count = 1
267+
hasund = false
268+
len = 0
269+
try
270+
de,_ = getData(dfg, Symbol(vla), bllb)
271+
bllb = string(bllb)
272+
# bllb *= bllb[end] != '_' ? "_" : ""
273+
datalabel[] = string(de.label)
274+
dlb = match(r"\d*", reverse(datalabel[]))
275+
# slightly complicated search if blob name already has an underscore number suffix, e.g. `_4`
276+
count, hasund, len = if occursin(Regex(dlb.match*"_"), reverse(datalabel[]))
277+
parse(Int, dlb.match |> reverse)+1, true, length(dlb.match)
278+
else
279+
1, datalabel[][end] == '_', 0
280+
end
281+
catch err
282+
# append latest count
283+
if !(err isa KeyError)
284+
throw(err)
285+
end
286+
end
287+
# the piece from old label without the suffix count number
288+
bllb = datalabel[][1:(end-len)]
289+
if !hasund || bllb[end] != '_'
290+
bllb *= "_"
291+
end
292+
bllb *= string(count)
293+
294+
S(bllb)
295+
end

src/DataBlobs/services/BlobStores.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
function getDataBlob(dfg::AbstractDFG, entry::BlobStoreEntry)
66
# cannot use entry.blobstore because the blob can be in any one of the blobstores
77
stores = getBlobStores(dfg)
8-
blob = UInt8[]
98
for (k,store) in stores
109
try
1110
blob = getDataBlob(store, entry)
@@ -18,7 +17,7 @@ function getDataBlob(dfg::AbstractDFG, entry::BlobStoreEntry)
1817
end
1918
throw(
2019
KeyError(
21-
"could not find $(entry.label), uuid $(entry.id)) in any of the listed blobstores:\n $((s->getKey(s)).(stores))"
20+
"could not find $(entry.label), uuid $(entry.id)) in any of the listed blobstores:\n $([s->getKey(s) for (s,v) in stores]))"
2221
)
2322
)
2423
end
@@ -85,7 +84,7 @@ function getData(
8584
dfg::AbstractDFG,
8685
blobstore::AbstractBlobStore,
8786
label::Symbol,
88-
key::Union{Symbol,UUID};
87+
key::Union{Symbol,UUID, <:AbstractString, Regex};
8988
hashfunction = sha256,
9089
checkhash::Bool=true
9190
)

src/DataBlobs/services/DataEntryBlob.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ end
114114
function getData(
115115
dfg::AbstractDFG,
116116
vlabel::Symbol,
117-
key::Union{Symbol,UUID};
117+
key::Union{Symbol,UUID, <:AbstractString, Regex};
118118
hashfunction = sha256,
119119
checkhash::Bool=true
120120
)

src/DistributedFactorGraphs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using SparseArrays
3030
using UUIDs
3131
using Pkg
3232
using TensorCast
33+
using ProgressMeter
3334

3435
# used for @defVariable
3536
import ManifoldsBase
@@ -192,12 +193,14 @@ export getSolvedCount, isSolved, setSolvedCount!, isInitialized, isMarginalized,
192193
export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
193194
export findFactorsBetweenNaive
194195
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
195-
# Big Data
196+
197+
# Entry Blob Data
196198
##------------------------------------------------------------------------------
197199
export addDataEntry!, getDataEntry, updateDataEntry!, deleteDataEntry!, getDataEntries, listDataEntries, hasDataEntry, hasDataEntry
198200
export listDataEntrySequence
199201
# convenience wrappers
200202
export addDataEntry!, mergeDataEntries!
203+
export incrDataLabelSuffix
201204
# aliases
202205
export addData!
203206

src/services/AbstractDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ function copyGraph!(destDFG::AbstractDFG,
950950
copyGraphMetadata::Bool=false,
951951
overwriteDest::Bool=false,
952952
deepcopyNodes::Bool=false,
953-
verbose::Bool = true)
953+
verbose::Bool = false)
954954
# Split into variables and factors
955955
sourceVariables = map(vId->getVariable(sourceDFG, vId), variableLabels)
956956
sourceFactors = map(fId->getFactor(sourceDFG, fId), factorLabels)

src/services/Serialization.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525
function _versionCheck(props::Dict{String, Any})
2626
if haskey(props, "_version")
2727
if props["_version"] != _getDFGVersion()
28-
@warn "This data was serialized using DFG $(props["_version"]) but you have $(_getDFGVersion()) installed, there may be deserialization issues."
28+
@warn "This data was serialized using DFG $(props["_version"]) but you have $(_getDFGVersion()) installed, there may be deserialization issues." maxlog=10
2929
end
3030
else
3131
@warn "There isn't a version tag in this data so it's older than v0.10, there may be deserialization issues."
@@ -442,9 +442,13 @@ end
442442

443443

444444
# Returns `::DFGFactor`
445-
function unpackFactor(dfg::G, packedProps::Dict{String, Any}) where G <: AbstractDFG
445+
function unpackFactor(
446+
dfg::G,
447+
packedProps::Dict{String, Any};
448+
skipVersionCheck::Bool=false
449+
) where G <: AbstractDFG
446450
# Version checking.
447-
_versionCheck(packedProps)
451+
!skipVersionCheck && _versionCheck(packedProps)
448452

449453
label = packedProps["label"]
450454
# Make sure that the timestamp is correctly formatted with subseconds

test/consol_DataEntryBlobTests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,18 @@ ds = FolderStore{Vector{UInt8}}(:filestore, "/tmp/dfgFolderStore")
9292
addBlobStore!(dfg, ds)
9393

9494
ade,adb = addData!(dfg, :filestore, :x1, :random, dataset1)
95+
_,_ = addData!(dfg, :filestore, :x1, :another_1, dataset1)
96+
_,_ = getData(dfg, :x1, "random")
97+
_,_ = getData(dfg, :x1, r"rando")
9598
gde,gdb = getData(dfg, :x1, :random)
99+
100+
@test incrDataLabelSuffix(dfg,:x1,:random) == :random_1
101+
@test incrDataLabelSuffix(dfg,:x1,:another_1) == :another_2
102+
# @test incrDataLabelSuffix(dfg,:x1,:another) == :another_2 # TODO exand support for Regex likely search on labels
103+
# @test incrDataLabelSuffix(dfg,:x1,"random") == "random_1" # TODO expand support for label::String
104+
96105
dde,ddb = deleteData!(dfg, :x1, :random)
106+
_,_ = deleteData!(dfg, :x1, :another_1)
97107

98108
@test ade == gde == dde
99109
@test adb == gdb == ddb

test/testBlocks.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,10 @@ function ProducingDotFiles(testDFGAPI,
14371437

14381438
addVariable!(dotdfg, v1)
14391439
addVariable!(dotdfg, v2)
1440+
# FIXME, fix deprecation
1441+
# ┌ Warning: addFactor!(dfg, variables, factor) is deprecated, use addFactor!(dfg, factor)
1442+
# │ caller = ProducingDotFiles(testDFGAPI::Type{GraphsDFG}, v1::Nothing, v2::Nothing, f1::Nothing; VARTYPE::Type{DFGVariable}, FACTYPE::Type{DFGFactor}) at testBlocks.jl:1440
1443+
# └ @ Main ~/.julia/dev/DistributedFactorGraphs/test/testBlocks.jl:1440
14401444
addFactor!(dotdfg, [v1, v2], f1)
14411445
#NOTE hardcoded toDot will have different results so test LightGraphs seperately
14421446
if testDFGAPI <: LightDFG || testDFGAPI <: GraphsDFG || testDFGAPI <: Neo4jDFG
@@ -1490,7 +1494,8 @@ function CopyFunctionsTest(testDFGAPI; kwargs...)
14901494
@test issetequal(lsf(dcdfg_part), flbls)
14911495

14921496
# deepcopy subgraph ignoring orphans
1493-
@test_logs (:warn, r"orphan") dcdfg_part = deepcopyGraph(LightDFG, dfg, vlbls, union(flbls, [:x1x2f1]))
1497+
# @test_logs (:warn, r"orphan") # orphan warning has been suppressed given overwhelming printouts
1498+
dcdfg_part = deepcopyGraph(LightDFG, dfg, vlbls, union(flbls, [:x1x2f1]))
14941499
@test issetequal(ls(dcdfg_part), vlbls)
14951500
@test issetequal(lsf(dcdfg_part), flbls)
14961501

0 commit comments

Comments
 (0)