Skip to content

Commit 4c5d3a8

Browse files
committed
Consolidate FactorDFG with FactorCompute, and rebuild serialization.
1 parent efd40d0 commit 4c5d3a8

27 files changed

+586
-860
lines changed

docs/extra/CoreAPI.fods

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@
16401640
<text:p>x</text:p>
16411641
</table:table-cell>
16421642
<table:table-cell table:style-name="ce51" office:value-type="string" calcext:value-type="string">
1643-
<text:p>_variableOrderSymbols</text:p>
1643+
<text:p>variableorder</text:p>
16441644
</table:table-cell>
16451645
<table:table-cell/>
16461646
<table:table-cell table:style-name="ce101"/>

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ StructUtils.@kwarg struct Blobentry
4949
version::VersionNumber = version(Blobentry)
5050
end
5151
version(::Type{Blobentry}) = v"0.1.0"
52-
version(node) = node.version
5352

5453
function Blobentry(label::Symbol, blobstore = :default; kwargs...)
5554
return Blobentry(; label, blobstore, kwargs...)
@@ -122,3 +121,5 @@ function Base.setproperty!(x::Blobentry, f::Symbol, val)
122121
setfield!(x, f, val)
123122
end
124123
end
124+
125+
const Blobentries = OrderedDict{Symbol, Blobentry}

src/Deprecated.jl

Lines changed: 144 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,148 @@
11
## ================================================================================
22
## Deprecated in v0.29
33
##=================================================================================
4+
export FactorCompute
5+
const FactorCompute = FactorDFG
6+
47
function getHash(entry::Blobentry)
58
return error(
69
"Blobentry field :hash has been deprecated; use :crchash or :shahash instead",
710
)
811
end
12+
13+
function getMetadata(node)
14+
error(
15+
"getMetadata(node::$(typeof(node))) is deprecated; metadata is now stored in bloblets. Use getBloblets instead.",
16+
)
17+
# return JSON.parse(base64decode(f.metadata), Dict{Symbol, MetadataTypes})
18+
end
19+
20+
# getTimestamp
21+
22+
# setTimestamp is deprecated for now we can implement setTimestamp!(dfg, lbl, ts) later.
23+
setTimestamp(args...; kwargs...) = error("setTimestamp is obsolete, use addVariable!(..., timestamp=...) instead.")
24+
setTimestamp!(args...; kwargs...) = error("setTimestamp! is not implemented, use addVariable!(..., timestamp=...) instead.")
25+
26+
##------------------------------------------------------------------------------
27+
## solveInProgress
28+
##------------------------------------------------------------------------------
29+
30+
# getSolveInProgress and isSolveInProgress is deprecated for DFG v1.0, we can bring it back fully implemented when needed.
31+
# """
32+
# $SIGNATURES
33+
34+
# Which variables or factors are currently being used by an active solver. Useful for ensuring atomic transactions.
35+
36+
# DevNotes:
37+
# - Will be renamed to `data.solveinprogress` which will be in VND, not AbstractGraphNode -- see DFG #201
38+
39+
# Related
40+
41+
# isSolvable
42+
# """
43+
function getSolveInProgress(
44+
var::Union{VariableCompute, FactorCompute},
45+
solveKey::Symbol = :default,
46+
)
47+
# Variable
48+
if var isa VariableCompute
49+
if haskey(getSolverDataDict(var), solveKey)
50+
return getSolverDataDict(var)[solveKey].solveInProgress
51+
else
52+
return 0
53+
end
54+
end
55+
# Factor
56+
return getFactorState(var).solveInProgress
57+
end
58+
59+
#TODO missing set solveInProgress and graph level accessor
60+
61+
function isSolveInProgress(
62+
node::Union{VariableCompute, FactorCompute},
63+
solvekey::Symbol = :default,
64+
)
65+
return getSolveInProgress(node, solvekey) > 0
66+
end
67+
68+
"""
69+
$(SIGNATURES)
70+
Get a type from the serialization module.
71+
"""
72+
function getTypeFromSerializationModule(_typeString::AbstractString)
73+
@debug "DFG converting type string to Julia type" _typeString
74+
try
75+
# split the type at last `.`
76+
split_st = split(_typeString, r"\.(?!.*\.)")
77+
#if module is specified look for the module in main, otherwise use Main
78+
if length(split_st) == 2
79+
m = getfield(Main, Symbol(split_st[1]))
80+
else
81+
m = Main
82+
end
83+
noparams = split(split_st[end], r"{")
84+
ret = if 1 < length(noparams)
85+
# fix #671, but does not work with specific module yet
86+
bidx = findfirst(r"{", split_st[end])[1]
87+
error("getTypeFromSerializationModule eval obsolete")
88+
# Core.eval(m, Base.Meta.parse("$(noparams[1])$(split_st[end][bidx:end])"))
89+
else
90+
getfield(m, Symbol(split_st[end]))
91+
end
92+
93+
return ret
94+
95+
catch ex
96+
@error "Unable to deserialize type $(_typeString)"
97+
io = IOBuffer()
98+
showerror(io, ex, catch_backtrace())
99+
err = String(take!(io))
100+
@error(err)
101+
end
102+
return nothing
103+
end
104+
105+
## Version checking
106+
#NOTE fixed really bad function but kept similar as fallback #TODO upgrade to use pkgversion(m::Module)
107+
function _getDFGVersion()
108+
return pkgversion(DistributedFactorGraphs)
109+
end
110+
111+
function _versionCheck(node::Union{<:VariableDFG, <:FactorDFG})
112+
if node._version.minor < _getDFGVersion().minor
113+
@warn "This data was serialized using DFG $(node._version) but you have $(_getDFGVersion()) installed, there may be deserialization issues." maxlog =
114+
10
115+
end
116+
end
117+
118+
refMetadata(node) = node.metadata
119+
120+
function packDistribution end
121+
function unpackDistribution end
122+
123+
getAgentMetadata(args...) = error("getAgentMetadata is obsolete, use Bloblets instead.")
124+
setAgentMetadata!(args...) = error("setAgentMetadata! is obsolete, use Bloblets instead.")
125+
getGraphMetadata(args...) = error("getGraphMetadata is obsolete, use Bloblets instead.")
126+
setGraphMetadata!(args...) = error("setGraphMetadata! is obsolete, use Bloblets instead.")
127+
128+
setDescription!(args...) = error("setDescription! was removed and may be implemented later.")
129+
130+
# TODO find replacement.
131+
function _getDuplicatedEmptyDFG(
132+
dfg::GraphsDFG{P, V, F},
133+
) where {P <: AbstractDFGParams, V <: AbstractGraphVariable, F <: AbstractGraphFactor}
134+
Base.depwarn(
135+
"_getDuplicatedEmptyDFG is deprecated.",
136+
:_getDuplicatedEmptyDFG,
137+
)
138+
newDfg = GraphsDFG{P, V, F}(;
139+
agentLabel = getAgentLabel(dfg),
140+
graphLabel = getGraphLabel(dfg),
141+
solverParams = deepcopy(dfg.solverParams),
142+
)
143+
# DFG.setDescription!(newDfg, "(Copy of) $(DFG.getDescription(dfg))")
144+
return newDfg
145+
end
9146
## ================================================================================
10147
## Deprecated in v0.28
11148
##=================================================================================
@@ -124,18 +261,19 @@ function cloneSolveKey!(dfg::AbstractDFG, dest::Symbol, src::Symbol; kw...)
124261
return cloneSolveKey!(dfg, dest, dfg, src; kw...)
125262
end
126263

127-
#TODO not a good function, as it's not complete.
264+
#TODO make a replacement if used a lot... not a good function, as it's not complete.
128265
# """
129266
# $(SIGNATURES)
130267
# Convenience function to get all the metadata of a DFG
131268
# """
132269
function getDFGInfo(dfg::AbstractDFG)
270+
Base.depwarn("getDFGInfo is deprecated and needs a replacement.", :getDFGInfo)
133271
return (
134-
description = getDescription(dfg),
272+
graphDescription = getDescription(dfg),
135273
agentLabel = getAgentLabel(dfg),
136274
graphLabel = getGraphLabel(dfg),
137-
agentMetadata = getAgentMetadata(dfg),
138-
graphMetadata = getGraphMetadata(dfg),
275+
# agentBloblets = getAgentBloblets(dfg),
276+
# graphBloblets = getGraphBloblets(dfg),
139277
solverParams = getSolverParams(dfg),
140278
)
141279
end
@@ -350,16 +488,7 @@ end
350488
@deprecate getFactorFunction(args...) getObservation(args...)
351489
@deprecate getFactorType(args...) getObservation(args...)
352490

353-
#TODO maybe deprecate setMetadata!
354-
function setMetadata!(v::VariableDFG, metadata::Dict{Symbol, MetadataTypes})
355-
return error("FIXME: Metadata is not currently mutable in a Variable")
356-
# v.metadata = base64encode(JSON3.write(metadata))
357-
end
358-
359-
function setMetadata!(v::VariableCompute, metadata::Dict{Symbol, MetadataTypes})
360-
v.smallData !== metadata && empty!(v.smallData)
361-
return merge!(v.smallData, metadata)
362-
end
491+
setMetadata!(args...) = error("setMetadata is obsolete, use Bloblets instead.")
363492

364493
function updateData!(
365494
dfg::AbstractDFG,
@@ -999,7 +1128,7 @@ end
9991128

10001129
# # Deprecated check usefull? # packedFnc = fncStringToData(factor.fnctype, factor.data)
10011130
# # Deprecated check usefull? # decodeType = getFactorOperationalMemoryType(dfg)
1002-
# # Deprecated check usefull? # fullFactorData = decodePackedType(dfg, factor._variableOrderSymbols, decodeType, packedFnc)
1131+
# # Deprecated check usefull? # fullFactorData = decodePackedType(dfg, factor.variableorder, decodeType, packedFnc)
10031132
# function fncStringToData(args...; kwargs...)
10041133
# @warn "fncStringToData is obsolete, called with" args kwargs
10051134
# return error("fncStringToData is obsolete.")

src/DistributedFactorGraphs.jl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ using Random
2222
using TimeZones
2323
using NanoDates
2424
using JSON
25+
export StructUtils # export for use in macros
2526
using LinearAlgebra
2627
using SparseArrays
2728
using UUIDs
@@ -31,7 +32,7 @@ using ProgressMeter
3132
using SHA
3233
using FileIO
3334

34-
import Distributions
35+
import Distributions #TODO this was unused before (if we move SerializingDistributions.jl out we can maybe remove the Distributions dependency?)
3536
import Tar
3637
import CodecZlib
3738

@@ -78,7 +79,7 @@ export AbstractPackedBelief, PackedBelief
7879
# Variables
7980
export VariableCompute, VariableDFG, VariableSummary, VariableSkeleton
8081
# Factors
81-
export FactorCompute, FactorDFG, FactorSummary, FactorSkeleton
82+
export FactorDFG, FactorSummary, FactorSkeleton
8283

8384
export Blobentry
8485

@@ -421,11 +422,13 @@ const unstable_functions::Vector{Symbol} = [
421422
:setSolverParams!,
422423
:setDescription!,
423424
:setSolvable!,
424-
:setTimestamp,
425425
:setTags!,
426426
:setSolvedCount!,
427427
:setMarginalized!,
428428
# no set on these
429+
430+
#deprecated in v0.29
431+
:setTimestamp,
429432
:setMetadata!, # no set, use add merge
430433
:setAgentMetadata!,
431434
:setGraphMetadata!,
@@ -527,6 +530,9 @@ include("entities/Bloblet.jl")
527530
include("DataBlobs/entities/BlobEntry.jl")
528531
include("DataBlobs/entities/BlobStores.jl")
529532

533+
include("serialization/PackedSerialization.jl")
534+
include("serialization/DistributionSerialization.jl")
535+
530536
include("entities/DFGFactor.jl")
531537

532538
include("entities/DFGVariable.jl")

src/FileDFG/services/FileDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function loadDFG!(
144144
end
145145

146146
# extract the factor graph from fileDFG folder
147-
factors = FactorCompute[]
147+
factors = FactorDFG[]
148148
varFolder = "$folder/variables"
149149
factorFolder = "$folder/factors"
150150
# Folder preparations

src/GraphsDFG/GraphsDFG.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ using ...DistributedFactorGraphs:
2121
getAgentLabel,
2222
getGraphLabel,
2323
isInitialized,
24-
MetadataTypes
24+
MetadataTypes,
25+
Bloblets,
26+
Blobentries
2527

2628
# import DFG functions to extend
2729
import ...DistributedFactorGraphs:

0 commit comments

Comments
 (0)