diff --git a/src/DataLayerAPI.jl b/src/DataLayerAPI.jl deleted file mode 100644 index 00ad819ec..000000000 --- a/src/DataLayerAPI.jl +++ /dev/null @@ -1,103 +0,0 @@ -# API definition file for data layer abstraction. -# The idea is for a one line call to change from internal Graphs.jl to CloudGraphs.jl -# switch for as data layer. - -""" -$(TYPEDEF) -""" -mutable struct DataLayerAPI - addvertex!::Function - getvertex::Function - # setupvertgraph!::Function - # setupfncvertgraph!::Function - makeaddedge!::Function - getedge::Function - outneighbors::Function - updatevertex!::Function - updateedge!::Function - deletevertex!::Function - deleteedge!::Function - cgEnabled::Bool -end - -# global dlapi - -dlapi = DataLayerAPI(addGraphsVert!, # addvertex - getVertNode, # getvertex - makeAddEdge!, # makeaddedge - graphsGetEdge, # getedge - graphsOutNeighbors, # outneighbors - updateFullVertData!, # updatevertex! - +, # updateedge! - graphsDeleteVertex!, # deletevertex! - +, # deleteedge! - false ) - -localapi = DataLayerAPI(addGraphsVert!, # addvertex - getVertNode, # getvertex - makeAddEdge!, # makeaddedge - graphsGetEdge, # getedge - graphsOutNeighbors, # outneighbors - updateFullVertData!, # updatevertex! - +, # updateedge! - graphsDeleteVertex!, # deletevertex! - +, # deleteedge! - false ) -# - - -# setCloudDataLayerAPI! -function setdatalayerAPI!(;addvertex::Function = addGraphsVert!, - getvertex::Function = getVertNode, - makeaddedge::Function = makeAddEdge!, - getedge::Function = graphsGetEdge, - outneighbors::Function = graphsOutNeighbors, - updatevertex::Function = updateFullVertData!, - updateedge::Function = +, - deletevertex::Function = graphsDeleteVertex!, - deleteedge::Function = +, - cgEnabled::Bool = false ) - - dlapi.addvertex! = addvertex - dlapi.getvertex = getvertex - dlapi.makeaddedge! = makeaddedge - dlapi.getedge = getedge - dlapi.outneighbors = outneighbors - dlapi.updatevertex! = updatevertex - dlapi.updateedge! = updateedge - dlapi.deletevertex! = deletevertex - dlapi.deleteedge! = deleteedge - dlapi.cgEnabled = cgEnabled - - # dlapi.addvertex! = addCloudVert! - # dlapi.getvertex = getExVertFromCloud - # dlapi.makeaddedge! = makeAddCloudEdge! - # dlapi.getedge = getEdgeFromCloud - # dlapi.updatevertex! = updateFullCloudVertData! - # dlapi.outneighbors = getCloudOutNeighbors - # dlapi.deletevertex! = deleteCloudVertex! - # dlapi.deleteedge! = deleteCloudEdge! - # dlapi.cgEnabled = true - - println("Changed internal `dlapi` for specific API calls.") - nothing -end - - -function showcurrentdlapi() - @show dlapi -end - - - - - -# Remember 3rd party users interact with -# addNode! -# addFactor! -# prepBatchTree! -# inferOverTree! -# -## Visualization functions -- Visualization may well be separated or abstracted out -# writeGraphPdf -# drawHorBeliefsList diff --git a/src/Deprecated.jl b/src/Deprecated.jl index 7378aeb7b..3ae3eeaa0 100644 --- a/src/Deprecated.jl +++ b/src/Deprecated.jl @@ -91,7 +91,6 @@ function addNode!(fg::FactorGraph, ready::Int=1, dontmargin::Bool=false, labels::Vector{<:AbstractString}=String[], - api::DataLayerAPI=dlapi, uid::Int=-1, smalldata="" ) where {T <:InferenceVariable} # @@ -104,7 +103,6 @@ function addNode!(fg::FactorGraph, ready=ready, dontmargin=dontmargin, labels=labels, - api=api, uid=uid, smalldata=smalldata ) end @@ -116,7 +114,6 @@ function addNode!(fg::FactorGraph, ready::Int=1, dontmargin::Bool=false, labels::Vector{<:AbstractString}=String[], - api::DataLayerAPI=dlapi, uid::Int=-1, # dims::Int=-1, smalldata="" ) @@ -130,7 +127,6 @@ function addNode!(fg::FactorGraph, ready=ready, dontmargin=dontmargin, labels=labels, - api=api, uid=uid, smalldata=smalldata ) end @@ -140,7 +136,7 @@ end Return all elements `ls(fg)` as tuples, or nodes connected to the a specific element, eg. `ls(fg, :x1) """ -function ls(fgl::FactorGraph, lbl::Symbol; api::DataLayerAPI=dlapi, ring::Int=1) +function ls(fgl::FactorGraph, lbl::Symbol; ring::Int=1) @warn "Deprecated, please use DFG.ls" # TODO ring functionality must still be implemented lsa = Symbol[] @@ -168,7 +164,6 @@ Experimental union of elements version of ls(::FactorGraph, ::Symbol). Not mean """ function ls(fgl::FactorGraph, lbls::Vector{Symbol}; - api::DataLayerAPI=dlapi, ring::Int=1) @warn "Deprecated, please use DFG.ls" union(ls.(fgl, lbls, ring=ring, api=api)[:]...) @@ -251,7 +246,7 @@ List factors in a factor graph. lsf(fg, :x1) ``` """ -function lsf(fgl::FactorGraph, lbl::Symbol; api::DataLayerAPI=dlapi) +function lsf(fgl::FactorGraph, lbl::Symbol) @warn "Deprecated, please use DFG.lsf" lsa = Symbol[] if haskey(fgl.fIDs, lbl) @@ -280,8 +275,7 @@ lsf(fg) lsf(fgl::FactorGraph, lbl::T) where {T <: AbstractString} = lsf(fgl,Symbol(lbl)) function lsf(fgl::FactorGraph, - mt::Type{T}; - api::DataLayerAPI=dlapi ) where {T <: FunctorInferenceType} + mt::Type{T}) where {T <: FunctorInferenceType} @warn "Deprecated, please use DFG.lsf" syms = Symbol[] for (fsym,fid) in fgl.fIDs diff --git a/src/DispatchPackedConversions.jl b/src/DispatchPackedConversions.jl index 8831ab46a..7425cefc8 100644 --- a/src/DispatchPackedConversions.jl +++ b/src/DispatchPackedConversions.jl @@ -82,36 +82,36 @@ function convert(::Type{T}, ::PT) where {T <: FunctorInferenceType, PT <: Packed getfield(PT.name.module, Symbol(string(PT.name.name)[7:end])) end -function getmodule(t::T) where T - T.name.module -end -function getname(t::T) where T - T.name.name -end -function getpackedtype(typestring::AS) where {AS <: AbstractString} - # println("Caesar.getpackedtype($(typestring))") - eval(Meta.parse(typestring))() # TODO consider caching or better -end -function encodePackedType(topackdata::VariableNodeData) - @warn "'encodePackedType' Deprecated..." - # error("IncrementalInference.encodePackedType(::VariableNodeData): Unknown packed type encoding of $(topackdata)") - pack(nothing, topackdata) -end -function encodePackedType(topackdata::GenericFunctionNodeData{CommonConvWrapper{T}, Symbol}) where {T <: FunctorInferenceType} - # println("IncrementalInference.encodePackedType(::GenericFunctionNodeData{T,Symbol}): Unknown packed type encoding T=$(T) of $(topackdata)") - fnctype = getfnctype(topackdata) - fnc = getfield(getmodule(fnctype), Symbol("Packed$(getname(fnctype))")) - convert(PackedFunctionNodeData{fnc}, topackdata) -end -function encodePackedType(topackdata::GenericFunctionNodeData{T, <:AbstractString}) where {T <: PackedInferenceType} - error("IncrementalInference.encodePackedType(::FunctionNodeData{T, <:AbstractString}): Unknown packed type encoding T=$(T) of $(topackdata)") - # @show T, typeof(topackdata) - # @warn "Yes, its packed!" - # fnctype = getfnctype(topackdata) - # @show fnc = getfield(getmodule(fnctype), Symbol("Packed$(getname(fnctype))")) - # convert(PackedFunctionNodeData{T}, topackdata) - topackdata -end +# function getmodule(t::T) where T +# T.name.module +# end +# function getname(t::T) where T +# T.name.name +# end +# function getpackedtype(typestring::AS) where {AS <: AbstractString} +# # println("Caesar.getpackedtype($(typestring))") +# eval(Meta.parse(typestring))() # TODO consider caching or better +# end +# function encodePackedType(topackdata::VariableNodeData) +# @warn "'encodePackedType' Deprecated..." +# # error("IncrementalInference.encodePackedType(::VariableNodeData): Unknown packed type encoding of $(topackdata)") +# pack(nothing, topackdata) +# end +# function encodePackedType(topackdata::GenericFunctionNodeData{CommonConvWrapper{T}, Symbol}) where {T <: FunctorInferenceType} +# # println("IncrementalInference.encodePackedType(::GenericFunctionNodeData{T,Symbol}): Unknown packed type encoding T=$(T) of $(topackdata)") +# fnctype = getfnctype(topackdata) +# fnc = getfield(getmodule(fnctype), Symbol("Packed$(getname(fnctype))")) +# convert(PackedFunctionNodeData{fnc}, topackdata) +# end +# function encodePackedType(topackdata::GenericFunctionNodeData{T, <:AbstractString}) where {T <: PackedInferenceType} +# error("IncrementalInference.encodePackedType(::FunctionNodeData{T, <:AbstractString}): Unknown packed type encoding T=$(T) of $(topackdata)") +# # @show T, typeof(topackdata) +# # @warn "Yes, its packed!" +# # fnctype = getfnctype(topackdata) +# # @show fnc = getfield(getmodule(fnctype), Symbol("Packed$(getname(fnctype))")) +# # convert(PackedFunctionNodeData{T}, topackdata) +# topackdata +# end """ $(SIGNATURES) @@ -131,19 +131,53 @@ end # Variables -function decodePackedType(packeddata::PackedVariableNodeData, - typestring::String ) -#TODO: typestring is unnecessary + +function decodePackedType(dfg::G, packeddata::PackedVariableNodeData) where G <: AbstractDFG + @warn "Deprecated?" convert(IncrementalInference.VariableNodeData, packeddata) end # Factors -#TODO: typestring is unnecessary -function decodePackedType(packeddata::GenericFunctionNodeData{PT,<:AbstractString}, notused::String) where {PT} +function decodePackedType(dfg::G, packeddata::GenericFunctionNodeData{PT,<:AbstractString}) where {PT, G <: AbstractDFG} usrtyp = convert(FunctorInferenceType, packeddata.fnc) fulltype = FunctionNodeData{CommonConvWrapper{usrtyp}} - return convert(fulltype, packeddata) + factor = convert(fulltype, packeddata) + return factor end +""" + $(SIGNATURES) +After deserializing a factor using decodePackedType, use this to +completely rebuild the factor's CCW and user data. +""" +function rebuildFactorMetadata!(dfg::G, factor::DFGFactor)::DFGFactor where G <: AbstractDFG + # Set up the neighbor data + neighbors = map(vId->getVariable(dfg, vId), getNeighbors(dfg, factor)) + neighborUserData = map(v->getData(v).softtype, neighbors) + + # Rebuilding the CCW + setDefaultFactorNode!(dfg, factor, neighbors, factor.data.fnc.usrfnc!) + + #... Copying neighbor data into the factor? + ccw_new = getData(factor) + for i in 1:Threads.nthreads() + ccw_new.fnc.cpt[i].factormetadata.variableuserdata = deepcopy(neighborUserData) + end + + # Copying all other fields in the factor + # TODO: Confirm whether we still need to do this? + ## Rebuild getData(fcnode).fncargvID, however, the list is order sensitive + # out_neighbors does not gaurantee ordering -- i.e. why is it not being saved + # for field in fieldnames(typeof(ccw_jld)) + # if field != :fnc + # setfield!(ccw_new, field, getfield(ccw_jld, field)) + # end + # end + + return factor +end + + + """ $(SIGNATURES) @@ -203,7 +237,7 @@ veeCategorical(val::Union{Nothing, Vector{Float64}}) = val Unpack PackedFunctionNodeData formats back to regular FunctonNodeData. """ -function decodefg(fgs::FactorGraph; api::DataLayerAPI=localapi) +function decodefg(fgs::FactorGraph) fgu = deepcopy(fgs) fgu.cg = nothing # will be deprecated or replaced fgu.registeredModuleFunctions = nothing # TODO: obsolete diff --git a/src/FGOSUtils.jl b/src/FGOSUtils.jl index 2a4fdeecc..34a6fd6d5 100644 --- a/src/FGOSUtils.jl +++ b/src/FGOSUtils.jl @@ -112,6 +112,7 @@ function compareAll(Al::T, return TP end +# TODO: KEEP function compareAll(Al::T1, Bl::T2; show::Bool=true, skip::Vector{Symbol}=Symbol[])::Bool where {T1 <: Union{SingleThreaded, MultiThreaded}, T2 <: Union{SingleThreaded, MultiThreaded}} return T1 == T2 end @@ -152,6 +153,7 @@ end # return true # end +# TODO: KEEP function compare(p1::BallTreeDensity, p2::BallTreeDensity)::Bool return compareAll(p1.bt,p2.bt, skip=[:calcStatsHandle; :data]) && compareAll(p1,p2, skip=[:calcStatsHandle; :bt]) @@ -198,6 +200,7 @@ function compareAllSpecial(A::T1, end end +# TODO: KEEP function compareAllSpecial(A::T1, B::T2; skip=Symbol[], show::Bool=true) where {T1 <: CommonConvWrapper, T2 <: CommonConvWrapper} # @@ -327,7 +330,7 @@ Related: `compareFactorGraphs`, `compareSimilarVariables`, `compareSimilarFactors`, `ls`. """ -function compareSubsetFactorGraph(fgS::FactorGraph, fgA::FactorGraph; api::DataLayerAPI=localapi) +function compareSubsetFactorGraph(fgS::FactorGraph, fgA::FactorGraph) error("not implemented yet") return false end @@ -629,7 +632,7 @@ end Return `::Bool` on whether this variable has been marginalized. """ isMarginalized(vert::DFGVariable) = getData(vert).ismargin -isMarginalized(dfg::G, sym::Symbol; api::DataLayerAPI=localapi) where G <: AbstractDFG = isMarginalized(DFG.getVariable(fg, sym)) +isMarginalized(dfg::G, sym::Symbol) where G <: AbstractDFG = isMarginalized(DFG.getVariable(fg, sym)) diff --git a/src/FactorGraph01.jl b/src/FactorGraph01.jl index 7f83d3f65..5364e072b 100644 --- a/src/FactorGraph01.jl +++ b/src/FactorGraph01.jl @@ -864,12 +864,11 @@ end function addBayesNetVerts!(dfg::G, elimOrder::Array{Symbol,1}) where G <: AbstractDFG for pId in elimOrder vert = DFG.getVariable(dfg, pId) - # @show vert.label, getData(vert).BayesNetVertID - if getData(vert).BayesNetVertID == nothing - # fg.bnid+=1 + if getData(vert).BayesNetVertID == nothing || getData(vert).BayesNetVertID == :_null # Special serialization case of nothing + @debug "[AddBayesNetVerts] Assigning $pId.data.BayesNetVertID = $pId" getData(vert).BayesNetVertID = pId else - @warn "addBayesNetVerts -- something is very wrong, should not have a Bayes net vertex" + @warn "addBayesNetVerts -- Something is wrong, variable '$pId' should not have an existing Bayes net reference to '$(getData(vert).BayesNetVertID)'" end end end diff --git a/src/FactorGraphTypes.jl b/src/FactorGraphTypes.jl index bcd878ecc..97acae8f4 100644 --- a/src/FactorGraphTypes.jl +++ b/src/FactorGraphTypes.jl @@ -168,6 +168,9 @@ mutable struct FactorMetadata FactorMetadata(x1, x2::Union{Vector,Tuple},x3,x4::Symbol,x5::Vector{Symbol};dbg::Bool=false) = new(x1, x2, x3, x4, x5, dbg) end +""" +$(TYPEDEF) +""" struct SingleThreaded end """ @@ -323,6 +326,7 @@ function addGraphsVert!(fgl::FactorGraph, exvert::Graphs.ExVertex; labels::Vector{<:AbstractString}=String[]) # + @warn "Deprecated" Graphs.add_vertex!(fgl.g, exvert) end @@ -349,7 +353,7 @@ getVertNode(fgl::G, lbl::T; nt::Symbol=:var, bigData::Bool=false) where {G <: Ab function updateFullVertData!(fgl::G, nv::N; # nv::Graphs.ExVertex; updateMAPest::Bool=false ) where {G <: AbstractDFG, N <: DFGNode} - # + @warn "Deprecated" sym = Symbol(nv.label) isvar = isVariable(fgl, sym) @@ -371,6 +375,7 @@ end function makeAddEdge!(fgl::FactorGraph, v1::Graphs.ExVertex, v2::Graphs.ExVertex; saveedgeID::Bool=true) + @warn "Deprecated" edge = Graphs.make_edge(fgl.g, v1, v2) Graphs.add_edge!(fgl.g, edge) if saveedgeID push!(getData(v2).edgeIDs,edge.index) end #.attributes["data"] @@ -378,13 +383,16 @@ function makeAddEdge!(fgl::FactorGraph, v1::Graphs.ExVertex, v2::Graphs.ExVertex end function graphsOutNeighbors(fgl::FactorGraph, vert::Graphs.ExVertex; ready::Int=1,backendset::Int=1, needdata::Bool=false) + @warn "Deprecated" Graphs.out_neighbors(vert, fgl.g) end function graphsOutNeighbors(fgl::FactorGraph, exVertId::Int; ready::Int=1,backendset::Int=1, needdata::Bool=false) + @warn "Deprecated" graphsOutNeighbors(fgl.g, getVert(fgl,exVertId), ready=ready, backendset=backendset, needdata=needdata) end function graphsGetEdge(fgl::FactorGraph, id::Int) + @warn "Deprecated" nothing end diff --git a/src/IncrementalInference.jl b/src/IncrementalInference.jl index eeff3bf4c..fa79b4a2a 100644 --- a/src/IncrementalInference.jl +++ b/src/IncrementalInference.jl @@ -63,7 +63,7 @@ export getTreeCliqsSolverHistories, assignTreeHistory!, - # OBSOLETE TODO REMOVE + # OBSOLETE TODO REMOVE #TODO TODO dlapi, localapi, showcurrentdlapi, @@ -457,7 +457,6 @@ include("FactorGraphTypes.jl") include("BeliefTypes.jl") include("AliasScalarSampling.jl") include("DefaultNodeTypes.jl") -include("DataLayerAPI.jl") include("FactorGraph01.jl") include("SubGraphFunctions.jl") include("SerializingDistributions.jl")