Skip to content

Commit bd1ec06

Browse files
authored
Merge pull request #217 from JuliaRobotics/feature/moving_isSolveInProgress
Moving isSolveInProgress to solver structures
2 parents d3c1a43 + 75ab42d commit bd1ec06

File tree

12 files changed

+63
-267
lines changed

12 files changed

+63
-267
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export getUserData, setUserData, getRobotData, setRobotData, getSessionData, set
3333
export pushUserData!, pushRobotData!, pushSessionData!, popUserData!, popRobotData!, popSessionData!
3434

3535
# Services/AbstractDFG Exports
36-
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
36+
export isInitialized, getFactorFunction, isVariable, isFactor
3737
export isSolvable, isSolveInProgress
3838
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
3939

src/entities/DFGFactor.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ mutable struct GenericFunctionNodeData{T, S}
2424
fnc::T
2525
multihypo::String # likely to moved when GenericWrapParam is refactored
2626
certainhypo::Vector{Int}
27+
solveInProgress::Int
2728
GenericFunctionNodeData{T, S}() where {T, S} = new{T,S}()
28-
GenericFunctionNodeData{T, S}(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T, S} = new{T,S}(x1, x2, x3, x4, x5, x6, x7, x8)
29-
GenericFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T, S} = new{T,S}(x1, x2, x3, x4, x5, x6, x7, x8)
29+
GenericFunctionNodeData{T, S}(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T, S} = new{T,S}(x1, x2, x3, x4, x5, x6, x7, x8, x9)
30+
GenericFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T, S} = new{T,S}(x1, x2, x3, x4, x5, x6, x7, x8, x9)
3031
# GenericFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String) where {T, S} = new{T,S}(x1, x2, x3, x4, x5, x6, x7)
3132
end
3233

@@ -39,11 +40,10 @@ mutable struct DFGFactor{T, S} <: AbstractDFGFactor
3940
tags::Vector{Symbol}
4041
data::GenericFunctionNodeData{T, S}
4142
solvable::Int
42-
solveInProgress::Int
4343
_internalId::Int64
4444
_variableOrderSymbols::Vector{Symbol}
45-
DFGFactor{T, S}(label::Symbol) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, 0, Symbol[])
46-
DFGFactor{T, S}(label::Symbol, _internalId::Int64) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, _internalId, Symbol[])
45+
DFGFactor{T, S}(label::Symbol) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, Symbol[])
46+
DFGFactor{T, S}(label::Symbol, _internalId::Int64) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, _internalId, Symbol[])
4747
end
4848

4949
label(f::F) where F <: DFGFactor = f.label
@@ -84,9 +84,9 @@ internalId(f::F) where F <: DFGFactor = f._internalId
8484

8585
# Simply for convenience - don't export
8686
const PackedFunctionNodeData{T} = GenericFunctionNodeData{T, <: AbstractString}
87-
PackedFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T <: PackedInferenceType, S <: AbstractString} = GenericFunctionNodeData(x1, x2, x3, x4, x5, x6, x7, x8)
87+
PackedFunctionNodeData(x1, x2, x3, x4, x5::S, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T <: PackedInferenceType, S <: AbstractString} = GenericFunctionNodeData(x1, x2, x3, x4, x5, x6, x7, x8, x9)
8888
const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}
89-
FunctionNodeData(x1, x2, x3, x4, x5::Symbol, x6::T, x7::String="", x8::Vector{Int}=Int[]) where {T <: Union{FunctorInferenceType, ConvolutionObject}}= GenericFunctionNodeData{T, Symbol}(x1, x2, x3, x4, x5, x6, x7, x8)
89+
FunctionNodeData(x1, x2, x3, x4, x5::Symbol, x6::T, x7::String="", x8::Vector{Int}=Int[], x9::Int=0) where {T <: Union{FunctorInferenceType, ConvolutionObject}}= GenericFunctionNodeData{T, Symbol}(x1, x2, x3, x4, x5, x6, x7, x8, x9)
9090

9191
"""
9292
$(SIGNATURES)

src/entities/DFGVariable.jl

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,40 @@ mutable struct VariableNodeData{T<:InferenceVariable}
2121
inferdim::Float64
2222
ismargin::Bool
2323
dontmargin::Bool
24+
solveInProgress::Int
2425
# Tonio surprise TODO
2526
# frontalonly::Bool
2627
end
2728

28-
# Julia is issuing a warning, this doesn't look to be necessary.
29-
# VariableNodeData(val::Array{Float64,2},
30-
# bw::Array{Float64,2},
31-
# BayesNetOutVertIDs::Array{Symbol,1},
32-
# dimIDs::Array{Int,1},
33-
# dims::Int,eliminated::Bool,
34-
# BayesNetVertID::Symbol,
35-
# separator::Array{Symbol,1},
36-
# softtype::T,
37-
# initialized::Bool,
38-
# inferdim::Float64,
39-
# ismargin::Bool,
40-
# dontmargin::Bool) where T <: InferenceVariable = VariableNodeData{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,eliminated,BayesNetVertID,separator,softtype::T,initialized,inferdim,ismargin,dontmargin)
29+
VariableNodeData(val::Array{Float64,2},
30+
bw::Array{Float64,2},
31+
BayesNetOutVertIDs::Array{Symbol,1},
32+
dimIDs::Array{Int,1},
33+
dims::Int,eliminated::Bool,
34+
BayesNetVertID::Symbol,
35+
separator::Array{Symbol,1},
36+
softtype::T,
37+
initialized::Bool,
38+
inferdim::Float64,
39+
ismargin::Bool,
40+
dontmargin::Bool,
41+
solveInProgress::Int=0) where T <: InferenceVariable =
42+
VariableNodeData{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,eliminated,BayesNetVertID,separator,
43+
softtype::T,initialized,inferdim,ismargin,dontmargin, solveInProgress)
44+
4145

4246
function VariableNodeData()
4347
st = stacktrace()
4448
@warn "VariableNodeData() is deprecated please use VariableNodeData{T}() or VariableNodeData(softtype::T) where T <: InferenceVariable. Enable DEBUG logging for stack trace."
4549
@debug st
46-
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false)
50+
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false, 0)
4751
end
4852

4953
VariableNodeData{T}() where {T <:InferenceVariable} =
50-
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false)
54+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0)
5155

5256
VariableNodeData(softtype::T) where T <: InferenceVariable =
53-
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false)
57+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0)
5458

5559
"""
5660
$(TYPEDEF)
@@ -71,6 +75,7 @@ mutable struct PackedVariableNodeData
7175
inferdim::Float64
7276
ismargin::Bool
7377
dontmargin::Bool
78+
solveInProgress::Int
7479
PackedVariableNodeData() = new()
7580
PackedVariableNodeData(x1::Vector{Float64},
7681
x2::Int,
@@ -86,7 +91,8 @@ mutable struct PackedVariableNodeData
8691
x12::Bool,
8792
x13::Float64,
8893
x14::Bool,
89-
x15::Bool ) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15)
94+
x15::Bool,
95+
x16::Int) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16)
9096
end
9197

9298
# AbstractPointParametricEst interface
@@ -128,7 +134,6 @@ mutable struct DFGVariable <: AbstractDFGVariable
128134
smallData::Dict{String, String}
129135
bigData::Dict{Symbol, AbstractBigDataEntry}
130136
solvable::Int
131-
solveInProgress::Int
132137
_internalId::Int64
133138
end
134139

@@ -145,21 +150,14 @@ function DFGVariable(label::Symbol, _internalId::Int64 = 0) #where {T <:Inferenc
145150
Dict{Symbol, MeanMaxPPE}(),
146151
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData()),
147152
Dict{String, String}(),
148-
Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
153+
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)
149154
end
150155
DFGVariable(label::Symbol, softtype::T, _internalId::Int64 = 0) where {T <: InferenceVariable} =
151156
DFGVariable(label, now(), Symbol[],
152157
Dict{Symbol, MeanMaxPPE}(),
153158
Dict{Symbol, VariableNodeData{T}}(:default => VariableNodeData{T}()),
154159
Dict{String, String}(),
155-
Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
156-
157-
# DFGVariable(label::Symbol, _internalId::Int64) =
158-
# DFGVariable(label, now(), Symbol[], Dict{Symbol, Dict{Symbol, VariableEstimate}}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, _internalId)
159-
#
160-
# DFGVariable(label::Symbol) =
161-
# DFGVariable(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), Dict{String, String}(), Dict{Symbol,AbstractBigDataEntry}(), 0, 0, 0)
162-
#
160+
Dict{Symbol,AbstractBigDataEntry}(), 0, _internalId)
163161

164162
# Accessors
165163
label(v::DFGVariable) = v.label

src/services/AbstractDFG.jl

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Related
339339
340340
isSolveInProgress
341341
"""
342-
isSolvable(var::Union{DFGVariable, DFGFactor}) = var.solvable
342+
isSolvable(var::Union{DFGVariable, DFGFactor})::Int = var.solvable
343343

344344
"""
345345
$SIGNATURES
@@ -353,7 +353,12 @@ Related
353353
354354
isSolvable
355355
"""
356-
isSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol=:default) = var.solveInProgress
356+
function isSolveInProgress(var::Union{DFGVariable, DFGFactor}; solveKey::Symbol=:default)::Int
357+
# Variable
358+
var isa DFGVariable && return haskey(solverDataDict(var), solveKey) ? solverDataDict(var)[solveKey].solveInProgress : 0
359+
# Factor
360+
return solverData(var).solveInProgress
361+
end
357362

358363
"""
359364
$(SIGNATURES)
@@ -513,27 +518,6 @@ function getAdjacencyMatrixSparse(dfg::G; solvable::Int=0)::Tuple{SparseMatrixCS
513518
return adjMat, varLabels, factLabels
514519
end
515520

516-
"""
517-
$SIGNATURES
518-
519-
Return boolean whether a factor `label` is present in `<:AbstractDFG`.
520-
"""
521-
function hasFactor(dfg::G, label::Symbol)::Bool where {G <: AbstractDFG}
522-
@warn "hasFactor() deprecated, please use exists()"
523-
return exists(dfg, label)
524-
end
525-
526-
"""
527-
$(SIGNATURES)
528-
529-
Return `::Bool` on whether `dfg` contains the variable `lbl::Symbol`.
530-
"""
531-
function hasVariable(dfg::G, label::Symbol)::Bool where {G <: AbstractDFG}
532-
@warn "hasVariable() deprecated, please use exists()"
533-
return exists(dfg, label) # haskey(vertices(dfg.g), label)
534-
end
535-
536-
537521
"""
538522
$SIGNATURES
539523
@@ -562,14 +546,14 @@ end
562546
563547
Return whether `sym::Symbol` represents a variable vertex in the graph.
564548
"""
565-
isVariable(dfg::G, sym::Symbol) where G <: AbstractDFG = hasVariable(dfg, sym)
549+
isVariable(dfg::G, sym::Symbol) where G <: AbstractDFG = exists(dfg, sym)
566550

567551
"""
568552
$SIGNATURES
569553
570554
Return whether `sym::Symbol` represents a factor vertex in the graph.
571555
"""
572-
isFactor(dfg::G, sym::Symbol) where G <: AbstractDFG = hasFactor(dfg, sym)
556+
isFactor(dfg::G, sym::Symbol) where G <: AbstractDFG = exists(dfg, sym)
573557

574558
"""
575559
$SIGNATURES

src/services/DFGFactor.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstract
2525
# Include the type
2626
props["fnctype"] = String(_getname(fnctype))
2727
props["_variableOrderSymbols"] = JSON2.write(f._variableOrderSymbols)
28-
props["solveInProgress"] = f.solveInProgress
2928
props["solvable"] = f.solvable
3029

3130
return props
@@ -54,7 +53,6 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}, iifModule)::DFGFac
5453

5554
# Include the type
5655
_variableOrderSymbols = JSON2.read(packedProps["_variableOrderSymbols"], Vector{Symbol})
57-
solveInProgress = packedProps["solveInProgress"]
5856
solvable = packedProps["solvable"]
5957

6058
# Rebuild DFGVariable
@@ -63,7 +61,6 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}, iifModule)::DFGFac
6361
factor.data = fullFactor
6462
factor._variableOrderSymbols = _variableOrderSymbols
6563
factor.solvable = solvable
66-
factor.solveInProgress = solveInProgress
6764

6865
# GUARANTEED never to bite us in the ass in the future...
6966
# ... TODO: refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350

src/services/DFGVariable.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
99
props["solverDataDict"] = JSON2.write(Dict(keys(v.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(v.solverDataDict))))
1010
props["smallData"] = JSON2.write(v.smallData)
1111
props["solvable"] = v.solvable
12-
props["solveInProgress"] = v.solveInProgress
1312
return props
1413
end
1514

@@ -38,7 +37,6 @@ function unpackVariable(dfg::G, packedProps::Dict{String, Any})::DFGVariable whe
3837
variable.solverDataDict = solverData
3938
variable.smallData = smallData
4039
variable.solvable = packedProps["solvable"]
41-
variable.solveInProgress = packedProps["solveInProgress"]
4240

4341
return variable
4442
end
@@ -50,7 +48,7 @@ function pack(dfg::G, d::VariableNodeData)::PackedVariableNodeData where G <: Ab
5048
d.BayesNetOutVertIDs,
5149
d.dimIDs, d.dims, d.eliminated,
5250
d.BayesNetVertID, d.separator,
53-
d.softtype != nothing ? string(d.softtype) : nothing, d.initialized, d.inferdim, d.ismargin, d.dontmargin)
51+
d.softtype != nothing ? string(d.softtype) : nothing, d.initialized, d.inferdim, d.ismargin, d.dontmargin, d.solveInProgress)
5452
end
5553

5654
function unpack(dfg::G, d::PackedVariableNodeData)::VariableNodeData where G <: AbstractDFG
@@ -89,7 +87,7 @@ function unpack(dfg::G, d::PackedVariableNodeData)::VariableNodeData where G <:
8987

9088
return VariableNodeData{typeof(st)}(M3,M4, d.BayesNetOutVertIDs,
9189
d.dimIDs, d.dims, d.eliminated, d.BayesNetVertID, d.separator,
92-
st, d.initialized, d.inferdim, d.ismargin, d.dontmargin )
90+
st, d.initialized, d.inferdim, d.ismargin, d.dontmargin, d.solveInProgress)
9391
end
9492

9593
function compare(a::VariableNodeData, b::VariableNodeData)
@@ -105,6 +103,7 @@ function compare(a::VariableNodeData, b::VariableNodeData)
105103
abs(a.inferdim - b.inferdim) > 1e-14 && @debug("inferdim is not equal")==nothing && return false
106104
a.ismargin != b.ismargin && @debug("ismargin is not equal")==nothing && return false
107105
a.dontmargin != b.dontmargin && @debug("dontmargin is not equal")==nothing && return false
106+
a.solveInProgress != b.solveInProgress && @debug("solveInProgress is not equal")==nothing && return false
108107
typeof(a.softtype) != typeof(b.softtype) && @debug("softtype is not equal")==nothing && return false
109108
return true
110109
end

test/fileDFGTests.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
# Same graph as iifInterfaceTests.jl
99
numNodes = 10
1010

11-
#change ready and backendset for x7,x8 for improved tests on x7x8f1
11+
#change ready and solvable for x7,x8 for improved tests on x7x8f1
1212
verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:POSE]), 1:numNodes)
1313
#TODO fix this to use accessors
1414
verts[7].solvable = 1
15-
# verts[7].backendset = 0
1615
verts[8].solvable = 0
17-
verts[8].solveInProgress = 1
16+
solverData(verts[8]).solveInProgress = 1
1817
#call update to set it on cloud
1918
updateVariable!(dfg, verts[7])
2019
updateVariable!(dfg, verts[8])

test/iifInterfaceTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ verts = map(n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar, labels = [:P
349349
#TODO fix this to use accessors
350350
verts[7].solvable = 1
351351
verts[8].solvable = 0
352-
verts[8].solveInProgress = 1
352+
solverData(verts[8]).solveInProgress = 1
353353
#call update to set it on cloud
354354
updateVariable!(dfg, verts[7])
355355
updateVariable!(dfg, verts[8])

0 commit comments

Comments
 (0)