Skip to content

Commit a672739

Browse files
committed
Add some missing functions, Blobentry and merge
1 parent 4a13246 commit a672739

10 files changed

Lines changed: 151 additions & 112 deletions

File tree

docs/src/GraphData.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,6 @@ Agent and Graph bloblets are useful for storing data that is related to the enti
161161
Example of using graph-level data:
162162

163163
```julia
164-
setAgentMetadata!(dfg, Dict(:a => "Hello"))
165-
getAgentMetadata(dfg)
164+
addAgentBloblet!(dfg, Bloblet(:status, "ready"))
165+
getAgentBloblet(dfg, :status)
166166
```

src/DataBlobs/services/BlobEntry.jl

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ end
1313
function getBlobentries(
1414
node;
1515
labelFilter::Union{Nothing, Function} = nothing,
16-
blobIdFilter::Union{Nothing, Function} = nothing,
16+
blobidFilter::Union{Nothing, Function} = nothing,
1717
)
1818
entries = collect(values(refBlobentries(node)))
1919
filterDFG!(entries, labelFilter, getLabel)
20-
filterDFG!(entries, blobIdFilter, x -> string(x.blobid))
20+
filterDFG!(entries, blobidFilter, x -> string(x.blobid))
2121
return entries
2222
end
2323

@@ -195,6 +195,52 @@ function listModelBlobentries end
195195
function hasGraphBlobentry end
196196
function hasAgentBlobentry end
197197
function hasModelBlobentry end
198+
199+
##==============================================================================
200+
## Default Variable/Factor implementations
201+
##==============================================================================
202+
203+
function getVariableBlobentry(dfg::AbstractDFG, variableLabel::Symbol, label::Symbol)
204+
return getBlobentry(getVariable(dfg, variableLabel), label)
205+
end
206+
207+
function getVariableBlobentries(
208+
dfg::AbstractDFG,
209+
variableLabel::Symbol;
210+
labelFilter::Union{Nothing, Function} = nothing,
211+
blobidFilter::Union{Nothing, Function} = nothing,
212+
)
213+
return getBlobentries(getVariable(dfg, variableLabel); labelFilter, blobidFilter)
214+
end
215+
216+
function listVariableBlobentries(dfg::AbstractDFG, variableLabel::Symbol)
217+
return listBlobentries(getVariable(dfg, variableLabel))
218+
end
219+
220+
function hasVariableBlobentry(dfg::AbstractDFG, variableLabel::Symbol, label::Symbol)
221+
return hasBlobentry(getVariable(dfg, variableLabel), label)
222+
end
223+
224+
function getFactorBlobentry(dfg::AbstractDFG, factorLabel::Symbol, label::Symbol)
225+
return getBlobentry(getFactor(dfg, factorLabel), label)
226+
end
227+
228+
function getFactorBlobentries(
229+
dfg::AbstractDFG,
230+
factorLabel::Symbol;
231+
labelFilter::Union{Nothing, Function} = nothing,
232+
blobidFilter::Union{Nothing, Function} = nothing,
233+
)
234+
return getBlobentries(getFactor(dfg, factorLabel); labelFilter, blobidFilter)
235+
end
236+
237+
function listFactorBlobentries(dfg::AbstractDFG, factorLabel::Symbol)
238+
return listBlobentries(getFactor(dfg, factorLabel))
239+
end
240+
241+
function hasFactorBlobentry(dfg::AbstractDFG, factorLabel::Symbol, label::Symbol)
242+
return hasBlobentry(getFactor(dfg, factorLabel), label)
243+
end
198244
##==============================================================================
199245
## Blobentry [default] bulk operations
200246
##==============================================================================
@@ -280,19 +326,10 @@ end
280326
## Blobentry - Helper functions, Lists, etc
281327
##==============================================================================
282328

283-
function getVariableBlobentries(
284-
dfg::AbstractDFG,
285-
variableLabel::Symbol;
286-
labelFilter::Union{Nothing, Function} = nothing,
287-
blobIdFilter::Union{Nothing, Function} = nothing,
288-
)
289-
return getBlobentries(getVariable(dfg, variableLabel); labelFilter, blobIdFilter)
290-
end
291-
292329
function gatherBlobentries(
293330
dfg::AbstractDFG;
294331
labelFilter::Union{Nothing, Function} = nothing,
295-
blobIdFilter::Union{Nothing, Function} = nothing,
332+
blobidFilter::Union{Nothing, Function} = nothing,
296333
solvableFilter::Union{Nothing, Function} = nothing,
297334
tagsFilter::Union{Nothing, Function} = nothing,
298335
typeFilter::Union{Nothing, Function} = nothing,
@@ -306,15 +343,11 @@ function gatherBlobentries(
306343
labelFilter = variableLabelFilter,
307344
)
308345
return map(vls) do vl
309-
return vl => getVariableBlobentries(dfg, vl; labelFilter, blobIdFilter)
346+
return vl => getVariableBlobentries(dfg, vl; labelFilter, blobidFilter)
310347
end
311348
end
312349
const collectBlobentries = gatherBlobentries
313350

314-
function listVariableBlobentries(dfg::AbstractDFG, label::Symbol)
315-
return listBlobentries(getVariable(dfg, label))
316-
end
317-
318351
"""
319352
$(SIGNATURES)
320353
Finds and returns the first blob entry that matches the filter.
@@ -324,11 +357,11 @@ Also see: [`getBlobentry`](@ref)
324357
function getfirstBlobentry(
325358
node;
326359
labelFilter::Union{Nothing, Function} = nothing,
327-
blobIdFilter::Union{Nothing, Function} = nothing,
360+
blobidFilter::Union{Nothing, Function} = nothing,
328361
sortby::Function = getLabel,
329362
sortlt::Function = natural_lt,
330363
)
331-
entries = getBlobentries(node; labelFilter, blobIdFilter)
364+
entries = getBlobentries(node; labelFilter, blobidFilter)
332365
if isempty(entries)
333366
return nothing
334367
else
@@ -340,9 +373,9 @@ function getfirstVariableBlobentry(
340373
dfg::AbstractDFG,
341374
label::Symbol;
342375
labelFilter::Union{Nothing, Function} = nothing,
343-
blobIdFilter::Union{Nothing, Function} = nothing,
376+
blobidFilter::Union{Nothing, Function} = nothing,
344377
)
345-
return getfirstBlobentry(getVariable(dfg, label); labelFilter, blobIdFilter)
378+
return getfirstBlobentry(getVariable(dfg, label); labelFilter, blobidFilter)
346379
end
347380

348381
## =============================================================================

src/Deprecated.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,18 +629,18 @@ end
629629

630630
function getfirstBlobentry(var::AbstractGraphVariable, blobId::UUID)
631631
Base.depwarn(
632-
"getfirstBlobentry(var, blobId) is deprecated, use getfirstBlobentry(var; blobIdFilter = ==(string(blobId))) instead.",
632+
"getfirstBlobentry(var, blobId) is deprecated, use getfirstBlobentry(var; blobidFilter = ==(string(blobId))) instead.",
633633
:getfirstBlobentry,
634634
)
635-
return getfirstBlobentry(var; blobIdFilter = ==(string(blobId)))
635+
return getfirstBlobentry(var; blobidFilter = ==(string(blobId)))
636636
end
637637

638638
function getfirstBlobentry(dfg::AbstractDFG, label::Symbol, blobId::UUID)
639639
Base.depwarn(
640-
"getfirstBlobentry(dfg, label, blobId) is deprecated, use getfirstBlobentry(dfg, label; blobIdFilter = ==(string(blobId))) instead.",
640+
"getfirstBlobentry(dfg, label, blobId) is deprecated, use getfirstBlobentry(dfg, label; blobidFilter = ==(string(blobId))) instead.",
641641
:getfirstBlobentry,
642642
)
643-
return getfirstBlobentry(dfg, label; blobIdFilter = ==(string(blobId)))
643+
return getfirstBlobentry(dfg, label; blobidFilter = ==(string(blobId)))
644644
end
645645

646646
function getfirstBlobentry(var::AbstractGraphVariable, key::Regex)

src/DistributedFactorGraphs.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ const LocalDFG = GraphsDFG
601601

602602
include("services/Tags.jl")
603603
include("services/Bloblet.jl")
604-
include("services/Blobentry.jl")
605604

606605
# Common includes
607606
include("services/DFGVariable.jl")

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ function mergeVariable!(dfg::GraphsDFG, variable::AbstractGraphVariable)
9191
return 1
9292
end
9393

94-
function DFG.mergeVariables!(dfg::GraphsDFG, variables)
95-
cnts = map(v -> mergeVariable!(dfg, v), variables)
96-
return sum(cnts)
97-
end
98-
9994
function mergeFactor!(dfg::GraphsDFG, factor::AbstractGraphFactor)
10095
if !haskey(dfg.g.factors, factor.label)
10196
addFactor!(dfg, factor)
@@ -112,11 +107,6 @@ function mergeFactor!(dfg::GraphsDFG, factor::AbstractGraphFactor)
112107
return 1
113108
end
114109

115-
function DFG.mergeFactors!(dfg::GraphsDFG, factors)
116-
cnts = map(f -> mergeFactor!(dfg, f), factors)
117-
return sum(cnts)
118-
end
119-
120110
function deleteVariable!(dfg::GraphsDFG, label::Symbol)#::Tuple{AbstractGraphVariable, Vector{<:AbstractGraphFactor}}
121111
if !haskey(dfg.g.variables, label)
122112
throw(LabelNotFoundError("Variable", label))
@@ -653,6 +643,42 @@ function DFG.mergeAgentBlobentries!(dfg::GraphsDFG, entries::Vector{Blobentry})
653643
return sum(cnts)
654644
end
655645

646+
##=============================================================================
647+
## Variable Blobentries
648+
##=============================================================================
649+
650+
function DFG.addVariableBlobentry!(dfg::GraphsDFG, label::Symbol, entry::Blobentry)
651+
variable = getVariable(dfg, label)
652+
addBlobentry!(variable, entry)
653+
return entry
654+
end
655+
656+
function DFG.mergeVariableBlobentry!(dfg::GraphsDFG, label::Symbol, entry::Blobentry)
657+
return mergeBlobentry!(getVariable(dfg, label), entry)
658+
end
659+
660+
function DFG.deleteVariableBlobentry!(dfg::GraphsDFG, label::Symbol, entryLabel::Symbol)
661+
return deleteBlobentry!(getVariable(dfg, label), entryLabel)
662+
end
663+
664+
##=============================================================================
665+
## Factor Blobentries
666+
##=============================================================================
667+
668+
function DFG.addFactorBlobentry!(dfg::GraphsDFG, label::Symbol, entry::Blobentry)
669+
factor = getFactor(dfg, label)
670+
addBlobentry!(factor, entry)
671+
return entry
672+
end
673+
674+
function DFG.mergeFactorBlobentry!(dfg::GraphsDFG, label::Symbol, entry::Blobentry)
675+
return mergeBlobentry!(getFactor(dfg, label), entry)
676+
end
677+
678+
function DFG.deleteFactorBlobentry!(dfg::GraphsDFG, label::Symbol, entryLabel::Symbol)
679+
return deleteBlobentry!(getFactor(dfg, label), entryLabel)
680+
end
681+
656682
function DFG.deleteGraphBlobentry!(dfg::GraphsDFG, label::Symbol)
657683
if !haskey(dfg.graph.blobentries, label)
658684
throw(LabelNotFoundError("Blobentry", label))

src/services/AbstractDFG.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ otherwise, the variable will be added to the graph.
238238
Implement `mergeVariable!(dfg::AbstractDFG, variable::AbstractGraphVariable)`
239239
"""
240240
function mergeVariable! end
241-
function mergeVariables! end
241+
242+
function mergeVariables!(dfg::AbstractDFG, variables::Vector{<:AbstractGraphVariable})
243+
counts = asyncmap(v->mergeVariable!(dfg, v), variables)
244+
return sum(counts)
245+
end
242246

243247
"""
244248
$(SIGNATURES)
@@ -247,7 +251,11 @@ otherwise, the factor will be added to the graph.
247251
Implement `mergeFactor!(dfg::AbstractDFG, factor::AbstractGraphFactor)`
248252
"""
249253
function mergeFactor! end
250-
function mergeFactors! end
254+
255+
function mergeFactors!(dfg::AbstractDFG, factors::Vector{<:AbstractGraphFactor})
256+
counts = asyncmap(f->mergeFactor!(dfg, f), factors)
257+
return sum(counts)
258+
end
251259

252260
"""
253261
$(SIGNATURES)
@@ -436,7 +444,7 @@ Common function for copying nodes from one graph into another graph.
436444
This is overridden in specialized implementations for performance.
437445
Orphaned factors are not added, with a warning if verbose.
438446
Set `overwriteDest` to overwrite existing variables and factors in the destination DFG.
439-
NOTE: copyGraphMetadata not supported yet.
447+
NOTE: `copyGraphMetadata` is deprecated – use agent/graph Bloblets instead.
440448
Related:
441449
- [`deepcopyGraph`](@ref)
442450
- [`deepcopyGraph!`](@ref)
@@ -498,8 +506,10 @@ function copyGraph!(
498506
end
499507

500508
if copyGraphMetadata
501-
setAgentMetadata(destDFG, getAgentMetadata(sourceDFG))
502-
setGraphMetadata(destDFG, getGraphMetadata(sourceDFG))
509+
error(
510+
"copyGraphMetadata keyword has been removed – metadata APIs were replaced by Bloblets. " *
511+
"Copy agent/graph Bloblets manually before calling copyGraph!",
512+
)
503513
end
504514
return nothing
505515
end

src/services/Blobentry.jl

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/iifInterfaceTests.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,13 @@ end
197197

198198
@test_throws LabelNotFoundError isInitialized(v2, :second)
199199

200-
# Session, robot, and user small data tests
201-
#FIXME change to Bloblets
202-
# smallRobotData = Dict{Symbol, MetadataTypes}(:a => "43", :b => "Hello")
203-
# smallSessionData = Dict{Symbol, MetadataTypes}(:a => "44", :b => "Hello")
204-
# setAgentMetadata!(dfg, deepcopy(smallRobotData))
205-
# setGraphMetadata!(dfg, deepcopy(smallSessionData))
206-
# @test getAgentMetadata(dfg) == smallRobotData
207-
# @test getGraphMetadata(dfg) == smallSessionData
200+
# Graph and Agent small data tests
201+
agentBloblets = [Bloblet(:a, "43"), Bloblet(:b, "Hello")]
202+
graphBloblets = [Bloblet(:c, "44"), Bloblet(:d, "Hello")]
203+
DFG.addAgentBloblets!(dfg, agentBloblets)
204+
DFG.addGraphBloblets!(dfg, graphBloblets)
205+
@test DFG.listAgentBloblets(dfg) == [:a, :b]
206+
@test DFG.listGraphBloblets(dfg) == [:c, :d]
208207
end
209208

210209
@testset "Data Entries" begin

test/interfaceTests.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if false
77
using UUIDs
88
using TimeZones
99
using TimesDates
10+
using DistributedFactorGraphs: OrderedDict
1011

1112
include("testBlocks.jl")
1213

@@ -33,13 +34,13 @@ end
3334
end
3435

3536
# User, Robot, Session Data
36-
# @testset "User, Robot, Session Data" begin
37-
# GraphAgentMetadata!(fg1)
38-
# end
37+
@testset "User, Robot, Session Data" begin
38+
GraphAgentBloblets!(fg1)
39+
end
3940

40-
# @testset "User, Robot, Session Blob Entries" begin
41-
# GraphAgentBlobentries!(fg1)
42-
# end
41+
@testset "User, Robot, Session Blob Entries" begin
42+
GraphAgentBlobentries!(fg1)
43+
end
4344

4445
# VariableCompute structure construction and accessors
4546
@testset "DFG Variable" begin

0 commit comments

Comments
 (0)