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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
- Deprecate getBlobentryFirst -> getfirstBlobentry, see #1114
- OrderedDict is no longer exported
- FolderStore path now includes the store label.
- Standardized error types and behaviour.

# v0.26
- Graph structure plotting now uses GraphMakie.jl instead of GraphPlot.jl. Update by replacing `using GraphPlot` with `using GraphMakie`.
Expand Down
6 changes: 6 additions & 0 deletions docs/src/func_ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ Modules = [DistributedFactorGraphs]
Pages = ["entities/DFGFactor.jl"]
```

### Error Types
```@autodocs
Modules = [DistributedFactorGraphs]
Pages = ["errors.jl"]
```

## DFG Plots [GraphMakie.jl]

```@autodocs
Expand Down
15 changes: 5 additions & 10 deletions src/DataBlobs/services/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@
"""
function getBlobentry(var::AbstractDFGVariable, key::Symbol)
if !hasBlobentry(var, key)
throw(
KeyError(
"No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))",
),
)
throw(LabelNotFoundError("Blobentry", key, collect(keys(var.dataDict))))
end
return var.dataDict[key]
end

function getBlobentry(var::VariableDFG, key::Symbol)
if !hasBlobentry(var, key)
throw(KeyError(key))
throw(LabelNotFoundError("Blobentry", key))

Check warning on line 77 in src/DataBlobs/services/BlobEntry.jl

View check run for this annotation

Codecov / codecov/patch

src/DataBlobs/services/BlobEntry.jl#L77

Added line #L77 was not covered by tests
end
return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
end
Expand Down Expand Up @@ -156,19 +152,18 @@

Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentries!`](@ref)
"""
function addBlobentry!(var::AbstractDFGVariable, entry::Blobentry;)
function addBlobentry!(var::AbstractDFGVariable, entry::Blobentry)
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
# blobId::Union{UUID,Nothing} = (isnothing(entry.blobId) ? entry.id : entry.blobId),
# blobSize::Int = (hasfield(Blobentry, :size) ? entry.size : -1)
haskey(var.dataDict, entry.label) &&
error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
haskey(var.dataDict, entry.label) && throw(LabelExistsError("Blobentry", entry.label))
var.dataDict[entry.label] = entry
return entry
end

function addBlobentry!(var::VariableDFG, entry::Blobentry)
entry.label in getproperty.(var.blobEntries, :label) &&
error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
throw(LabelExistsError("Blobentry", entry.label))
push!(var.blobEntries, entry)
return entry
end
Expand Down
10 changes: 10 additions & 0 deletions src/Deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@
return error("fncStringToData is obsolete.")
end

#TODO make sure getFactorOperationalMemoryType is obsolete
function getFactorOperationalMemoryType(dummy)
return error(

Check warning on line 425 in src/Deprecated.jl

View check run for this annotation

Codecov / codecov/patch

src/Deprecated.jl#L424-L425

Added lines #L424 - L425 were not covered by tests
"Please extend your workspace with function getFactorOperationalMemoryType(<:AbstractParams) for your usecase, e.g. IncrementalInference uses `CommonConvWrapper <: FactorSolverCache`",
)
end
function getFactorOperationalMemoryType(dfg::AbstractDFG)
return getFactorOperationalMemoryType(getSolverParams(dfg))

Check warning on line 430 in src/Deprecated.jl

View check run for this annotation

Codecov / codecov/patch

src/Deprecated.jl#L429-L430

Added lines #L429 - L430 were not covered by tests
end

## ================================================================================
## Deprecated in v0.25
##=================================================================================
Expand Down
1 change: 1 addition & 0 deletions src/DistributedFactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ export plotDFG
##==============================================================================

# Entities
include("errors.jl")

include("entities/AbstractDFG.jl")

Expand Down
7 changes: 4 additions & 3 deletions src/GraphsDFG/FactorGraphs/FactorGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ function addFactor!(
(@error "Label $(factor.label) already in fg"; return false)

for vlabel in variableLabels
!haskey(g.labels, vlabel) && (throw(KeyError(vlabel))
# @error "Variable '$(vlabel)' not found in graph when creating Factor '$(factor.label)'"; return false
) #TODO debug error or exception?
if !haskey(g.labels, vlabel)
@error "Variable '$(vlabel)' not found in graph when creating Factor '$(factor.label)'"
return false
end
end

add_vertex!(g.graph) || return false
Expand Down
2 changes: 1 addition & 1 deletion src/GraphsDFG/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using OrderedCollections
using StructTypes

using ...DistributedFactorGraphs
using ...DistributedFactorGraphs: Agent
using ...DistributedFactorGraphs: Agent, LabelNotFoundError, LabelExistsError

# import DFG functions to extend
import ...DistributedFactorGraphs:
Expand Down
35 changes: 16 additions & 19 deletions src/GraphsDFG/services/GraphsDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
dfg::GraphsDFG{<:AbstractParams, V, <:AbstractDFGFactor},
variable::V,
) where {V <: AbstractDFGVariable}
#TODO should this be an error
if haskey(dfg.g.variables, variable.label)
error("Variable '$(variable.label)' already exists in the factor graph")
throw(LabelExistsError("Variable", variable.label))
end

FactorGraphs.addVariable!(dfg.g, variable) || return false
Expand Down Expand Up @@ -104,11 +103,15 @@
factor::F,
) where {F <: AbstractDFGFactor}
if haskey(dfg.g.factors, factor.label)
error("Factor '$(factor.label)' already exists in the factor graph")
throw(LabelExistsError("Factor", factor.label))
end
# TODO
# @assert FactorGraphs.addFactor!(dfg.g, getVariableOrder(factor), factor)
@assert FactorGraphs.addFactor!(dfg.g, Symbol[factor._variableOrderSymbols...], factor)
variableLabels = Symbol[factor._variableOrderSymbols...]
for vlabel in variableLabels
!exists(dfg, vlabel) && throw(LabelNotFoundError("Variable", vlabel))
end
@assert FactorGraphs.addFactor!(dfg.g, variableLabels, factor)
return factor
end

Expand All @@ -121,16 +124,15 @@

function getVariable(dfg::GraphsDFG, label::Symbol)
if !haskey(dfg.g.variables, label)
error("Variable label '$(label)' does not exist in the factor graph")
throw(LabelNotFoundError("Variable", label))
end

return dfg.g.variables[label]
end

function getFactor(dfg::GraphsDFG, label::Symbol)
if !haskey(dfg.g.factors, label)
#TODO throw a typed error
error("Factor label '$(label)' does not exist in the factor graph")
throw(LabelNotFoundError("Factor", label))
end
return dfg.g.factors[label]
end
Expand All @@ -151,8 +153,8 @@
#TODO should we allow merging the factor neighbors or error as before?
error("Cannot update the factor, the neighbors are not the same.")
# We need to delete the factor if we are updating the neighbors
deleteFactor!(dfg, factor.label)
addFactor!(dfg, factor)
# deleteFactor!(dfg, factor.label)
# addFactor!(dfg, factor)
else
dfg.g.factors[factor.label] = factor
end
Expand All @@ -162,7 +164,7 @@

function deleteVariable!(dfg::GraphsDFG, label::Symbol)#::Tuple{AbstractDFGVariable, Vector{<:AbstractDFGFactor}}
if !haskey(dfg.g.variables, label)
error("Variable label '$(label)' does not exist in the factor graph")
throw(LabelNotFoundError("Variable", label))
end

deleteNeighbors = true # reserved, orphaned factors are not supported at this time
Expand All @@ -175,7 +177,7 @@

function deleteFactor!(dfg::GraphsDFG, label::Symbol; suppressGetFactor::Bool = false)
if !haskey(dfg.g.factors, label)
error("Factor label '$(label)' does not exist in the factor graph")
throw(LabelNotFoundError("Factor", label))
end
rem_vertex!(dfg.g, dfg.g.labels[label])
return 1
Expand Down Expand Up @@ -280,10 +282,7 @@
function _isSolvable(dfg::GraphsDFG, label::Symbol, ready::Int)
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solvable >= ready)
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solvable >= ready)

#TODO should this be a breaking error?
@error "Node not in factor or variable"
return false
throw(LabelNotFoundError(label))

Check warning on line 285 in src/GraphsDFG/services/GraphsDFG.jl

View check run for this annotation

Codecov / codecov/patch

src/GraphsDFG/services/GraphsDFG.jl#L285

Added line #L285 was not covered by tests
end

function listNeighbors(dfg::GraphsDFG, node::DFGNode; solvable::Int = 0)
Expand All @@ -292,7 +291,7 @@

function listNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int = 0)
if !exists(dfg, label)
error("Variable/factor with label '$(label)' does not exist in the factor graph")
throw(LabelNotFoundError(label))

Check warning on line 294 in src/GraphsDFG/services/GraphsDFG.jl

View check run for this annotation

Codecov / codecov/patch

src/GraphsDFG/services/GraphsDFG.jl#L294

Added line #L294 was not covered by tests
end

neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
Expand Down Expand Up @@ -540,9 +539,7 @@

function addGraphBlobentry!(fg::GraphsDFG, entry::Blobentry)
if haskey(fg.graphBlobEntries, entry.label)
error(
"Blobentry '$(entry.label)' already exists in the factor graph's blob entries.",
)
throw(LabelExistsError("Blobentry", entry.label))

Check warning on line 542 in src/GraphsDFG/services/GraphsDFG.jl

View check run for this annotation

Codecov / codecov/patch

src/GraphsDFG/services/GraphsDFG.jl#L542

Added line #L542 was not covered by tests
end
push!(fg.graphBlobEntries, entry.label => entry)
return entry
Expand Down
57 changes: 57 additions & 0 deletions src/errors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Comment thread
Affie marked this conversation as resolved.
LabelNotFoundError(label, available)

Error thrown when a requested label is not found in the factor graph.
"""
struct LabelNotFoundError <: Exception
name::String
label::Symbol
available::Vector{Symbol}
end

LabelNotFoundError(name::String, label::Symbol) = LabelNotFoundError(name, label, Symbol[])
LabelNotFoundError(label::Symbol) = LabelNotFoundError("Node", label, Symbol[])

Check warning on line 13 in src/errors.jl

View check run for this annotation

Codecov / codecov/patch

src/errors.jl#L13

Added line #L13 was not covered by tests

function Base.showerror(io::IO, ex::LabelNotFoundError)
print(io, "LabelNotFoundError: ", ex.name, " label '", ex.label, "' not found.")
if !isempty(ex.available)
println(io, " Available labels:")
show(io, ex.available)

Check warning on line 19 in src/errors.jl

View check run for this annotation

Codecov / codecov/patch

src/errors.jl#L15-L19

Added lines #L15 - L19 were not covered by tests
end
end

"""
LabelExistsError(label)

Error thrown when attempting to add a label that already exists in the collection.
"""
struct LabelExistsError <: Exception
name::String
label::Symbol
end

LabelExistsError(label::Symbol) = LabelExistsError("Node", label)

Check warning on line 33 in src/errors.jl

View check run for this annotation

Codecov / codecov/patch

src/errors.jl#L33

Added line #L33 was not covered by tests

function Base.showerror(io::IO, ex::LabelExistsError)
return print(

Check warning on line 36 in src/errors.jl

View check run for this annotation

Codecov / codecov/patch

src/errors.jl#L35-L36

Added lines #L35 - L36 were not covered by tests
io,
"LabelExistsError: ",
ex.name,
" label '",
ex.label,
"' already exists.",
)
end

"""
SerializationError(msg)

Error thrown when serialization or deserialization fails.
"""
struct SerializationError <: Exception
msg::String
end

function Base.showerror(io::IO, ex::SerializationError)
return print(io, "SerializationError: ", ex.msg)

Check warning on line 56 in src/errors.jl

View check run for this annotation

Codecov / codecov/patch

src/errors.jl#L55-L56

Added lines #L55 - L56 were not covered by tests
end
23 changes: 6 additions & 17 deletions src/services/AbstractDFG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,6 @@
"""
getSolverParams(dfg::AbstractDFG) = dfg.solverParams

"""
$(SIGNATURES)

Method must be overloaded by the user for Serialization to work. E.g. IncrementalInference uses `CommonConvWrapper <: FactorSolverCache`.
"""
function getFactorOperationalMemoryType(dummy)
return error(
"Please extend your workspace with function getFactorOperationalMemoryType(<:AbstractParams) for your usecase, e.g. IncrementalInference uses `CommonConvWrapper <: FactorSolverCache`",
)
end
function getFactorOperationalMemoryType(dfg::AbstractDFG)
return getFactorOperationalMemoryType(getSolverParams(dfg))
end

"""
$(SIGNATURES)

Expand All @@ -121,7 +107,10 @@
factor::AbstractDFGFactor,
neighbors = [],
)
@warn("rebuildFactorCache! is not implemented for $(typeof(dfg))")
@warn(

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

View check run for this annotation

Codecov / codecov/patch

src/services/AbstractDFG.jl#L110

Added line #L110 was not covered by tests
"FactorCache not build, rebuildFactorCache! is not implemented for $(typeof(dfg)). Make sure to load IncrementalInference.",
maxlog = 1
)
return nothing
end

Expand Down Expand Up @@ -533,7 +522,7 @@
var = getVariable(dfg, label)

if isa(var, VariableCompute) && !haskey(var.solverDataDict, solveKey)
error("Solvekey '$solveKey' does not exists in the variable")
throw(LabelNotFoundError("VariableNode", solveKey))
elseif !isa(var, VariableCompute)
@warn "getVariable(dfg, label, solveKey) only supported for type VariableCompute."
end
Expand Down Expand Up @@ -1096,7 +1085,7 @@
elseif overwriteDest
mergeVariable!(destDFG, variableCopy)
else
error("Variable $(variable.label) already exists in destination graph!")
throw(LabelExistsError("Variable", variable.label))
end
end
# And then all factors to the destDFG.
Expand Down
Loading
Loading