Skip to content

Commit ffe75ea

Browse files
authored
Deprecate and change verb update to merge (#1135)
* update -> merge for Variable and Factor * update -> merge for Blobentry and State --------- Co-authored-by: Johannes Terblanche <Affie@users.noreply.github.com>
1 parent 7b98ea2 commit ffe75ea

19 files changed

+267
-273
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
22

33
# v0.27
44
- `delete` returns number of nodes deleted and no longer the object that was deleted.
5+
- Deprecate `updateVariable!` for `mergeVariable!`, note `merege` returns number of nodes updated/added.
6+
- Deprecate `updateFactor!` for `mergeFactor!`, note `merege` returns number of nodes updated/added.
57

68
# v0.26
79
- Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`.

docs/src/BuildingGraphs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ independently using the functions as discussed in the update section below.
135135

136136
Full variables and factors can be updated using the following functions:
137137

138-
- [`updateVariable!`](@ref)
139-
- [`updateFactor!`](@ref)
138+
- [`mergeVariable!`](@ref)
139+
- [`mergeFactor!`](@ref)
140140

141141

142142
**NOTE**: Skeleton and summary variables are read-only. To perform updates you

docs/src/GraphData.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ Labels are the principle identifier of a variable or factor.
4747
Each variable or factor can have a timestamp associated with it.
4848

4949
- [`getTimestamp`](@ref)
50-
- [`setTimestamp!`](@ref)
5150

5251

5352
#### Tags
@@ -129,7 +128,7 @@ Related functions:
129128
- [`listVariableSolverData`](@ref)
130129
- [`getVariableSolverData`](@ref)
131130
- [`addVariableSolverData!`](@ref)
132-
- [`updateVariableSolverData!`](@ref)
131+
- [`mergeVariableState!`](@ref)
133132
- [`deleteVariableSolverData!`](@ref)
134133
- [`mergeVariableSolverData!`](@ref)
135134

src/DataBlobs/services/BlobEntry.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,21 @@ end
181181

182182
"""
183183
$(SIGNATURES)
184-
Update data entry
185-
186-
DevNote
187-
- DF, unclear if `update` verb is applicable in this case, see #404
184+
Update a Blobentry in the factor graph.
185+
If the Blobentry does not exist, it will be added.
186+
Notes:
188187
"""
189-
function updateBlobEntry!(var::AbstractDFGVariable, bde::BlobEntry)
190-
!haskey(var.dataDict, bde.label) &&
191-
(@warn "$(bde.label) does not exist in variable $(getLabel(var)), adding")
192-
var.dataDict[bde.label] = bde
193-
return bde
188+
function mergeBlobentry!(var::AbstractDFGVariable, bde::BlobEntry)
189+
if !haskey(var.dataDict, bde.label)
190+
addBlobEntry!(var, bde)
191+
else
192+
var.dataDict[bde.label] = bde
193+
end
194+
return 1
194195
end
195-
function updateBlobEntry!(dfg::AbstractDFG, label::Symbol, bde::BlobEntry)
196+
function mergeBlobentry!(dfg::AbstractDFG, label::Symbol, bde::BlobEntry)
196197
# !isVariable(dfg, label) && return nothing
197-
return updateBlobEntry!(getVariable(dfg, label), bde)
198+
return mergeBlobentry!(getVariable(dfg, label), bde)
198199
end
199200

200201
"""

src/DataBlobs/services/BlobStores.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function addBlob! end
2525
"""
2626
Update a blob to the blob store or dfg with the given entry.
2727
Related
28-
[`updateBlobEntry!`](@ref)
28+
[`mergeBlobentry!`](@ref)
2929
3030
$(METHODLIST)
3131

src/DataBlobs/services/HelpersDataWrapEntryBlob.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function addData! end
2525
"""
2626
Update a blob entry or blob to the blob store or dfg.
2727
Related
28-
[`updateBlobEntry!`](@ref)
28+
[`mergeBlobentry!`](@ref)
2929
3030
$(METHODLIST)
3131
"""
@@ -247,9 +247,9 @@ function updateData!(
247247
)
248248
checkhash && assertHash(entry, blob; hashfunction)
249249
# order of ops with unknown new blobId not tested
250-
de = updateBlobEntry!(dfg, label, entry)
250+
mergeBlobentry!(dfg, label, entry)
251251
db = updateBlob!(dfg, de, blob)
252-
return de => db
252+
return 2
253253
end
254254

255255
function updateData!(
@@ -269,10 +269,9 @@ function updateData!(
269269
origin = buildSourceString(dfg, label),
270270
_version = string(_getDFGVersion()),
271271
)
272-
273-
de = updateBlobEntry!(dfg, label, newEntry)
274-
db = updateBlob!(blobstore, de, blob)
275-
return de => db
272+
mergeBlobentry!(dfg, label, newEntry)
273+
updateBlob!(blobstore, newEntry, blob)
274+
return 2
276275
end
277276

278277
function deleteData!(dfg::AbstractDFG, vLbl::Symbol, bLbl::Symbol)

src/Deprecated.jl

Lines changed: 145 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,151 @@
33
##=================================================================================
44

55
@deprecate getNeighborhood(args...; kwargs...) listNeighborhood(args...; kwargs...)
6-
@deprecate addBlob!(store::AbstractBlobStore, blobId::UUID, data, ::String) addBlob!(store, blobId, data)
7-
@deprecate addBlob!(store::AbstractBlobStore{T}, data::T, ::String) where {T} addBlob!(store, uuid4(), data)
6+
@deprecate addBlob!(store::AbstractBlobStore, blobId::UUID, data, ::String) addBlob!(
7+
store,
8+
blobId,
9+
data,
10+
)
11+
@deprecate addBlob!(store::AbstractBlobStore{T}, data::T, ::String) where {T} addBlob!(
12+
store,
13+
uuid4(),
14+
data,
15+
)
16+
17+
@deprecate updateVariable!(args...) mergeVariable!(args...)
18+
@deprecate updateFactor!(args...) mergeFactor!(args...)
19+
20+
@deprecate updateBlobEntry!(args...) mergeBlobentry!(args...)
21+
@deprecate updateGraphBlobEntry!(args...) mergeGraphBlobentry!(args...)
22+
@deprecate updateAgentBlobEntry!(args...) mergeAgentBlobentry!(args...)
23+
24+
export updateVariableSolverData!
25+
26+
#TODO possibly completely deprecated or not exported until update verb is standardized
27+
function updateVariableSolverData!(
28+
dfg::AbstractDFG,
29+
variablekey::Symbol,
30+
vnd::VariableNodeData,
31+
useCopy::Bool = false,
32+
fields::Vector{Symbol} = Symbol[];
33+
warn_if_absent::Bool = true,
34+
)
35+
#This is basically just setSolverData
36+
var = getVariable(dfg, variablekey)
37+
warn_if_absent &&
38+
!haskey(var.solverDataDict, vnd.solveKey) &&
39+
@warn "VariableNodeData '$(vnd.solveKey)' does not exist, adding"
40+
41+
# for InMemoryDFGTypes do memory copy or repointing, for cloud this would be an different kind of update.
42+
usevnd = vnd # useCopy ? deepcopy(vnd) : vnd
43+
# should just one, or many pointers be updated?
44+
useExisting =
45+
haskey(var.solverDataDict, vnd.solveKey) &&
46+
isa(var.solverDataDict[vnd.solveKey], VariableNodeData) &&
47+
length(fields) != 0
48+
# @error useExisting vnd.solveKey
49+
if useExisting
50+
# change multiple pointers inside the VND var.solverDataDict[solvekey]
51+
for field in fields
52+
destField = getfield(var.solverDataDict[vnd.solveKey], field)
53+
srcField = getfield(usevnd, field)
54+
if isa(destField, Array) && size(destField) == size(srcField)
55+
# use broadcast (in-place operation)
56+
destField .= srcField
57+
else
58+
# change pointer of destination VND object member
59+
setfield!(var.solverDataDict[vnd.solveKey], field, srcField)
60+
end
61+
end
62+
else
63+
# change a single pointer in var.solverDataDict
64+
var.solverDataDict[vnd.solveKey] = usevnd
65+
end
66+
67+
return var.solverDataDict[vnd.solveKey]
68+
end
69+
70+
function updateVariableSolverData!(
71+
dfg::AbstractDFG,
72+
variablekey::Symbol,
73+
vnd::VariableNodeData,
74+
solveKey::Symbol,
75+
useCopy::Bool = false,
76+
fields::Vector{Symbol} = Symbol[];
77+
warn_if_absent::Bool = true,
78+
)
79+
# TODO not very clean
80+
if vnd.solveKey != solveKey
81+
@warn(
82+
"updateVariableSolverData with solveKey parameter might change in the future, see DFG #565. Future warnings are suppressed",
83+
maxlog = 1
84+
)
85+
usevnd = useCopy ? deepcopy(vnd) : vnd
86+
usevnd.solveKey = solveKey
87+
return updateVariableSolverData!(
88+
dfg,
89+
variablekey,
90+
usevnd,
91+
useCopy,
92+
fields;
93+
warn_if_absent = warn_if_absent,
94+
)
95+
else
96+
return updateVariableSolverData!(
97+
dfg,
98+
variablekey,
99+
vnd,
100+
useCopy,
101+
fields;
102+
warn_if_absent = warn_if_absent,
103+
)
104+
end
105+
end
106+
107+
function updateVariableSolverData!(
108+
dfg::AbstractDFG,
109+
sourceVariable::VariableCompute,
110+
solveKey::Symbol = :default,
111+
useCopy::Bool = false,
112+
fields::Vector{Symbol} = Symbol[];
113+
warn_if_absent::Bool = true,
114+
)
115+
#
116+
vnd = getSolverData(sourceVariable, solveKey)
117+
# toshow = listSolveKeys(sourceVariable) |> collect
118+
# @info "update DFGVar solveKey" solveKey vnd.solveKey
119+
# @show toshow
120+
@assert solveKey == vnd.solveKey "VariableNodeData's solveKey=:$(vnd.solveKey) does not match requested :$solveKey"
121+
return updateVariableSolverData!(
122+
dfg,
123+
sourceVariable.label,
124+
vnd,
125+
useCopy,
126+
fields;
127+
warn_if_absent = warn_if_absent,
128+
)
129+
end
130+
131+
function updateVariableSolverData!(
132+
dfg::AbstractDFG,
133+
sourceVariables::Vector{<:VariableCompute},
134+
solveKey::Symbol = :default,
135+
useCopy::Bool = false,
136+
fields::Vector{Symbol} = Symbol[];
137+
warn_if_absent::Bool = true,
138+
)
139+
#I think cloud would do this in bulk for speed
140+
for var in sourceVariables
141+
updateVariableSolverData!(
142+
dfg,
143+
var.label,
144+
getSolverData(var, solveKey),
145+
useCopy,
146+
fields;
147+
warn_if_absent = warn_if_absent,
148+
)
149+
end
150+
end
8151

9152
## ================================================================================
10153
## Deprecated in v0.25
@@ -69,4 +212,3 @@ DFGSummary(args) = error("DFGSummary is deprecated")
69212
)
70213

71214
@deprecate lsfWho(dfg::AbstractDFG, type::Symbol) lsf(dfg, getfield(Main, type))
72-

src/DistributedFactorGraphs.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ export getGraphBlobEntry,
7979
getGraphBlobEntries,
8080
addGraphBlobEntry!,
8181
addGraphBlobEntries!,
82-
updateGraphBlobEntry!,
82+
mergeGraphBlobentry!,
8383
deleteGraphBlobEntry!,
8484
getAgentBlobEntry,
8585
getAgentBlobEntries,
8686
addAgentBlobEntry!,
8787
addAgentBlobEntries!,
88-
updateAgentBlobEntry!,
88+
mergeAgentBlobentry!,
8989
deleteAgentBlobEntry!,
9090
listGraphBlobEntries,
9191
listAgentBlobEntries
@@ -110,8 +110,8 @@ export exists,
110110
addFactors!,
111111
getVariable,
112112
getFactor,
113-
updateVariable!,
114-
updateFactor!,
113+
mergeVariable!,
114+
mergeFactor!,
115115
deleteVariable!,
116116
deleteFactor!,
117117
listVariables,
@@ -145,7 +145,7 @@ export getSolvable, setSolvable!, isSolvable
145145
export getVariableLabelNumber
146146

147147
# accessors
148-
export getLabel, getTimestamp, setTimestamp, setTimestamp!, getTags, setTags!
148+
export getLabel, getTimestamp, setTimestamp, getTags, setTags!
149149

150150
export getAgentLabel, getGraphLabel
151151

@@ -186,7 +186,7 @@ export getMetadata,
186186
# CRUD & SET
187187
export getVariableSolverData,
188188
addVariableSolverData!,
189-
updateVariableSolverData!,
189+
mergeVariableState!,
190190
deleteVariableSolverData!,
191191
listVariableSolverData,
192192
mergeVariableSolverData!,
@@ -228,7 +228,7 @@ export hasBlobEntry,
228228
getBlobEntryFirst,
229229
addBlobEntry!,
230230
addBlobEntries!,
231-
updateBlobEntry!,
231+
mergeBlobentry!,
232232
deleteBlobEntry!,
233233
listBlobEntrySequence,
234234
mergeBlobEntries!

src/GraphsDFG/GraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import ...DistributedFactorGraphs:
2727
exists,
2828
isVariable,
2929
isFactor,
30-
updateVariable!,
31-
updateFactor!,
30+
mergeVariable!,
31+
mergeFactor!,
3232
deleteVariable!,
3333
deleteFactor!,
3434
getVariables,

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -134,37 +134,29 @@ function getFactor(dfg::GraphsDFG, label::Symbol)
134134
return dfg.g.factors[label]
135135
end
136136

137-
function updateVariable!(
138-
dfg::GraphsDFG,
139-
variable::AbstractDFGVariable;
140-
warn_if_absent::Bool = true,
141-
)
137+
function mergeVariable!(dfg::GraphsDFG, variable::AbstractDFGVariable)
142138
if !haskey(dfg.g.variables, variable.label)
143-
warn_if_absent &&
144-
@warn "Variable label '$(variable.label)' does not exist in the factor graph, adding"
145-
return addVariable!(dfg, variable)
139+
addVariable!(dfg, variable)
140+
else
141+
dfg.g.variables[variable.label] = variable
146142
end
147-
dfg.g.variables[variable.label] = variable
148-
return variable
143+
return 1
149144
end
150145

151-
function updateFactor!(
152-
dfg::GraphsDFG,
153-
factor::AbstractDFGFactor;
154-
warn_if_absent::Bool = true,
155-
)
146+
function mergeFactor!(dfg::GraphsDFG, factor::AbstractDFGFactor;)
156147
if !haskey(dfg.g.factors, factor.label)
157-
warn_if_absent &&
158-
@warn "Factor label '$(factor.label)' does not exist in the factor graph, adding"
159-
return addFactor!(dfg, factor)
160-
end
161-
162-
# Confirm that we're not updating the neighbors
163-
dfg.g.factors[factor.label]._variableOrderSymbols != factor._variableOrderSymbols &&
148+
addFactor!(dfg, factor)
149+
elseif dfg.g.factors[factor.label]._variableOrderSymbols != factor._variableOrderSymbols
150+
#TODO should we allow merging the factor neighbors or error as before?
164151
error("Cannot update the factor, the neighbors are not the same.")
152+
# We need to delete the factor if we are updating the neighbors
153+
deleteFactor!(dfg, factor.label)
154+
addFactor!(dfg, factor)
155+
else
156+
dfg.g.factors[factor.label] = factor
157+
end
165158

166-
dfg.g.factors[factor.label] = factor
167-
return factor
159+
return 1
168160
end
169161

170162
function deleteVariable!(dfg::GraphsDFG, label::Symbol)#::Tuple{AbstractDFGVariable, Vector{<:AbstractDFGFactor}}

0 commit comments

Comments
 (0)