Skip to content

Commit f3b0dc0

Browse files
authored
Merge pull request #437 from JuliaRobotics/maint/20Q2/rem_dep_v08
Remove deprecated for v0.8.0
2 parents bfadef9 + ee07424 commit f3b0dc0

12 files changed

+99
-348
lines changed

src/Deprecated.jl

Lines changed: 22 additions & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,18 @@
44

55

66
##==============================================================================
7-
## Remove in 0.8
7+
## Remove in 0.9
88
##==============================================================================
99

10-
#TODO alias or deprecate
11-
@deprecate getVariableIds(dfg::AbstractDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0) listVariables(dfg, regexFilter, tags=tags, solvable=solvable)
12-
13-
@deprecate getFactorIds(dfg, regexFilter=nothing; solvable=0) listFactors(dfg, regexFilter, solvable=solvable)
14-
15-
@deprecate listPPE(args...) listPPEs(args...)
16-
17-
export getLabelDict
18-
getLabelDict(dfg::AbstractDFG) = error("getLabelDict is deprecated, consider using listing functions")
19-
20-
export getAdjacencyMatrix
21-
"""
22-
$(SIGNATURES)
23-
Get a matrix indicating relationships between variables and factors. Rows are
24-
all factors, columns are all variables, and each cell contains either nothing or
25-
the symbol of the relating factor. The first row and first column are factor and
26-
variable headings respectively.
27-
"""
28-
function getAdjacencyMatrix(dfg::AbstractDFG; solvable::Int=0)::Matrix{Union{Nothing, Symbol}}
29-
error("Deprecated function, please use getBiadjacencyMatrix")
30-
end
31-
32-
@deprecate getAdjacencyMatrixSparse(dfg::AbstractDFG; solvable::Int=0) getBiadjacencyMatrix(dfg, solvable=solvable)
33-
3410

3511
Base.getproperty(x::DFGFactor,f::Symbol) = begin
36-
if f == :solvable
37-
getfield(x,:_dfgNodeParams).solvable
38-
elseif f == :_internalId
39-
getfield(x,:_dfgNodeParams)._internalId
40-
elseif f == :data
41-
Base.depwarn("DFGFactor get: data field is deprecated, use getSolverData", :getproperty)
42-
getfield(x, :solverData)
43-
else
44-
getfield(x,f)
45-
end
12+
if f == :solvable
13+
getfield(x,:_dfgNodeParams).solvable
14+
elseif f == :_internalId
15+
getfield(x,:_dfgNodeParams)._internalId
16+
else
17+
getfield(x,f)
18+
end
4619
end
4720

4821
Base.setproperty!(x::DFGFactor,f::Symbol, val) = begin
@@ -51,237 +24,27 @@ Base.setproperty!(x::DFGFactor,f::Symbol, val) = begin
5124
getfield(x,:_dfgNodeParams).solvable = val
5225
elseif f == :_internalId
5326
getfield(x,:_dfgNodeParams)._internalId = val
54-
elseif f == :data
55-
Base.depwarn("DFGFactor set: data field is deprecated, use getSolverData", :getproperty)
56-
setfield!(x,:solverData, val)
5727
else
5828
setfield!(x,f,val)
5929
end
60-
end
61-
62-
Base.getproperty(x::DFGVariable,f::Symbol) = begin
63-
# if f == :estimateDict
64-
# @warn "estimateDict is deprecated, use ppeDict instead"
65-
# getfield(x, :ppeDict)
66-
if f == :solvable
67-
getfield(x,:_dfgNodeParams).solvable
68-
elseif f == :_internalId
69-
getfield(x,:_dfgNodeParams)._internalId
70-
else
71-
getfield(x,f)
72-
end
73-
end
74-
75-
Base.setproperty!(x::DFGVariable,f::Symbol, val) = begin
76-
# if f == :estimateDict
77-
# error("estimateDict is deprecated, use ppeDict instead")
78-
if f == :solvable
79-
getfield(x,:_dfgNodeParams).solvable = val
80-
elseif f == :_internalId
81-
getfield(x,:_dfgNodeParams)._internalId = val
82-
else
83-
setfield!(x,f,val)
84-
end
85-
end
86-
87-
88-
#NOTE deprecate in favor of constructors because its not lossless: https://docs.julialang.org/en/v1/manual/conversion-and-promotion/#Conversion-vs.-Construction-1
89-
function Base.convert(::Type{DFGVariableSummary}, v::DFGVariable)
90-
Base.depwarn("convert to type DFGVariableSummary is deprecated use the constructor", :convert)
91-
return DFGVariableSummary(v)
92-
end
93-
94-
function Base.convert(::Type{SkeletonDFGVariable}, v::VariableDataLevel1)
95-
Base.depwarn("convert to type SkeletonDFGVariable is deprecated use the constructor", :convert)
96-
return SkeletonDFGVariable(v)
9730
end
9831

99-
function Base.convert(::Type{DFGFactorSummary}, f::DFGFactor)
100-
Base.depwarn("convert to type DFGFactorSummary is deprecated use the constructor", :convert)
101-
return DFGFactorSummary(f)
102-
end
103-
104-
function Base.convert(::Type{SkeletonDFGFactor}, f::FactorDataLevel1)
105-
Base.depwarn("convert to type SkeletonDFGFactor is deprecated use the constructor", :convert)
106-
return SkeletonDFGFactor(f)
107-
end
108-
109-
110-
@deprecate hasOrphans(dfg) !isConnected(dfg)
111-
@deprecate isFullyConnected(dfg) isConnected(dfg)
112-
113-
##==============================================================================
114-
## WIP on consolidated subgraph functions, aim to remove in 0.8
115-
##==============================================================================
116-
# Deprecate in favor of buildSubgraph, mergeGraph
117-
export getSubgraph, getSubgraphAroundNode
118-
export buildSubgraphFromLabels!
119-
120-
"""
121-
$(SIGNATURES)
122-
Common function for copying nodes from one graph into another graph.
123-
This is overridden in specialized implementations for performance.
124-
NOTE: copyGraphMetadata not supported yet.
125-
"""
126-
function _copyIntoGraph!(sourceDFG::G, destDFG::H, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false; copyGraphMetadata::Bool=false)::Nothing where {G <: AbstractDFG, H <: AbstractDFG}
127-
# Split into variables and factors
128-
Base.depwarn("_copyIntoGraph! is deprecated use copyGraph/deepcopyGraph[!]", :_copyIntoGraph!)
129-
130-
includeOrphanFactors && (@error "Adding orphaned factors is not supported")
131-
132-
sourceVariables = map(vId->getVariable(sourceDFG, vId), intersect(listVariables(sourceDFG), variableFactorLabels))
133-
sourceFactors = map(fId->getFactor(sourceDFG, fId), intersect(listFactors(sourceDFG), variableFactorLabels))
134-
if length(sourceVariables) + length(sourceFactors) != length(variableFactorLabels)
135-
rem = symdiff(map(v->v.label, sourceVariables), variableFactorLabels)
136-
rem = symdiff(map(f->f.label, sourceFactors), variableFactorLabels)
137-
error("Cannot copy because cannot find the following nodes in the source graph: $rem")
138-
end
139-
140-
# Now we have to add all variables first,
141-
for variable in sourceVariables
142-
if !exists(destDFG, variable)
143-
addVariable!(destDFG, deepcopy(variable))
144-
end
145-
end
146-
# And then all factors to the destDFG.
147-
for factor in sourceFactors
148-
# Get the original factor variables (we need them to create it)
149-
sourceFactorVariableIds = getNeighbors(sourceDFG, factor)
150-
# Find the labels and associated variables in our new subgraph
151-
factVariableIds = Symbol[]
152-
for variable in sourceFactorVariableIds
153-
if exists(destDFG, variable)
154-
push!(factVariableIds, variable)
155-
end
156-
end
157-
# Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
158-
if includeOrphanFactors || length(factVariableIds) == length(sourceFactorVariableIds)
159-
if !exists(destDFG, factor)
160-
addFactor!(destDFG, deepcopy(factor))
161-
end
162-
end
163-
end
164-
165-
if copyGraphMetadata
166-
setUserData(destDFG, getUserData(sourceDFG))
167-
setRobotData(destDFG, getRobotData(sourceDFG))
168-
setSessionData(destDFG, getSessionData(sourceDFG))
169-
end
170-
return nothing
171-
end
172-
173-
"""
174-
$(SIGNATURES)
175-
Retrieve a deep subgraph copy around a given variable or factor.
176-
Optionally provide a distance to specify the number of edges should be followed.
177-
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
178-
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
179-
Note: Always returns the node at the center, but filters around it if solvable is set.
180-
"""
181-
function getSubgraphAroundNode(dfg::AbstractDFG, node::DFGNode, distance::Int=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg); solvable::Int=0)::AbstractDFG
182-
183-
Base.depwarn("getSubgraphAroundNode is deprecated use buildSubgraph", :getSubgraphAroundNode)
184-
185-
if !exists(dfg, node.label)
186-
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
187-
end
188-
189-
neighbors = getNeighborhood(dfg, node.label, distance)
190-
191-
# for some reason: always returns the node at the center with || (nlbl == node.label)
192-
solvable != 0 && filter!(nlbl -> (getSolvable(dfg, nlbl) >= solvable) || (nlbl == node.label), neighbors)
193-
194-
# Copy the section of graph we want
195-
_copyIntoGraph!(dfg, addToDFG, neighbors, includeOrphanFactors)
196-
return addToDFG
197-
end
198-
199-
"""
200-
$(SIGNATURES)
201-
Get a deep subgraph copy from the DFG given a list of variables and factors.
202-
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
203-
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
204-
"""
205-
function getSubgraph(dfg::G,
206-
variableFactorLabels::Vector{Symbol},
207-
includeOrphanFactors::Bool=false,
208-
addToDFG::H=_getDuplicatedEmptyDFG(dfg))::H where {G <: AbstractDFG, H <: AbstractDFG}
209-
210-
Base.depwarn("getSubgraph is deprecated use buildSubgraph", :getSubgraph)
211-
212-
for label in variableFactorLabels
213-
if !exists(dfg, label)
214-
error("Variable/factor with label '$(label)' does not exist in the factor graph")
215-
end
32+
Base.getproperty(x::DFGVariable,f::Symbol) = begin
33+
if f == :solvable
34+
getfield(x,:_dfgNodeParams).solvable
35+
elseif f == :_internalId
36+
getfield(x,:_dfgNodeParams)._internalId
37+
else
38+
getfield(x,f)
21639
end
217-
218-
_copyIntoGraph!(dfg, addToDFG, variableFactorLabels, includeOrphanFactors)
219-
return addToDFG
22040
end
22141

222-
223-
# TODO needsahome: home should be in IIF, calling just deepcopyGraph, or copyGraph
224-
# Into, Labels, Subgraph are all implied from the parameters.
225-
# can alies names but like Sam suggested only on copy is needed.
226-
227-
228-
"""
229-
$SIGNATURES
230-
Construct a new factor graph object as a subgraph of `dfg <: AbstractDFG` based on the
231-
variable labels `syms::Vector{Symbols}`.
232-
233-
SamC: Can we not just use _copyIntoGraph! for this? Looks like a small refactor to make it work.
234-
Will paste in as-is for now and we can figure it out as we go.
235-
DF: Absolutely agree that subgraph functions should use `DFG._copyIntoGraph!` as a single dependency in the code base. There have been a repeated new rewrites of IIF.buildSubGraphFromLabels (basic wrapper is fine) but nominal should be to NOT duplicate DFG functionality in IIF -- rather use/improve the existing features in DFG. FYI, I have repeatedly refactored this function over and over to use DFG properly but somehow this (add/delete/Variable/Factor) version keeps coming back without using `_copyIntoGraph`!!??? See latest effort commented out below `buildSubgraphFromLabels!_SPECIAL`...
236-
237-
Notes
238-
- Slighly messy internals, but gets the job done -- some room for performance improvement.
239-
- Defaults to GraphDFG, but likely to change to LightDFG in future.
240-
- since DFG v0.6 LightDFG is the default.
241-
242-
DevNotes
243-
- TODO: still needs to be consolidated with `DFG._copyIntoGraph`
244-
245-
Related
246-
247-
listVariables, _copyIntoGraph!
248-
"""
249-
function buildSubgraphFromLabels!(dfg::G,
250-
syms::Vector{Symbol};
251-
subfg::AbstractDFG=(G <: InMemoryDFGTypes ? G : GraphsDFG)(params=getSolverParams(dfg)),
252-
solvable::Int=0,
253-
allowedFactors::Union{Nothing, Vector{Symbol}}=nothing )::AbstractDFG where G <: AbstractDFG
254-
#
255-
Base.depwarn("buildSubgraphFromLabels! is deprecated use copyGraph, buildSubgraph or buildCliqueSubgraph!(IIF)", :buildSubgraphFromLabels!)
256-
# add a little too many variables (since we need the factors)
257-
for sym in syms
258-
if solvable <= getSolvable(dfg, sym)
259-
getSubgraphAroundNode(dfg, getVariable(dfg, sym), 2, false, subfg, solvable=solvable)
260-
end
261-
end
262-
263-
# remove excessive variables that were copied by neighbors distance 2
264-
currVars = listVariables(subfg)
265-
toDelVars = setdiff(currVars, syms)
266-
for dv in toDelVars
267-
# delete any neighboring factors first
268-
for fc in lsf(subfg, dv)
269-
deleteFactor!(subfg, fc)
270-
end
271-
272-
# and the variable itself
273-
deleteVariable!(subfg, dv)
274-
end
275-
276-
# delete any factors not in the allowed list
277-
if allowedFactors != nothing
278-
delFcts = setdiff(lsf(subfg), allowedFactors)
279-
for dfct in delFcts
280-
deleteFactor!(subfg, dfct)
42+
Base.setproperty!(x::DFGVariable,f::Symbol, val) = begin
43+
if f == :solvable
44+
getfield(x,:_dfgNodeParams).solvable = val
45+
elseif f == :_internalId
46+
getfield(x,:_dfgNodeParams)._internalId = val
47+
else
48+
setfield!(x,f,val)
28149
end
282-
end
283-
284-
# orphaned variables are allowed, but not orphaned factors
285-
286-
return subfg
28750
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export
233233

234234
## Deprecated exports should be listed in Deprecated.jl if possible, otherwise here
235235
#TODO remove export in DFG v0.8.0
236-
export ConvolutionObject
236+
# export ConvolutionObject
237237

238238
## needsahome.jl
239239
import Base: print

src/entities/DFGFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ abstract type FunctorInferenceType <: Function end
1212
abstract type FactorOperationalMemory <: Function end
1313
# TODO to be removed from DFG,
1414
# we can add to IIF or have IIF.CommonConvWrapper <: FactorOperationalMemory directly
15-
abstract type ConvolutionObject <: FactorOperationalMemory end
15+
# abstract type ConvolutionObject <: FactorOperationalMemory end
1616

1717
abstract type FunctorSingleton <: FunctorInferenceType end
1818
abstract type FunctorPairwise <: FunctorInferenceType end

src/services/AbstractDFG.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,20 @@ function buildSubgraph(::Type{G},
954954
variableFactorLabels::Vector{Symbol},
955955
distance::Int=0;
956956
solvable::Int=0,
957+
sessionId::String = "",
957958
kwargs...) where G <: AbstractDFG
958959

960+
if sessionId == ""
961+
sessionId = getSessionId(dfg) * "_sub_$(string(uuid4())[1:6])"
962+
end
963+
959964
#build up the neighborhood from variableFactorLabels
960965
allvarfacs = getNeighborhood(dfg, variableFactorLabels, distance; solvable=solvable)
961966

962967
variableLabels = intersect(listVariables(dfg), allvarfacs)
963968
factorLabels = intersect(listFactors(dfg), allvarfacs)
964969
# Copy the section of graph we want
965-
destDFG = deepcopyGraph(G, dfg, variableLabels, factorLabels; kwargs...)
970+
destDFG = deepcopyGraph(G, dfg, variableLabels, factorLabels; sessionId=sessionId, kwargs...)
966971
return destDFG
967972
end
968973

test/CGStructureTests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ f2 = addFactor!(dfg, [:b; :c], LinearConditional(Normal(50.0,2.0)) )
6969
sessions = lsSessions(dfg)
7070
@test map(s -> s.id, sessions) == [session.id]
7171

72-
dfgLocal = GraphsDFG{SolverParams}(params=SolverParams())
73-
DistributedFactorGraphs.getSubgraph(dfg, union(ls(dfg), lsf(dfg)), true, dfgLocal)
72+
dfgLocal = buildSubgraph(LightDFG, dfg, union(ls(dfg), lsf(dfg)))
7473
# Confirm that with sentinels we still have the same graph (doesn't pull in the sentinels)
7574
@test symdiff(ls(dfgLocal), ls(dfg)) == []
7675
@test symdiff(lsf(dfgLocal), lsf(dfg)) == []

test/LightDFGSummaryTypes.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ end
8383
GettingNeighbors(LightDFG{NoSolverParams, VARTYPE, FACTYPE}, VARTYPE=VARTYPE, FACTYPE=FACTYPE)
8484
end
8585

86-
@testset "Getting Subgraphs" begin
87-
GettingSubgraphs(LightDFG{NoSolverParams, VARTYPE, FACTYPE}, VARTYPE=VARTYPE, FACTYPE=FACTYPE)
86+
# @testset "Getting Subgraphs" begin
87+
# GettingSubgraphs(LightDFG{NoSolverParams, VARTYPE, FACTYPE}, VARTYPE=VARTYPE, FACTYPE=FACTYPE)
88+
# end
89+
@testset "Building Subgraphs" begin
90+
BuildingSubgraphs(LightDFG{NoSolverParams, VARTYPE, FACTYPE}, VARTYPE=VARTYPE, FACTYPE=FACTYPE)
8891
end
8992

90-
9193
@testset "Producing Dot Files" begin
9294
ProducingDotFiles(LightDFG{NoSolverParams, VARTYPE, FACTYPE}, VARTYPE=VARTYPE, FACTYPE=FACTYPE)
9395
end

0 commit comments

Comments
 (0)