Skip to content

Commit 307a65b

Browse files
authored
Merge pull request #481 from JuliaRobotics/develop
2 parents 261d212 + 41236b3 commit 307a65b

25 files changed

+509
-509
lines changed

src/CloudGraphsDFG/LICENSE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright (c) 2017-2020 NavAbility
2+
3+
This CloudGraphDFG Driver is not yet licensed for public use but an open-source license is in the works.
4+
5+
The CloudGraphDFG driver should be considered an optional internal library of the larger DistributedFactorGraphs package. The code is available as part of a cooperative work, but the work is underway to satisfy all prospective license requirements.

src/CloudGraphsDFG/entities/CloudGraphsDFG.jl

Lines changed: 102 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,64 @@ mutable struct CloudGraphsDFG{T <: AbstractParams} <: AbstractDFG{T}
1010
userId::String
1111
robotId::String
1212
sessionId::String
13-
description::String
13+
description::String #TODO Maybe remove description
1414
addHistory::Vector{Symbol}
1515
solverParams::T # Solver parameters
16+
17+
# inner constructor for all constructors in common
18+
function CloudGraphsDFG{T}(neo4jInstance::Neo4jInstance,
19+
userId::String,
20+
robotId::String,
21+
sessionId::String,
22+
description::String,
23+
addHistory::Vector{Symbol},
24+
solverParams::T;
25+
createSessionNodes::Bool=true,
26+
userData::Dict{Symbol, String} = Dict{Symbol, String}(),
27+
robotData::Dict{Symbol, String} = Dict{Symbol, String}(),
28+
sessionData::Dict{Symbol, String} = Dict{Symbol, String}()) where T <: AbstractParams
29+
# Validate the userId, robotId, and sessionId
30+
!isValidLabel(userId) && error("'$userId' is not a valid User ID")
31+
!isValidLabel(robotId) && error("'$robotId' is not a valid Robot ID")
32+
!isValidLabel(sessionId) && error("'$sessionId' is not a valid Session ID")
33+
34+
# neo4jConnection = Neo4j.Connection(host, port=port, user=dbUser, password=dbPassword);
35+
# graph = Neo4j.getgraph(neo4jConnection)
36+
# neo4jInstance = Neo4jInstance(neo4jConnection, graph)
37+
38+
dfg = new{T}(neo4jInstance, userId, robotId, sessionId, description, addHistory, solverParams)
39+
# Create the session if it doesn't already exist
40+
if createSessionNodes
41+
createDfgSessionIfNotExist(dfg)
42+
setUserData!(dfg, userData)
43+
setRobotData!(dfg, robotData)
44+
setSessionData!(dfg, sessionData)
45+
setDescription!(dfg, description)
46+
end
47+
48+
return dfg
49+
end
1650
end
1751

1852
"""
1953
$(SIGNATURES)
20-
Create a new CloudGraphs-based DFG factor graph using a Neo4j.Connection.
54+
Create a new CloudGraphs-based DFG factor graph using a Neo4j.Connection or by specifying the Neo4j connection information
2155
"""
2256
function CloudGraphsDFG{T}(neo4jConnection::Neo4j.Connection,
23-
userId::String,
24-
robotId::String,
25-
sessionId::String,
26-
description::String;
27-
solverParams::T=NoSolverParams(),
28-
createSessionNodes::Bool=true) where T <: AbstractParams
29-
# Validate the userId, robotId, and sessionId
30-
!isValidLabel(userId) && error("'$userId' is not a valid User ID")
31-
!isValidLabel(robotId) && error("'$robotId' is not a valid Robot ID")
32-
!isValidLabel(sessionId) && error("'$sessionId' is not a valid Session ID")
57+
userId::String,
58+
robotId::String,
59+
sessionId::String,
60+
description::String;
61+
solverParams::T=NoSolverParams(),
62+
kwargs...) where T <: AbstractParams
3363

3464
graph = Neo4j.getgraph(neo4jConnection)
3565
neo4jInstance = Neo4jInstance(neo4jConnection, graph)
36-
dfg = CloudGraphsDFG{T}(neo4jInstance, userId, robotId, sessionId, description, Symbol[], solverParams)
37-
# Create the session if it doesn't already exist
38-
createSessionNodes && createDfgSessionIfNotExist(dfg)
39-
return dfg
66+
67+
return CloudGraphsDFG{T}(neo4jInstance, userId, robotId, sessionId, description, Symbol[], solverParams; kwargs...)
68+
4069
end
41-
"""
42-
$(SIGNATURES)
43-
Create a new CloudGraphs-based DFG factor graph by specifying the Neo4j connection information.
44-
"""
70+
4571
function CloudGraphsDFG{T}(host::String,
4672
port::Int,
4773
dbUser::String,
@@ -50,12 +76,64 @@ function CloudGraphsDFG{T}(host::String,
5076
robotId::String,
5177
sessionId::String,
5278
description::String;
53-
solverParams::T=NoSolverParams(),
54-
createSessionNodes::Bool=true) where T <: AbstractParams
55-
neo4jConnection = Neo4j.Connection(host, port=port, user=dbUser, password=dbPassword);
56-
return CloudGraphsDFG{T}(neo4jConnection, userId, robotId, sessionId, description, solverParams=solverParams, createSessionNodes=createSessionNodes)
79+
kwargs...) where T <: AbstractParams
80+
neo4jConnection = Neo4j.Connection(host, port=port, user=dbUser, password=dbPassword)
81+
return CloudGraphsDFG{T}(neo4jConnection, userId, robotId, sessionId, description; kwargs...)
5782
end
5883

84+
# construct using the default settings for localhost
85+
function CloudGraphsDFG(; hostname="localhost",
86+
port=7474,
87+
username="neo4j",
88+
password="test",
89+
userId::String="DefaultUser",
90+
robotId::String="DefaultRobot",
91+
sessionId::String="Session_$(string(uuid4())[1:6])", #TODO randstring(['a':'z';'A':'Z'],1) ipv Session
92+
description::String="CloudGraphsDFG implementation",
93+
solverParams::T=NoSolverParams(),
94+
kwargs...) where T <: AbstractParams
95+
96+
@info "Creating $sessionId"
97+
return CloudGraphsDFG{T}(hostname,
98+
port,
99+
username,
100+
password,
101+
userId,
102+
robotId,
103+
sessionId,
104+
description;
105+
solverParams=solverParams,
106+
kwargs...)
107+
end
108+
109+
function CloudGraphsDFG(description::String,
110+
userId::String,
111+
robotId::String,
112+
sessionId::String,
113+
userData::Dict{Symbol, String},
114+
robotData::Dict{Symbol, String},
115+
sessionData::Dict{Symbol, String},
116+
solverParams::AbstractParams;
117+
host::String = "localhost",
118+
port::Int = 7474,
119+
dbUser::String = "neo4j",
120+
dbPassword::String = "test")
121+
122+
return CloudGraphsDFG{typeof(solverParams)}(host,
123+
port,
124+
dbUser,
125+
dbPassword,
126+
userId,
127+
robotId,
128+
sessionId,
129+
description;
130+
solverParams=solverParams,
131+
userData=userData,
132+
robotData=robotData,
133+
sessionData=sessionData)
134+
135+
136+
end
59137

60138
function show(io::IO, ::MIME"text/plain", c::CloudGraphsDFG)
61139
println(io, "CloudGraphsDFG:")

src/Common.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11

2-
import Base: *
3-
4-
5-
# FIXME remove! is it really needed? This is type piracy
6-
*(a::Symbol, b::AbstractString)::Symbol = Symbol(string(a,b))
7-
82
## Utility functions for getting type names and modules (from IncrementalInference)
93
function _getmodule(t::T) where T
104
T.name.module
@@ -69,7 +63,7 @@ sortDFG(vars::Vector{Symbol}; lt=natural_lt, kwargs...)::Vector{Symbol} = sort(v
6963
## Validation of session, robot, and user IDs.
7064
##==============================================================================
7165

72-
global _invalidIds = ["USER", "ROBOT", "SESSION", "VARIABLE", "FACTOR", "ENVIRONMENT", "PPE", "BIGDATA"]
66+
global _invalidIds = ["USER", "ROBOT", "SESSION", "VARIABLE", "FACTOR", "ENVIRONMENT", "PPE", "BIGDATA", "FACTORGRAPH"]
7367
global _validLabelRegex = r"^[a-zA-Z]\w*$"
7468

7569
"""

src/DFGPlots/DFGPlots.jl

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -97,43 +97,50 @@ function gplot(dfg::LightDFG; keyargs...)
9797
end
9898

9999

100-
function Base.show(io::IO, ::MIME"application/prs.juno.plotpane+html", dfg::AbstractDFG)
101-
size = get(io, :juno_plotsize, [100, 100])
102-
103-
plot_output = IOBuffer()
104-
draw(SVGJS(plot_output, GraphPlot.Compose.default_graphic_width,
105-
GraphPlot.Compose.default_graphic_width, false), dfgplot(dfg))
106-
plotsvg = String(take!(plot_output))
107-
108-
print(io,
109-
"""
110-
<div style="
111-
background-color: #eee;
112-
color: #222;
113-
width: $(size[1]-40)px;
114-
height: $(size[2]-40)px;
115-
position: absolute;
116-
top: 0;
117-
left: 0;
118-
padding: 20px;
119-
margin: 0;
120-
">
121-
$(typeof(dfg))
122-
<ul>
123-
<li>$(dfg.userId)</li>
124-
<li>$(dfg.robotId)</li>
125-
<li>$(dfg.sessionId)</li>
126-
<li>$(dfg.description)</li>
127-
</ul>
128-
<script charset="utf-8">
129-
$(read(Compose.snapsvgjs, String))
130-
</script>
131-
<script charset="utf-8">
132-
$(read(GraphPlot.gadflyjs, String))
133-
</script>
134-
$(plotsvg)
135-
</div>
136-
""")
100+
#TODO decide if we want to overload show for display in juno, It's a bit annoying with development
101+
# function Base.show(io::IO, ::MIME"application/prs.juno.plotpane+html", dfg::AbstractDFG)
102+
function dfgplot(io::IO, ::MIME"application/prs.juno.plotpane+html", dfg::AbstractDFG)
103+
104+
if length(ls(dfg)) != 0
105+
size = get(io, :juno_plotsize, [100, 100])
106+
107+
plot_output = IOBuffer()
108+
GraphPlot.draw(GraphPlot.SVGJS(plot_output, GraphPlot.Compose.default_graphic_width,
109+
GraphPlot.Compose.default_graphic_width, false), dfgplot(dfg))
110+
plotsvg = String(take!(plot_output))
111+
112+
print(io,
113+
"""
114+
<div style="
115+
background-color: #eee;
116+
color: #222;
117+
width: $(size[1]-40)px;
118+
height: $(size[2]-40)px;
119+
position: absolute;
120+
top: 0;
121+
left: 0;
122+
padding: 20px;
123+
margin: 0;
124+
">
125+
$(typeof(dfg))
126+
<ul>
127+
<li>$(dfg.userId)</li>
128+
<li>$(dfg.robotId)</li>
129+
<li>$(dfg.sessionId)</li>
130+
<li>$(dfg.description)</li>
131+
</ul>
132+
<script charset="utf-8">
133+
$(read(GraphPlot.Compose.snapsvgjs, String))
134+
</script>
135+
<script charset="utf-8">
136+
$(read(GraphPlot.gadflyjs, String))
137+
</script>
138+
$(plotsvg)
139+
</div>
140+
""")
141+
else
142+
Base.show(io, dfg)
143+
end
137144

138145
end
139146

src/Deprecated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include("../attic/GraphsDFG/GraphsDFG.jl")
2020
export buildSubgraphFromLabels!
2121
function buildSubgraphFromLabels!(dfg::AbstractDFG,
2222
syms::Vector{Symbol};
23-
subfg::AbstractDFG=LightDFG(params=getSolverParams(dfg)),
23+
subfg::AbstractDFG=LightDFG(solverParams=getSolverParams(dfg)),
2424
solvable::Int=0,
2525
allowedFactors::Union{Nothing, Vector{Symbol}}=nothing )
2626
error("""buildSubgraphFromLabels! is deprecated

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export isValidLabel
198198

199199
## List
200200
export ls, lsf, ls2
201-
export lsTypes, lsfTypes
201+
export lsTypes, lsfTypes, lsTypesDict, lsfTypesDict
202202
export lsWho, lsfWho
203203
export isPrior, lsfPriors
204204
export hasTags, hasTagsNeighbors

src/FileDFG/services/FileDFG.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,26 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::String)
127127
varFiles = readdir(varFolder)
128128
factorFiles = readdir(factorFolder)
129129
for varFile in varFiles
130-
io = open("$varFolder/$varFile")
131-
packedData = JSON2.read(io, Dict{String, Any})
132-
push!(variables, unpackVariable(dfgLoadInto, packedData))
130+
open("$varFolder/$varFile") do io
131+
packedData = JSON2.read(io, Dict{String, Any})
132+
push!(variables, unpackVariable(dfgLoadInto, packedData))
133+
end
133134
end
134135
@info "Loaded $(length(variables)) variables - $(map(v->v.label, variables))"
135136
@info "Inserting variables into graph..."
136137
# Adding variables
137138
map(v->addVariable!(dfgLoadInto, v), variables)
138139

139140
for factorFile in factorFiles
140-
io = open("$factorFolder/$factorFile")
141-
packedData = JSON2.read(io, Dict{String, Any})
142-
push!(factors, unpackFactor(dfgLoadInto, packedData))
141+
open("$factorFolder/$factorFile") do io
142+
packedData = JSON2.read(io, Dict{String, Any})
143+
push!(factors, unpackFactor(dfgLoadInto, packedData))
144+
end
143145
end
144146
@info "Loaded $(length(variables)) factors - $(map(f->f.label, factors))"
145147
@info "Inserting factors into graph..."
146148
# # Adding factors
147-
map(f->addFactor!(dfgLoadInto, f._variableOrderSymbols, f), factors)
149+
map(f->addFactor!(dfgLoadInto, f), factors)
148150

149151
# Finally, rebuild the CCW's for the factors to completely reinflate them
150152
@info "Rebuilding CCW's for the factors..."

src/LightDFG/entities/LightDFG.jl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ function LightDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
3636
userData::Dict{Symbol, String} = Dict{Symbol, String}(),
3737
robotData::Dict{Symbol, String} = Dict{Symbol, String}(),
3838
sessionData::Dict{Symbol, String} = Dict{Symbol, String}(),
39-
params::T=T()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
39+
solverParams::T=T()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
4040
# Validate the userId, robotId, and sessionId
4141
!isValidLabel(userId) && error("'$userId' is not a valid User ID")
4242
!isValidLabel(robotId) && error("'$robotId' is not a valid Robot ID")
4343
!isValidLabel(sessionId) && error("'$sessionId' is not a valid Session ID")
44-
return LightDFG{T,V,F}(g, description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], params)
44+
return LightDFG{T,V,F}(g, description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], solverParams)
4545
end
4646

4747
# LightDFG{T}(; kwargs...) where T <: AbstractParams = LightDFG{T,DFGVariable,DFGFactor}(;kwargs...)
48+
4849
"""
4950
$(SIGNATURES)
5051
@@ -53,11 +54,27 @@ Create an in-memory LightDFG with the following parameters:
5354
- V: Variable type
5455
- F: Factor type
5556
"""
56-
LightDFG{T}(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); kwargs...) where T <: AbstractParams =
57-
LightDFG{T,DFGVariable,DFGFactor}(g; kwargs...)
57+
function LightDFG{T}(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}();
58+
params=nothing,
59+
kwargs...) where T <: AbstractParams
60+
61+
#TODO remove params deprecation error in v0.9
62+
if params != nothing
63+
@warn "keyword `params` is deprecated, please use solverParams"
64+
return LightDFG{T,DFGVariable,DFGFactor}(g; solverParams = params, kwargs...)
65+
end
66+
return LightDFG{T,DFGVariable,DFGFactor}(g; kwargs...)
67+
end
5868

59-
LightDFG(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); params::T=NoSolverParams(), kwargs...) where T =
60-
LightDFG{T,DFGVariable,DFGFactor}(g; params=params, kwargs...)
69+
function LightDFG(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}();
70+
solverParams::T=NoSolverParams(), params=nothing, kwargs...) where T
71+
#TODO remove params deprecation error in v0.9
72+
if params != nothing
73+
@warn "keyword `params` is deprecated, please use solverParams"
74+
return LightDFG{typeof(params),DFGVariable,DFGFactor}(g; solverParams=params, kwargs...)
75+
end
76+
return LightDFG{T,DFGVariable,DFGFactor}(g; solverParams=solverParams, kwargs...)
77+
end
6178

6279

6380
LightDFG(description::String,

src/LightDFG/services/LightDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ Gets an empty and unique LightDFG derived from an existing DFG.
318318
function _getDuplicatedEmptyDFG(dfg::LightDFG{P,V,F})::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
319319
newDfg = LightDFG{P,V,F}(;
320320
userId=dfg.userId, robotId=dfg.robotId, sessionId=dfg.sessionId,
321-
params=deepcopy(dfg.solverParams))
321+
solverParams=deepcopy(dfg.solverParams))
322322
newDfg.description ="(Copy of) $(dfg.description)"
323323
return newDfg
324324
end

0 commit comments

Comments
 (0)