Skip to content

Commit 266f80b

Browse files
authored
Merge pull request #210 from JuliaRobotics/feature/4Q19/v051_cleanup
Feature - 4Q19 - v0.51 cleanup
2 parents 47f1527 + 433b2fc commit 266f80b

File tree

14 files changed

+78
-217
lines changed

14 files changed

+78
-217
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1313
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
1414
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1515
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
16-
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
1716
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1817
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1918
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -27,7 +26,6 @@ GraphPlot = "0.3.1, 0.4"
2726
Graphs = "0.10.2, 0.11, 1"
2827
JSON2 = "0.3.1"
2928
LightGraphs = "1.2, 1.3"
30-
MetaGraphs = "^0.6.3"
3129
Neo4j = "2"
3230
Reexport = "0.2, 0.3, 0.4, 0.5, 1"
3331
Requires = "0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 1"

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 13 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,7 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::Bool
9191
if exists(dfg, variable)
9292
error("Variable '$(variable.label)' already exists in the factor graph")
9393
end
94-
props = Dict{String, Any}()
95-
props["label"] = string(variable.label)
96-
props["timestamp"] = string(variable.timestamp)
97-
props["tags"] = JSON2.write(variable.tags)
98-
props["estimateDict"] = JSON2.write(variable.estimateDict)
99-
props["solverDataDict"] = JSON2.write(Dict(keys(variable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(variable.solverDataDict))))
100-
props["smallData"] = JSON2.write(variable.smallData)
101-
props["ready"] = variable.solvable
102-
props["backendset"] = variable.solveInProgress
103-
# Don't handle big data at the moment.
94+
props = packVariable(dfg, variable)
10495

10596
neo4jNode = Neo4j.createnode(dfg.neo4jInstance.graph, props);
10697
variable._internalId = neo4jNode.id
@@ -132,20 +123,7 @@ function addFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor:
132123
factor._variableOrderSymbols = map(v->v.label, variables)
133124

134125
# Construct the properties to save
135-
props = Dict{String, Any}()
136-
props["label"] = string(factor.label)
137-
props["tags"] = JSON2.write(factor.tags)
138-
# Pack the node data
139-
fnctype = factor.data.fnc.usrfnc!
140-
packtype = getfield(_getmodule(fnctype), Symbol("Packed$(_getname(fnctype))"))
141-
packed = convert(PackedFunctionNodeData{packtype}, factor.data)
142-
props["data"] = JSON2.write(packed)
143-
# Include the type
144-
props["fnctype"] = String(_getname(fnctype))
145-
props["_variableOrderSymbols"] = JSON2.write(factor._variableOrderSymbols)
146-
props["backendset"] = factor.solveInProgress
147-
props["ready"] = factor.solvable
148-
# Don't handle big data at the moment.
126+
props = packFactor(dfg, factor)
149127

150128
neo4jNode = Neo4j.createnode(dfg.neo4jInstance.graph, props);
151129
factor._internalId = neo4jNode.id
@@ -182,27 +160,8 @@ Get a DFGVariable from a DFG using its underlying integer ID.
182160
"""
183161
function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
184162
props = getnodeproperties(dfg.neo4jInstance.graph, variableId)
185-
# Time to do deserialization
186-
# props["label"] = Symbol(variable.label)
187-
timestamp = DateTime(props["timestamp"])
188-
tags = JSON2.read(props["tags"], Vector{Symbol})
189-
#TODO this will work for some time, but unpacking in an <: AbstractPointParametricEst would be lekker.
190-
estimateDict = JSON2.read(props["estimateDict"], Dict{Symbol, MeanMaxPPE})
191-
smallData = nothing
192-
smallData = JSON2.read(props["smallData"], Dict{String, String})
193-
194-
packed = JSON2.read(props["solverDataDict"], Dict{String, PackedVariableNodeData})
195-
solverData = Dict(Symbol.(keys(packed)) .=> map(p -> unpack(dfg, p), values(packed)))
196-
197-
# Rebuild DFGVariable
198-
variable = DFGVariable(Symbol(props["label"]), variableId)
199-
variable.timestamp = timestamp
200-
variable.tags = tags
201-
variable.estimateDict = estimateDict
202-
variable.solverDataDict = solverData
203-
variable.smallData = smallData
204-
variable.solvable = props["ready"]
205-
variable.solveInProgress = props["backendset"]
163+
variable = unpackVariable(dfg, props)
164+
variable._internalId = variableId
206165

207166
# Add to cache
208167
push!(dfg.variableCache, variable.label=>variable)
@@ -235,35 +194,14 @@ Get a DFGFactor from a DFG using its underlying integer ID.
235194
"""
236195
function getFactor(dfg::CloudGraphsDFG, factorId::Int64)::DFGFactor
237196
props = getnodeproperties(dfg.neo4jInstance.graph, factorId)
238-
239-
label = props["label"]
240-
tags = JSON2.read(props["tags"], Vector{Symbol})
241-
242-
data = props["data"]
243-
datatype = props["fnctype"]
244-
# fulltype = getfield(Main, Symbol(datatype))
245-
packtype = getfield(Main, Symbol("Packed"*datatype))
246-
packed = JSON2.read(data, GenericFunctionNodeData{packtype,String})
247-
fullFactor = dfg.decodePackedTypeFunc(dfg, packed)
248-
249-
# Include the type
250-
_variableOrderSymbols = JSON2.read(props["_variableOrderSymbols"], Vector{Symbol})
251-
backendset = props["backendset"]
252-
ready = props["ready"]
253-
254-
# Rebuild DFGVariable
255-
factor = DFGFactor{typeof(fullFactor.fnc), Symbol}(Symbol(label), factorId)
256-
factor.tags = tags
257-
factor.data = fullFactor
258-
factor._variableOrderSymbols = _variableOrderSymbols
259-
factor.solvable = ready
260-
factor.solveInProgress = backendset
197+
factor = unpackFactor(dfg, props, getSerializationModule(dfg))
198+
factor._internalId = factorId
261199

262200
# Lastly, rebuild the metadata
263201
factor = dfg.rebuildFactorMetadata!(dfg, factor)
264202
# GUARANTEED never to bite us in the future...
265203
# ... TODO: refactor if changed: https://github.com/JuliaRobotics/IncrementalInference.jl/issues/350
266-
solverData(factor).fncargvID = _variableOrderSymbols
204+
solverData(factor).fncargvID = factor._variableOrderSymbols
267205

268206
# Add to cache
269207
push!(dfg.factorCache, factor.label=>factor)
@@ -302,17 +240,7 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
302240
variable._internalId = nodeId
303241

304242
neo4jNode = Neo4j.getnode(dfg.neo4jInstance.graph, nodeId)
305-
props = getnodeproperties(dfg.neo4jInstance.graph, nodeId)
306-
307-
props["label"] = string(variable.label)
308-
props["timestamp"] = string(variable.timestamp)
309-
props["tags"] = JSON2.write(variable.tags)
310-
props["estimateDict"] = JSON2.write(variable.estimateDict)
311-
props["solverDataDict"] = JSON2.write(Dict(keys(variable.solverDataDict) .=> map(vnd -> pack(dfg, vnd), values(variable.solverDataDict))))
312-
props["smallData"] = JSON2.write(variable.smallData)
313-
props["ready"] = variable.solvable
314-
props["backendset"] = variable.solveInProgress
315-
# Don't handle big data at the moment.
243+
props = packVariable(dfg, variable)
316244

317245
Neo4j.updatenodeproperties(neo4jNode, props)
318246
Neo4j.updatenodelabels(neo4jNode, union([string(variable.label), "VARIABLE", dfg.userId, dfg.robotId, dfg.sessionId], variable.tags))
@@ -349,21 +277,7 @@ function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor
349277
# Update the _internalId
350278
factor._internalId = nodeId
351279
neo4jNode = Neo4j.getnode(dfg.neo4jInstance.graph, nodeId)
352-
props = getnodeproperties(dfg.neo4jInstance.graph, nodeId)
353-
354-
props["label"] = string(factor.label)
355-
props["tags"] = JSON2.write(factor.tags)
356-
# Pack the node data
357-
fnctype = factor.data.fnc.usrfnc!
358-
packtype = getfield(_getmodule(fnctype), Symbol("Packed$(_getname(fnctype))"))
359-
packed = convert(PackedFunctionNodeData{packtype}, factor.data)
360-
props["data"] = JSON2.write(packed)
361-
# Include the type
362-
props["fnctype"] = String(_getname(fnctype))
363-
props["_variableOrderSymbols"] = JSON2.write(factor._variableOrderSymbols)
364-
props["backendset"] = factor.solveInProgress
365-
props["ready"] = factor.solvable
366-
# Don't handle big data at the moment.
280+
props = packFactor(dfg, factor)
367281

368282
Neo4j.updatenodeproperties(neo4jNode, props)
369283
Neo4j.updatenodelabels(neo4jNode, union([string(factor.label), "FACTOR", dfg.userId, dfg.robotId, dfg.sessionId], factor.tags))
@@ -597,10 +511,10 @@ function getNeighbors(dfg::CloudGraphsDFG, node::T; ready::Union{Nothing, Int}=n
597511
query = "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))--(node) where (node:VARIABLE or node:FACTOR) "
598512
if ready != nothing || backendset != nothing
599513
if ready != nothing
600-
query = query * " and node.ready >= $(ready)"
514+
query = query * " and node.solvable >= $(ready)"
601515
end
602516
if backendset != nothing
603-
query = query * " and node.backendset = $(backendset)"
517+
query = query * " and node.solveInProgress = $(backendset)"
604518
end
605519
end
606520
@debug "[Query] $query"
@@ -620,10 +534,10 @@ function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing,
620534
query = "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(label))--(node) where (node:VARIABLE or node:FACTOR) "
621535
if ready != nothing || backendset != nothing
622536
if ready != nothing
623-
query = query * " and node.ready >= $(ready)"
537+
query = query * " and node.solvable >= $(ready)"
624538
end
625539
if backendset != nothing
626-
query = query * " and node.backendset = $(backendset)"
540+
query = query * " and node.solveInProgress = $(backendset)"
627541
end
628542
end
629543
@debug "[Query] $query"
@@ -756,32 +670,3 @@ function getAdjacencyMatrixSparse(dfg::CloudGraphsDFG)::Tuple{SparseMatrixCSC, V
756670

757671
return adjMat, varLabels, factLabels
758672
end
759-
760-
# """
761-
# $(SIGNATURES)
762-
# Produces a dot-format of the graph for visualization.
763-
# """
764-
# function toDot(dfg::CloudGraphsDFG)::String
765-
# m = PipeBuffer()
766-
# write(m,Graphs.to_dot(dfg.g))
767-
# data = take!(m)
768-
# close(m)
769-
# return String(data)
770-
# end
771-
#
772-
# """
773-
# $(SIGNATURES)
774-
# Produces a dot file of the graph for visualization.
775-
# Download XDot to see the data
776-
#
777-
# Note
778-
# - Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
779-
# - Can be viewed with the `xdot` system application.
780-
# - Based on graphviz.org
781-
# """
782-
# function toDotFile(dfg::CloudGraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
783-
# open(fileName, "w") do fid
784-
# write(fid,Graphs.to_dot(dfg.g))
785-
# end
786-
# return nothing
787-
# end

src/DFGPlots/DFGPlots.jl

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module DFGPlots
22

33
using Colors
44
using LightGraphs
5-
using MetaGraphs
65
using GraphPlot
76
using DocStringExtensions
87
import GraphPlot: gplot
@@ -84,39 +83,6 @@ using Compose
8483
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
8584
```
8685
87-
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
88-
"""
89-
function dfgplot(dfg::DistributedFactorGraphs.MetaGraphsDFG, p::DFGPlotProps = DFGPlotProps())
90-
@info "Deprecated, please use GraphsDFG or LightDFG."
91-
nodesize = [has_prop(dfg.g,i,:factor) ? p.nodesize.fac : p.nodesize.var for i=vertices(dfg.g)]
92-
if p.drawlabels
93-
nodelabel = [has_prop(dfg.g,i,:factor) ? "" : string(get_prop(dfg.g,i,:label)) for i=vertices(dfg.g)]
94-
else
95-
nodelabel = nothing
96-
end
97-
nodefillc = [has_prop(dfg.g,i,:factor) ? p.nodefillc.fac : p.nodefillc.var for i=vertices(dfg.g)]
98-
99-
gplot(dfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=p.layout)
100-
101-
end
102-
103-
"""
104-
$(SIGNATURES)
105-
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactoGraphs for these functions to be available.
106-
Returns the plot context.
107-
108-
E.g.
109-
```
110-
using GraphPlot
111-
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
112-
# ... Make graph...
113-
# Using GraphViz plotting
114-
dfgplot(fg)
115-
# Save to PDFG
116-
using Compose
117-
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
118-
```
119-
12086
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
12187
"""
12288
function dfgplot(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
@@ -128,11 +94,6 @@ function dfgplot(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
12894
dfgplot(ldfg, p)
12995
end
13096

131-
function gplot(dfg::DistributedFactorGraphs.MetaGraphsDFG; keyargs...)
132-
@info "Deprecated, please use GraphsDFG or LightDFG."
133-
gplot(dfg.g; keyargs...)
134-
end
135-
13697
function gplot(dfg::LightDFG; keyargs...)
13798
gplot(dfg.g; keyargs...)
13899
end

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ using Reexport
99
using JSON2
1010
using LinearAlgebra
1111
using SparseArrays
12+
# This is used in the definition of getAdjacencyMatrixSparse
13+
using LightGraphs
1214

1315
# Entities
1416
include("entities/AbstractDFG.jl")
@@ -87,9 +89,6 @@ include("GraphsDFG/GraphsDFG.jl")
8789
# Include the FilesDFG API.
8890
include("FileDFG/FileDFG.jl")
8991

90-
# Include the LightGraphs.jl (MetaGraphs.jl) API.
91-
include("MetaGraphsDFG/MetaGraphsDFG.jl")
92-
9392
include("SymbolDFG/SymbolDFG.jl")
9493
using .SymbolDFGs
9594

src/SymbolDFG/services/SymbolDFG.jl

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -459,38 +459,6 @@ function getAdjacencyMatrixSparse(dfg::SymbolDFG; solvable::Int=0)::Tuple{LightG
459459
end
460460
return adjMat, varLabels, factLabels
461461
end
462-
#=
463-
"""
464-
$(SIGNATURES)
465-
Produces a dot-format of the graph for visualization.
466-
"""
467-
function toDot(dfg::SymbolDFG)::String
468-
@error "toDot(dfg::SymbolDFG) is not sopported yet, see https://github.com/JuliaGraphs/MetaGraphs.jl/issues/86"
469-
m = PipeBuffer()
470-
MetaGraphs.savedot(m, dfg.g)
471-
data = take!(m)
472-
close(m)
473-
return String(data)
474-
end
475-
476-
"""
477-
$(SIGNATURES)
478-
Produces a dot file of the graph for visualization.
479-
Download XDot to see the data
480-
481-
Note
482-
- Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
483-
- Can be viewed with the `xdot` system application.
484-
- Based on graphviz.org
485-
"""
486-
function toDotFile(dfg::SymbolDFG, fileName::String="/tmp/dfg.dot")::Nothing
487-
@error "toDotFile(dfg::SymbolDFG,filename) is not sopported yet, see https://github.com/JuliaGraphs/MetaGraphs.jl/issues/86"
488-
open(fileName, "w") do fid
489-
MetaGraphs.savedot(fid, dfg.g)
490-
end
491-
return nothing
492-
end
493-
=#
494462

495463
"""
496464
$(SIGNATURES)

src/attic/MetaGraphsDFG/DFGPlots.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
$(SIGNATURES)
3+
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactoGraphs for these functions to be available.
4+
Returns the plot context.
5+
6+
E.g.
7+
```
8+
using GraphPlot
9+
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
10+
# ... Make graph...
11+
# Using GraphViz plotting
12+
dfgplot(fg)
13+
# Save to PDFG
14+
using Compose
15+
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
16+
```
17+
18+
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
19+
"""
20+
function dfgplot(dfg::DistributedFactorGraphs.MetaGraphsDFG, p::DFGPlotProps = DFGPlotProps())
21+
@info "Deprecated, please use GraphsDFG or LightDFG."
22+
nodesize = [has_prop(dfg.g,i,:factor) ? p.nodesize.fac : p.nodesize.var for i=vertices(dfg.g)]
23+
if p.drawlabels
24+
nodelabel = [has_prop(dfg.g,i,:factor) ? "" : string(get_prop(dfg.g,i,:label)) for i=vertices(dfg.g)]
25+
else
26+
nodelabel = nothing
27+
end
28+
nodefillc = [has_prop(dfg.g,i,:factor) ? p.nodefillc.fac : p.nodefillc.var for i=vertices(dfg.g)]
29+
30+
gplot(dfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=p.layout)
31+
32+
end
33+
34+
function gplot(dfg::DistributedFactorGraphs.MetaGraphsDFG; keyargs...)
35+
@info "Deprecated, please use GraphsDFG or LightDFG."
36+
gplot(dfg.g; keyargs...)
37+
end

src/MetaGraphsDFG/MetaGraphsDFG.jl renamed to src/attic/MetaGraphsDFG/MetaGraphsDFG.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using MetaGraphs
44
# Imports
55
include("entities/MetaGraphsDFG.jl")
66
include("services/MetaGraphsDFG.jl")
7+
include("DFGPlots.jl")
78

89
# Exports
910
# Deprecated -

0 commit comments

Comments
 (0)