Skip to content

Commit 58a87d8

Browse files
committed
DFG version in serialized data
1 parent 182a5b6 commit 58a87d8

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

src/CloudGraphsDFG/CloudGraphsDFG.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ import ...DistributedFactorGraphs: setSolverParams!,
8686
getDataEntry,
8787
addDataEntry!,
8888
updateDataEntry!,
89-
deleteDataEntry!
89+
deleteDataEntry!,
90+
_getDFGVersion
9091

9192
using Neo4j
9293
using Base64

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable; skipAddErro
177177
# Create/update the base variable
178178
# NOTE: We are not merging the variable.tags into the labels anymore. We can index by that but not
179179
# going to pollute the graph with unnecessary (and potentially dangerous) labels.
180-
addProps = Dict("softtype" => "\"$(string(typeof(getSofttype(variable))))\"")
180+
addProps = Dict(
181+
"softtype" => "\"$(string(typeof(getSofttype(variable))))\"",
182+
"_version" => "\"$(_getDFGVersion())\"")
181183
query = """
182184
MATCH (session:$(join(_getLabelsForType(dfg, Session), ":")))
183185
MERGE (node:$(join(_getLabelsForInst(dfg, variable), ":")))
@@ -296,7 +298,9 @@ function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor; skipAddError::Boo
296298
# NOTE: We are no merging the factor tags into the labels anymore. We can index by that but not
297299
# going to pollute the graph with unnecessary (and potentially dangerous) labels.
298300
fnctype = getSolverData(factor).fnc.usrfnc!
299-
addProps = Dict("fnctype" => "\"$(String(_getname(fnctype)))\"")
301+
addProps = Dict(
302+
"fnctype" => "\"$(String(_getname(fnctype)))\"",
303+
"_version" => "\"$(_getDFGVersion())\"")
300304
query = """
301305
MATCH (session:$(join(_getLabelsForType(dfg, Session), ":")))
302306
MERGE (node:$(join(_getLabelsForInst(dfg, factor), ":")))

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using JSON2 # JSON2 requires all properties to be in correct sequence, can't gua
2727
using LinearAlgebra
2828
using SparseArrays
2929
using UUIDs
30+
using Pkg
3031

3132

3233
##==============================================================================

src/services/Serialization.jl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22
# For all types that pack their type into their own structure (e.g. PPE)
33
const TYPEKEY = "_type"
44

5-
# Custom serialization
5+
## Custom serialization
66
using JSON
77
import JSON.show_json
88
import JSON.Writer: StructuralContext, JSONContext, show_json
99
import JSON.Serializations: CommonSerialization, StandardSerialization
1010
JSON.show_json(io::JSONContext, serialization::CommonSerialization, uuid::UUID) = print(io.io, "\"$uuid\"")
1111

12+
## Version checking
13+
function _getDFGVersion()
14+
# Looks like this is deprecated but there's no replacement function yet.
15+
return string(Pkg.installed()["DistributedFactorGraphs"])
16+
end
17+
18+
function _versionCheck(props::Dict{String, Any})
19+
if haskey(props, "_version")
20+
if props["_version"] != _getDFGVersion()
21+
@warn "This data was serialized using DFG $(props["_version"]) but you have $(_getDFGVersion()) installed, there may be deserialization issues."
22+
end
23+
else
24+
@warn "There isn't a version tag in this data so it older than v0.10, there may be deserialization issues."
25+
end
26+
end
1227

1328
##==============================================================================
1429
## Variable Packing and unpacking
@@ -29,6 +44,7 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
2944
props["dataEntry"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> JSON.json(bde), values(v.dataDict))))
3045

3146
props["dataEntryType"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> typeof(bde), values(v.dataDict))))
47+
props["_version"] = _getDFGVersion()
3248
return props
3349
end
3450

@@ -72,6 +88,8 @@ function unpackVariable(dfg::G,
7288
unpackSolverData::Bool=true,
7389
unpackBigData::Bool=true)::DFGVariable where G <: AbstractDFG
7490
@debug "Unpacking variable:\r\n$packedProps"
91+
# Version checking.
92+
_versionCheck(packedProps)
7593
label = Symbol(packedProps["label"])
7694
# Make sure that the timestamp is correctly formatted with subseconds
7795
packedProps["timestamp"] = replace(packedProps["timestamp"], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3")
@@ -203,7 +221,7 @@ function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstract
203221
props["fnctype"] = String(_getname(fnctype))
204222
props["_variableOrderSymbols"] = JSON2.write(f._variableOrderSymbols)
205223
props["solvable"] = getSolvable(f)
206-
224+
props["_version"] = _getDFGVersion()
207225
return props
208226
end
209227

@@ -219,6 +237,9 @@ end
219237

220238

221239
function unpackFactor(dfg::G, packedProps::Dict{String, Any})::DFGFactor where G <: AbstractDFG
240+
# Version checking.
241+
_versionCheck(packedProps)
242+
222243
label = packedProps["label"]
223244
# Make sure that the timestamp is correctly formatted with subseconds
224245
packedProps["timestamp"] = replace(packedProps["timestamp"], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3")

0 commit comments

Comments
 (0)