Skip to content

Commit 9c26b3f

Browse files
committed
Bringing up to date
2 parents df881f6 + 266f80b commit 9c26b3f

File tree

18 files changed

+128
-223
lines changed

18 files changed

+128
-223
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: 31 additions & 126 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))
@@ -595,8 +509,18 @@ Retrieve a list of labels of the immediate neighbors around a given variable or
595509
"""
596510
function getNeighbors(dfg::CloudGraphsDFG, node::T; ready::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
597511
query = "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))--(node) where (node:VARIABLE or node:FACTOR) "
512+
<<<<<<< HEAD
598513
if ready != nothing
599514
query = query * " and node.ready >= $(ready)"
515+
=======
516+
if ready != nothing || backendset != nothing
517+
if ready != nothing
518+
query = query * " and node.solvable >= $(ready)"
519+
end
520+
if backendset != nothing
521+
query = query * " and node.solveInProgress = $(backendset)"
522+
end
523+
>>>>>>> 266f80b3a71e8a4f8749fe34d74613606141b7eb
600524
end
601525
@debug "[Query] $query"
602526
neighbors = _getLabelsFromCyphonQuery(dfg.neo4jInstance, query)
@@ -613,8 +537,18 @@ Retrieve a list of labels of the immediate neighbors around a given variable or
613537
"""
614538
function getNeighbors(dfg::CloudGraphsDFG, label::Symbol; ready::Union{Nothing, Int}=nothing)::Vector{Symbol}
615539
query = "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(label))--(node) where (node:VARIABLE or node:FACTOR) "
540+
<<<<<<< HEAD
616541
if ready != nothing
617542
query = query * " and node.ready >= $(ready)"
543+
=======
544+
if ready != nothing || backendset != nothing
545+
if ready != nothing
546+
query = query * " and node.solvable >= $(ready)"
547+
end
548+
if backendset != nothing
549+
query = query * " and node.solveInProgress = $(backendset)"
550+
end
551+
>>>>>>> 266f80b3a71e8a4f8749fe34d74613606141b7eb
618552
end
619553
@debug "[Query] $query"
620554
neighbors = _getLabelsFromCyphonQuery(dfg.neo4jInstance, query)
@@ -653,12 +587,12 @@ Optionally provide a distance to specify the number of edges should be followed.
653587
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
654588
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.
655589
"""
656-
function getSubgraphAroundNode(dfg::CloudGraphsDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg))::AbstractDFG
590+
function getSubgraphAroundNode(dfg::CloudGraphsDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg); solvable::Int=0)::AbstractDFG
657591
distance < 1 && error("getSubgraphAroundNode() only works for distance > 0")
658592

659593
# Thank you Neo4j for 0..* awesomeness!!
660594
neighborList = _getLabelsFromCyphonQuery(dfg.neo4jInstance,
661-
"(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))-[FACTORGRAPH*0..$distance]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId)) WHERE (n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR) and not (node:SESSION)")
595+
"(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))-[FACTORGRAPH*0..$distance]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId)) WHERE (n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR) and not (node:SESSION) and (node.solvable >= $solvable)")
662596

663597
# Copy the section of graph we want
664598
_copyIntoGraph!(dfg, addToDFG, neighborList, includeOrphanFactors)
@@ -746,32 +680,3 @@ function getAdjacencyMatrixSparse(dfg::CloudGraphsDFG)::Tuple{SparseMatrixCSC, V
746680

747681
return adjMat, varLabels, factLabels
748682
end
749-
750-
# """
751-
# $(SIGNATURES)
752-
# Produces a dot-format of the graph for visualization.
753-
# """
754-
# function toDot(dfg::CloudGraphsDFG)::String
755-
# m = PipeBuffer()
756-
# write(m,Graphs.to_dot(dfg.g))
757-
# data = take!(m)
758-
# close(m)
759-
# return String(data)
760-
# end
761-
#
762-
# """
763-
# $(SIGNATURES)
764-
# Produces a dot file of the graph for visualization.
765-
# Download XDot to see the data
766-
#
767-
# Note
768-
# - Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
769-
# - Can be viewed with the `xdot` system application.
770-
# - Based on graphviz.org
771-
# """
772-
# function toDotFile(dfg::CloudGraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
773-
# open(fileName, "w") do fid
774-
# write(fid,Graphs.to_dot(dfg.g))
775-
# end
776-
# return nothing
777-
# 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: 3 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")
@@ -21,6 +23,7 @@ export AbstractParams, NoSolverParams
2123
export DFGNode, DFGVariable, DFGFactor, AbstractDFGVariable, AbstractDFGFactor
2224
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
2325
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
26+
export getMaxPPE, getMeanPPE, getSuggestedPPE
2427
export label, timestamp, tags, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
2528
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
2629

@@ -86,9 +89,6 @@ include("GraphsDFG/GraphsDFG.jl")
8689
# Include the FilesDFG API.
8790
include("FileDFG/FileDFG.jl")
8891

89-
# Include the LightGraphs.jl (MetaGraphs.jl) API.
90-
include("MetaGraphsDFG/MetaGraphsDFG.jl")
91-
9292
include("SymbolDFG/SymbolDFG.jl")
9393
using .SymbolDFGs
9494

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ Optionally provide a distance to specify the number of edges should be followed.
327327
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
328328
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.
329329
"""
330-
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}())::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
330+
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}(); solvable::Int=0)::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
331331
if !haskey(dfg.labelDict, node.label)
332332
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
333333
end
@@ -341,7 +341,7 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
341341
for (key, node) in curList
342342
neighbors = in_neighbors(node, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
343343
for neighbor in neighbors
344-
if !haskey(neighborList, neighbor.dfgNode.label)
344+
if !haskey(neighborList, neighbor.dfgNode.label) && (isSolvable(neighbor.dfgNode) >= solvable)
345345
push!(neighborList, neighbor.dfgNode.label => neighbor)
346346
push!(newNeighbors, neighbor.dfgNode.label => neighbor)
347347
end

src/LightDFG/services/LightDFG.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,13 +384,15 @@ Optionally provide a distance to specify the number of edges should be followed.
384384
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
385385
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.
386386
"""
387-
function getSubgraphAroundNode(dfg::LightDFG{P,V,F}, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}())::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
387+
function getSubgraphAroundNode(dfg::LightDFG{P,V,F}, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}(); solvable::Int=0)::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
388388
if !exists(dfg,node.label)
389389
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
390390
end
391391

392392
# Get a list of all unique neighbors inside 'distance'
393393
ns = neighborhood(dfg.g, dfg.g.labels[node.label], distance)
394+
# Always return the center node, skip that if we're filtering.
395+
solvable != 0 && (filter!(id -> _isSolvable(dfg, dfg.g.labels[id], solvable) || dfg.g.labels[id] == node.label, ns))
394396

395397
# Copy the section of graph we want
396398
_copyIntoGraph!(dfg, addToDFG, ns, includeOrphanFactors)

0 commit comments

Comments
 (0)