diff --git a/src/Deprecated.jl b/src/Deprecated.jl index a323d107..a398daf1 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -90,6 +90,12 @@ const VariableNodeData = VariableState solveKey, ) +@deprecate packVariableNodeData(args...; kwargs...) packVariableState(args...; kwargs...) +@deprecate unpackVariableNodeData(args...; kwargs...) unpackVariableState( + args...; + kwargs..., +) + export updateVariableSolverData! #TODO possibly completely deprecated or not exported until update verb is standardized diff --git a/src/DistributedFactorGraphs.jl b/src/DistributedFactorGraphs.jl index 255e91ae..50fb1d8e 100644 --- a/src/DistributedFactorGraphs.jl +++ b/src/DistributedFactorGraphs.jl @@ -52,6 +52,8 @@ using StaticArrays import Base: getindex +using InteractiveUtils: subtypes + ##============================================================================== # Exports ##============================================================================== diff --git a/src/services/AbstractDFG.jl b/src/services/AbstractDFG.jl index afb847a1..95ceab0e 100644 --- a/src/services/AbstractDFG.jl +++ b/src/services/AbstractDFG.jl @@ -121,7 +121,8 @@ function rebuildFactorCache!( factor::AbstractDFGFactor, neighbors = [], ) - return error("rebuildFactorCache! is not implemented for $(typeof(dfg))") + @warn("rebuildFactorCache! is not implemented for $(typeof(dfg))") + return nothing end """ diff --git a/src/services/DFGFactor.jl b/src/services/DFGFactor.jl index 76a0cee0..1d5abd51 100644 --- a/src/services/DFGFactor.jl +++ b/src/services/DFGFactor.jl @@ -48,7 +48,15 @@ that contains the information about the factor, such as the measurement, prior, getObservation(f::FactorCompute) = f.observation function getObservation(f::FactorDFG) #FIXME completely refactor to not need getTypeFromSerializationModule and just use StructTypes - packtype = DFG.getTypeFromSerializationModule("Packed" * f.fnctype) + + if contains(f.fnctype, ".") + # packed factor contains a module name, just extracting type and ignoring module + fnctype = split(f.fnctype, ".")[end] + else + fnctype = f.fnctype + end + + packtype = DFG.getTypeFromSerializationModule("Packed" * fnctype) return packtype(; JSON3.read(f.observJSON)...) # return packtype(JSON3.read(f.observJSON)) end diff --git a/src/services/Serialization.jl b/src/services/Serialization.jl index 93d650ec..988b93f4 100644 --- a/src/services/Serialization.jl +++ b/src/services/Serialization.jl @@ -40,6 +40,34 @@ end typeModuleName(varT::Type{<:InferenceVariable}) = typeModuleName(varT()) +function parseVariableType(_typeString::AbstractString) + m = match(r"{(\d+)}", _typeString) + if !isnothing(m) #parameters in type + param = parse(Int, m[1]) + typeString = _typeString[1:(m.offset - 1)] + else + param = nothing + typeString = _typeString + end + + all_subtypes = Dict(map(s -> nameof(s) => s, subtypes(InferenceVariable))) + + subtype = get(all_subtypes, Symbol(split(typeString, ".")[end]), nothing) + + if isnothing(subtype) + error("Unable to deserialize type $(_typeString), not found") + return nothing + end + + if isnothing(param) + # no parameters, just return the type + return subtype + else + # return the type with parameters + return subtype{param} + end +end + """ $(SIGNATURES) Get a type from the serialization module. @@ -123,7 +151,7 @@ function unpackVariableState(d::PackedVariableState) # Figuring out the variableType # TODO deprecated remove in v0.11 - for backward compatibility for saved variableTypes. ststring = string(split(d.variableType, "(")[1]) - T = getTypeFromSerializationModule(ststring) + T = parseVariableType(ststring) isnothing(T) && error( "The variable doesn't seem to have a variableType. It needs to set up with an InferenceVariable from IIF. This will happen if you use DFG to add serialized variables directly and try use them. Please use IncrementalInference.addVariable().", ) @@ -206,7 +234,7 @@ function unpackVariable(variable::VariableDFG; skipVersionCheck::Bool = false) !skipVersionCheck && _versionCheck(variable) # Variable and point type - variableType = DFG.getTypeFromSerializationModule(variable.variableType) + variableType = parseVariableType(variable.variableType) isnothing(variableType) && error( "Cannot deserialize variableType '$(variable.variableType)' in variable '$(variable.label)'", ) @@ -249,7 +277,9 @@ VariableDFG(v::VariableCompute) = packVariable(v) # returns FactorDFG function packFactor(f::FactorCompute) - fnctype = getObservation(f) + obstype = typeof(getObservation(f)) + fnctype = string(parentmodule(obstype), ".", nameof(obstype)) + return FactorDFG(; id = f.id, label = f.label, @@ -257,7 +287,9 @@ function packFactor(f::FactorCompute) _variableOrderSymbols = f._variableOrderSymbols, timestamp = f.timestamp, nstime = string(f.nstime.value), - fnctype = String(_getname(fnctype)), + #TODO fully test include module name in factor fnctype, see #1140 + # fnctype = String(_getname(getObservation(f))), + fnctype, solvable = getSolvable(f), metadata = base64encode(JSON3.write(f.smallData)), # Pack the node data @@ -284,8 +316,7 @@ function unpackObservation(factor::FactorDFG) #TODO change to unpack: observ = unpack(observpacked) # currently the observation type is stored in the factor and this complicates unpacking of seperate observations observpacked = getObservation(factor) - packtype = DFG.getTypeFromSerializationModule("Packed" * factor.fnctype) - return convert(convertStructType(packtype), observpacked) + return convert(convertStructType(typeof(observpacked)), observpacked) else rethrow() end diff --git a/test/runtests.jl b/test/runtests.jl index e354e9fd..80a5cc11 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -64,7 +64,7 @@ if get(ENV, "IIF_TEST", "true") == "true" Pkg.add( #FIXME This is a temporary fix to use the refactored factor branch. # PackageSpec(; name = "IncrementalInference", rev = "upstream/dfg_integration_test"), - PackageSpec(; name = "IncrementalInference", rev = "refac/factor"), + PackageSpec(; name = "IncrementalInference", rev = "develop"), ) @info "------------------------------------------------------------------------" @info "These tests are using IncrementalInference to do additional driver tests"