Skip to content

Commit 6f740d1

Browse files
committed
Merge branch 'master' into feature/149_DFGVariableSofttype
2 parents dcd97da + 10ab05b commit 6f740d1

File tree

13 files changed

+354
-138
lines changed

13 files changed

+354
-138
lines changed

.travis.yml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
language: julia
2+
sudo: required
3+
dist: trusty
24

35
os:
46
- linux
@@ -13,37 +15,35 @@ julia:
1315
- 1.3
1416
- nightly
1517

16-
notifications:
17-
email: false
18-
19-
matrix:
20-
allow_failures:
21-
- julia: nightly
22-
23-
# script:
24-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
25-
# - julia --project --check-bounds=yes -e 'using UUIDs; write("Project.toml", replace(read("Project.toml", String), r"uuid = .*?\n" =>"uuid = \"$(uuid4())\"\n"));
26-
# import Pkg; Pkg.build("DistributedFactorGraphs"); Pkg.test("DistributedFactorGraphs"; coverage=true)'
27-
28-
# script:
29-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
30-
# - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("DistributedFactorGraphs"); Pkg.test("DistributedFactorGraphs"; coverage=true)'
31-
32-
# can be used if master of package is required
33-
# script:
34-
# - julia --project --color=yes --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(name="MetaGraphs", rev="master")); Pkg.build(); Pkg.test(coverage=true)'
35-
36-
after_success:
37-
- julia -e 'using Pkg; cd(Pkg.dir("DistributedFactorGraphs")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder()); Coveralls.submit(process_folder())'
18+
env:
19+
- IIF_TEST=false
3820

3921
jobs:
4022
include:
23+
- julia: 1.2
24+
env: IIF_TEST=true
4125
- stage: "Documentation"
4226
julia: 1.0
4327
os: linux
4428
script:
45-
- julia -e 'import Pkg; Pkg.add("Documenter"); Pkg.add("DataFrames")'
29+
- julia -e 'import Pkg; Pkg.add("Documenter"); Pkg.add("Neo4j"); Pkg.add("GraphPlot")'
4630
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));
4731
Pkg.instantiate()'
4832
- julia --project=docs/ docs/make.jl
4933
after_success: skip
34+
35+
notifications:
36+
email: false
37+
38+
matrix:
39+
allow_failures:
40+
- julia: nightly
41+
- env: IIF_TEST=true
42+
43+
# Set the password for Neo4j to neo4j:test
44+
before_script:
45+
- sleep 10
46+
- curl -v POST http://neo4j:neo4j@localhost:7474/user/neo4j/password -d"password=test"
47+
48+
after_success:
49+
- julia -e 'using Pkg; cd(Pkg.dir("DistributedFactorGraphs")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder()); Coveralls.submit(process_folder())'

Project.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ MetaGraphs = "≥ 0.6.4"
2525
Reexport = "≥ 0.2"
2626
Requires = "≥ 0.5"
2727
julia = "0.7, 1"
28-
IncrementalInference = "0.7.7"
2928

3029
[extras]
3130
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3231
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
3332
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
34-
IncrementalInference = "904591bb-b899-562f-9e6f-b8df64c7d480"
33+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
3534

3635
[targets]
37-
test = ["Test", "GraphPlot", "Neo4j", "IncrementalInference"]
36+
test = ["Test", "GraphPlot", "Neo4j", "Pkg"]

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ function setSolverParams(dfg::CloudGraphsDFG, solverParams::T)::T where T <: Abs
6767
return dfg.solverParams = solverParams
6868
end
6969

70+
function getSerializationModule(dfg::CloudGraphsDFG)::Module where G <: AbstractDFG
71+
# TODO: If we need to specialize this for RoME etc, here is where we'll change it.
72+
return Main
73+
end
74+
7075
"""
7176
$(SIGNATURES)
7277
True if the variable or factor exists in the graph.
@@ -627,15 +632,19 @@ function isFullyConnected(dfg::CloudGraphsDFG)::Bool
627632
# Total nodes
628633
varIds = getVariableIds(dfg)
629634
factIds = getFactorIds(dfg)
630-
totalNodes = length(varIds) + length(factIds)
631-
if length(varIds) == 0
632-
return false
633-
end
635+
length(varIds) + length(factIds) == 0 && return false
634636

635637
# Total connected nodes - thank you Neo4j for 0..* awesomeness!!
636-
connectedList = _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(varIds[1]))-[FACTORGRAPH*]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))")
637-
638-
return length(connectedList) == totalNodes
638+
query = """
639+
match (n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(varIds[1]))-[FACTORGRAPH*]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))
640+
WHERE n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR
641+
WITH collect(n)+collect(node) as nodelist
642+
unwind nodelist as nodes
643+
return count(distinct nodes)"""
644+
@debug "[Querying] $query"
645+
result = _queryNeo4j(dfg.neo4jInstance, query)
646+
# Neo4j.jl data structure sometimes feels brittle... like below
647+
return result.results[1]["data"][1]["row"][1] == length(varIds) + length(factIds)
639648
end
640649

641650
#Alias

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
alphaOnlyMatchRegex = r"^[a-zA-Z0-9_]*$"
22

3+
"""
4+
$(SIGNATURES)
5+
Returns the transaction for a given query.
6+
NOTE: Must commit(transaction) after you're done.
7+
"""
8+
function _queryNeo4j(neo4jInstance::Neo4jInstance, query::String)
9+
loadtx = transaction(neo4jInstance.connection)
10+
result = loadtx(query; submit=true)
11+
if length(result.errors) > 0
12+
error(string(result.errors))
13+
end
14+
# Have to finish the transaction
15+
commit(loadtx)
16+
return result
17+
end
18+
319
"""
420
$(SIGNATURES)
521
Returns the list of CloudGraph nodes that matches the Cyphon query.
@@ -11,16 +27,9 @@ If orderProperty is not ==, then 'order by n.{orderProperty} will be appended to
1127
So can make orderProperty = label or id.
1228
"""
1329
function _getLabelsFromCyphonQuery(neo4jInstance::Neo4jInstance, matchCondition::String, orderProperty::String="")::Vector{Symbol}
14-
# 2. Perform the transaction
15-
loadtx = transaction(neo4jInstance.connection)
1630
query = "match $matchCondition return distinct(node.label) $(orderProperty != "" ? "order by node.$orderProperty" : "")";
17-
nodes = loadtx(query; submit=true)
18-
if length(nodes.errors) > 0
19-
error(string(nodes.errors))
20-
end
21-
nodeIds = map(node -> node["row"][1], nodes.results[1]["data"])
22-
# Have to finish the transaction
23-
commit(loadtx)
31+
result = _queryNeo4j(neo4jInstance, query)
32+
nodeIds = map(node -> node["row"][1], result.results[1]["data"])
2433
return Symbol.(nodeIds)
2534
end
2635

src/LightDFG/services/LightDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ end
257257
Checks if the graph is fully connected, returns true if so.
258258
"""
259259
function isFullyConnected(dfg::LightDFG)::Bool
260-
return length(connected_components(dfg.g)) == 1
260+
return length(LightGraphs.connected_components(dfg.g)) == 1
261261
end
262262

263263
function _isready(dfg::LightDFG, label::Symbol, ready::Int)::Bool

src/SymbolDFG/services/SymbolDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ end
264264
Checks if the graph is fully connected, returns true if so.
265265
"""
266266
function isFullyConnected(dfg::SymbolDFG)::Bool
267-
return length(connected_components(dfg.g)) == 1
267+
return length(LightGraphs.connected_components(dfg.g)) == 1
268268
end
269269

270270
#Alias

src/services/AbstractDFG.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ showFactor(fgl::G, fsym::Symbol) where G <: AbstractDFG = @show getFactor(fgl,fs
569569
Produces a dot-format of the graph for visualization.
570570
"""
571571
function toDot(dfg::AbstractDFG)::String
572-
@warn "Falling Back to convert to GraphsDFG"
573572
#TODO implement convert
574573
graphsdfg = GraphsDFG{AbstractParams}()
575574
DistributedFactorGraphs._copyIntoGraph!(dfg, graphsdfg, union(getVariableIds(dfg), getFactorIds(dfg)), true)
@@ -589,7 +588,6 @@ Note
589588
- Based on graphviz.org
590589
"""
591590
function toDotFile(dfg::AbstractDFG, fileName::String="/tmp/dfg.dot")::Nothing
592-
@warn "Falling Back to convert to GraphsDFG"
593591
#TODO implement convert
594592
graphsdfg = GraphsDFG{AbstractParams}()
595593
DistributedFactorGraphs._copyIntoGraph!(dfg, graphsdfg, union(getVariableIds(dfg), getFactorIds(dfg)), true)

src/services/DFGVariable.jl

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,80 @@ function unpack(dfg::G, d::PackedVariableNodeData)::VariableNodeData where G <:
7777
end
7878
@debug "Net conversion result: $st"
7979

80+
if st == nothing
81+
error("The variable doesn't seem to have a softtype. It needs to set up with an InferenceVariable from IIF. This will happen if you use DFG to add serialized variables directly and try use them. Please use IncrementalInference.addVariable().")
82+
end
83+
8084
return VariableNodeData(M3,M4, d.BayesNetOutVertIDs,
8185
d.dimIDs, d.dims, d.eliminated, d.BayesNetVertID, d.separator,
8286
st, d.initialized, d.inferdim, d.ismargin, d.dontmargin )
8387
end
8488

8589
function compare(a::VariableNodeData, b::VariableNodeData)
86-
TP = true
87-
TP = TP && a.val == b.val
88-
TP = TP && a.bw == b.bw
89-
TP = TP && a.BayesNetOutVertIDs == b.BayesNetOutVertIDs
90-
TP = TP && a.dimIDs == b.dimIDs
91-
TP = TP && a.dims == b.dims
92-
TP = TP && a.eliminated == b.eliminated
93-
TP = TP && a.BayesNetVertID == b.BayesNetVertID
94-
TP = TP && a.separator == b.separator
95-
TP = TP && abs(a.inferdim - b.inferdim) < 1e-14
96-
TP = TP && a.ismargin == b.ismargin
97-
TP = TP && a.softtype == b.softtype
98-
return TP
90+
a.val != b.val && @debug("val is not equal")==nothing && return false
91+
a.bw != b.bw && @debug("bw is not equal")==nothing && return false
92+
a.BayesNetOutVertIDs != b.BayesNetOutVertIDs && @debug("BayesNetOutVertIDs is not equal")==nothing && return false
93+
a.dimIDs != b.dimIDs && @debug("dimIDs is not equal")==nothing && return false
94+
a.dims != b.dims && @debug("dims is not equal")==nothing && return false
95+
a.eliminated != b.eliminated && @debug("eliminated is not equal")==nothing && return false
96+
a.BayesNetVertID != b.BayesNetVertID && @debug("BayesNetVertID is not equal")==nothing && return false
97+
a.separator != b.separator && @debug("separator is not equal")==nothing && return false
98+
a.initialized != b.initialized && @debug("initialized is not equal")==nothing && return false
99+
abs(a.inferdim - b.inferdim) > 1e-14 && @debug("inferdim is not equal")==nothing && return false
100+
a.ismargin != b.ismargin && @debug("ismargin is not equal")==nothing && return false
101+
a.dontmargin != b.dontmargin && @debug("dontmargin is not equal")==nothing && return false
102+
typeof(a.softtype) != typeof(b.softtype) && @debug("softtype is not equal")==nothing && return false
103+
return true
99104
end
100105

106+
"""
107+
$(SIGNATURES)
108+
Equality check for VariableNodeData.
109+
"""
101110
function ==(a::VariableNodeData,b::VariableNodeData, nt::Symbol=:var)
102111
return DistributedFactorGraphs.compare(a,b)
103112
end
104113

114+
"""
115+
$(SIGNATURES)
116+
Equality check for VariableEstimate.
117+
"""
118+
function ==(a::VariableEstimate, b::VariableEstimate)::Bool
119+
a.solverKey != b.solverKey && @debug("solverKey are not equal")==nothing && return false
120+
a.ppeType != b.ppeType && @debug("type is not equal")==nothing && return false
121+
a.estimate != b.estimate && @debug("estimate are not equal")==nothing && return false
122+
a.lastUpdatedTimestamp != b.lastUpdatedTimestamp && @debug("lastUpdatedTimestamp is not equal")==nothing && return false
123+
return true
124+
end
125+
126+
"""
127+
$(SIGNATURES)
128+
Equality check for DFGVariable.
129+
"""
130+
function ==(a::DFGVariable, b::DFGVariable)::Bool
131+
a.label != b.label && @debug("label is not equal")==nothing && return false
132+
a.timestamp != b.timestamp && @debug("timestamp is not equal")==nothing && return false
133+
a.tags != b.tags && @debug("tags is not equal")==nothing && return false
134+
symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && @debug("estimateDict keys are not equal")==nothing && return false
135+
for k in keys(a.estimateDict)
136+
a.estimateDict[k] != b.estimateDict[k] && @debug("estimateDict[$k] is not equal")==nothing && return false
137+
end
138+
symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != Set(Symbol[]) && @debug("solverDataDict keys are not equal")==nothing && return false
139+
for k in keys(a.solverDataDict)
140+
a.solverDataDict[k] != b.solverDataDict[k] && @debug("solverDataDict[$k] is not equal")==nothing && return false
141+
end
142+
a.smallData != b.smallData && @debug("smallData is not equal")==nothing && return false
143+
a.bigData != b.bigData && @debug("bigData is not equal")==nothing && return false
144+
a.ready != b.ready && @debug("ready is not equal")==nothing && return false
145+
a.backendset != b.backendset && @debug("backendset is not equal")==nothing && return false
146+
a._internalId != b._internalId && @debug("_internalId is not equal")==nothing && return false
147+
return true
148+
end
149+
150+
"""
151+
$(SIGNATURES)
152+
Convert a DFGVariable to a DFGVariableSummary.
153+
"""
105154
function convert(::Type{DFGVariableSummary}, v::DFGVariable)
106155
return DFGVariableSummary(v.label, v.timestamp, deepcopy(v.tags), deepcopy(v.estimateDict), Symbol(typeof(getSofttype(v))), v._internalId)
107156
end

0 commit comments

Comments
 (0)