Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ using StaticArrays

import Base: getindex

using InteractiveUtils: subtypes

##==============================================================================
# Exports
##==============================================================================
Expand Down
3 changes: 2 additions & 1 deletion src/services/AbstractDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
factor::AbstractDFGFactor,
neighbors = [],
)
return error("rebuildFactorCache! is not implemented for $(typeof(dfg))")
@warn("rebuildFactorCache! is not implemented for $(typeof(dfg))")
return nothing

Check warning on line 125 in src/services/AbstractDFG.jl

View check run for this annotation

Codecov / codecov/patch

src/services/AbstractDFG.jl#L124-L125

Added lines #L124 - L125 were not covered by tests
end

"""
Expand Down
10 changes: 9 additions & 1 deletion src/services/DFGFactor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@
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

Check warning on line 56 in src/services/DFGFactor.jl

View check run for this annotation

Codecov / codecov/patch

src/services/DFGFactor.jl#L56

Added line #L56 was not covered by tests
end

packtype = DFG.getTypeFromSerializationModule("Packed" * fnctype)
return packtype(; JSON3.read(f.observJSON)...)
# return packtype(JSON3.read(f.observJSON))
end
Expand Down
43 changes: 37 additions & 6 deletions src/services/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@

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

Check warning on line 59 in src/services/Serialization.jl

View check run for this annotation

Codecov / codecov/patch

src/services/Serialization.jl#L58-L59

Added lines #L58 - L59 were not covered by tests
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.
Expand Down Expand Up @@ -123,7 +151,7 @@
# 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().",
)
Expand Down Expand Up @@ -206,7 +234,7 @@
!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)'",
)
Expand Down Expand Up @@ -249,15 +277,19 @@

# 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,
tags = f.tags,
_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
Expand All @@ -284,8 +316,7 @@
#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
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading