From 9cdcf756189fe5982ef469a363bd9f4e45bf84ce Mon Sep 17 00:00:00 2001 From: Johannes Terblanche Date: Tue, 12 May 2026 14:21:56 +0200 Subject: [PATCH] Add DFG types serialization version to relevant structs --- src/GraphsDFG/entities/GraphsDFG.jl | 12 ++++++------ src/Serialization/PackedSerialization.jl | 16 +++++++++++++--- src/entities/Agent_and_Graph.jl | 4 ++++ src/entities/Blobentry.jl | 6 +++--- src/entities/Factor.jl | 12 +++++------- src/entities/State.jl | 3 +++ src/entities/Variable.jl | 18 ++++++++---------- 7 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/GraphsDFG/entities/GraphsDFG.jl b/src/GraphsDFG/entities/GraphsDFG.jl index 3b4c582c..6dc69dea 100644 --- a/src/GraphsDFG/entities/GraphsDFG.jl +++ b/src/GraphsDFG/entities/GraphsDFG.jl @@ -33,12 +33,12 @@ function GraphsDFG{T, V, F}( graphTags::Union{Set{Symbol}, Vector{Symbol}} = Set{Symbol}(), graphBloblets::Bloblets = Bloblets(), graphBlobentries = Blobentries(), - graph::Graphroot = Graphroot( - graphLabel, - graphDescription, - graphTags, - graphBloblets, - graphBlobentries, + graph::Graphroot = Graphroot(; + label = graphLabel, + description = graphDescription, + tags = graphTags, + bloblets = graphBloblets, + blobentries = graphBlobentries, ), agents::OrderedDict{Symbol, Agent} = OrderedDict{Symbol, Agent}(), #TODO deprecated v0.29 diff --git a/src/Serialization/PackedSerialization.jl b/src/Serialization/PackedSerialization.jl index f835710b..169bab5b 100644 --- a/src/Serialization/PackedSerialization.jl +++ b/src/Serialization/PackedSerialization.jl @@ -69,8 +69,17 @@ See also: [`pack`](@ref), [`Packed`](@ref) """ function unpack end -version(::Type{T}) where {T} = pkgversion(parentmodule(T)) -# version(node) = node.version +""" + DFG_TYPES_VERSION + +DFG types serialization format version, tracked separately from `pkgversion(DistributedFactorGraphs)`. +All independently serialized DFG CRUD nodes (`VariableDFG`, `FactorDFG`, `State`, `Blobentry`, +`Agent`, `Graphroot`) embed this version so that serialized data remains compatible +across minor/patch releases of the DFG package. + +Bump this when any serialized DFG type changes its field layout. +""" +const DFG_TYPES_VERSION::VersionNumber = v"0.1" """ TypeMetadata(pkg, name, version) @@ -91,7 +100,8 @@ struct TypeMetadata end function TypeMetadata(::Type{T}) where {T} - return TypeMetadata(fullname(parentmodule(T))[1], nameof(T), version(T)) + mod = parentmodule(T) + return TypeMetadata(fullname(mod)[1], nameof(T), pkgversion(mod)) end """ diff --git a/src/entities/Agent_and_Graph.jl b/src/entities/Agent_and_Graph.jl index fa090c2e..d86e8167 100644 --- a/src/entities/Agent_and_Graph.jl +++ b/src/entities/Agent_and_Graph.jl @@ -5,6 +5,8 @@ tags::Set{Symbol} = Set{Symbol}() bloblets::Bloblets = Bloblets() blobentries::Blobentries = Blobentries() + """ DFG types serialization format version.""" + version::VersionNumber = DFG.DFG_TYPES_VERSION end @kwdef mutable struct Graphroot @@ -13,6 +15,8 @@ end tags::Set{Symbol} = Set{Symbol}() bloblets::Bloblets = Bloblets() blobentries::Blobentries = Blobentries() + """ DFG types serialization format version.""" + version::VersionNumber = DFG.DFG_TYPES_VERSION end #TODO diff --git a/src/entities/Blobentry.jl b/src/entities/Blobentry.jl index b25f196c..9510f32e 100644 --- a/src/entities/Blobentry.jl +++ b/src/entities/Blobentry.jl @@ -30,10 +30,10 @@ StructUtils.@kwarg struct Blobentry metadata::JSONText = JSONText("{}") """ When the Blob itself was first created. Serialized as an ISO 8601 string.""" timestamp::TimeDateZone = now_tdz() - """ Type version of this Blobentry.""" - version::VersionNumber = DFG.version(Blobentry) + """ DFG serialization format version.""" + """ DFG types serialization format version.""" + version::VersionNumber = DFG.DFG_TYPES_VERSION end -version(::Type{Blobentry}) = v"0.1.0" # construction helper from existing Blobentry for user overriding via kwargs function Blobentry(entry::Blobentry; kwargs...) diff --git a/src/entities/Factor.jl b/src/entities/Factor.jl index 106a5813..e5af5d04 100644 --- a/src/entities/Factor.jl +++ b/src/entities/Factor.jl @@ -91,14 +91,12 @@ StructUtils.@kwarg struct FactorDFG{T <: AbstractObservation, N} <: AbstractGrap solvercache::Base.RefValue{<:FactorCache} = Ref{FactorCache}() & (ignore = true,)#TODO easy of use vs. performance as container is abstract in any case. """Blobentries associated with this factor.""" blobentries::Blobentries = Blobentries() #NOTE v0.29 added - """Internal: used for automatic type metadata generation.""" - _autotype::Nothing = nothing & (name = :type, lower = _ -> TypeMetadata(FactorDFG)) + """ DFG types serialization format version.""" + version::VersionNumber = DFG.DFG_TYPES_VERSION end -version(::Type{<:FactorDFG}) = v"0.29.0" - -##------------------------------------------------------------------------------ -## Constructors - IIF like +#------------------------------------------------------------------------------ +# Constructors - IIF like function FactorDFG( variableorder::Union{<:Tuple, Vector{Symbol}}, observation::AbstractObservation; @@ -201,7 +199,7 @@ function FactorDFG( state, solvercache, blobentries, - nothing, + DFG_TYPES_VERSION, ) end diff --git a/src/entities/State.jl b/src/entities/State.jl index 9a44ed6c..f4100ac8 100644 --- a/src/entities/State.jl +++ b/src/entities/State.jl @@ -30,6 +30,8 @@ $(TYPEDFIELDS) marginalized::Bool = false #TODO renamed from ismargin v0.29 """How many times has a solver updated this state estimate.""" solves::Int = 0 # TODO renamed from solvedCount v0.29 + """ DFG types serialization format version.""" + version::VersionNumber = DFG.DFG_TYPES_VERSION end # OLD deprecated fields, removed in v0.29, kept here for reference during transition # val::Vector{P} = Vector{P}() @@ -89,6 +91,7 @@ function StructUtils.fielddefaults( marginalized = false, solves = 0, statekind = T(), + version = DFG_TYPES_VERSION, ) end diff --git a/src/entities/Variable.jl b/src/entities/Variable.jl index 3ab258bc..71e22328 100644 --- a/src/entities/Variable.jl +++ b/src/entities/Variable.jl @@ -52,10 +52,9 @@ $(TYPEDFIELDS) Accessors: [`getSolvable`](@ref), [`setSolvable!`](@ref)""" solvable::Base.RefValue{Int} = Ref{Int}(1) #& (lower = getindex,) statekind::T = T() - # TODO autotype or version and statekind - _autotype::Nothing = nothing #& (name = :type, lower = _ -> TypeMetadata(VariableDFG)) + """ DFG types serialization format version.""" + version::VersionNumber = DFG.DFG_TYPES_VERSION end -version(::Type{<:VariableDFG}) = v"0.29" refStates(v::VariableDFG) = v.states #NOTE fielddefaults and fieldtags not through @kwarg macro due to error with State{T, P, N} @@ -70,16 +69,15 @@ function StructUtils.fielddefaults( bloblets = Bloblets(), blobentries = Blobentries(), solvable = Ref(1), - _autotype = nothing, + version = DFG.DFG_TYPES_VERSION, ) end -function StructUtils.fieldtags(::StructUtils.StructStyle, ::Type{<:VariableDFG}) - return ( - _autotype = (name = :type, lower = _ -> TypeMetadata(VariableDFG)), - # solvable = (lower = getindex,), - ) -end +# function StructUtils.fieldtags(::StructUtils.StructStyle, ::Type{<:VariableDFG}) +# return ( +# solvable = (lower = getindex,), +# ) +# end function resolveVariableDFGType(lazyobj) statekind = liftStateKind(lazyobj.statekind[])