Skip to content

Commit 5ef922a

Browse files
committed
Merge branch feature/IIFTests_cgdfg into jt/develop_merge without tests
2 parents 8838526 + b110db9 commit 5ef922a

File tree

10 files changed

+312
-75
lines changed

10 files changed

+312
-75
lines changed

.travis.yml

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

35
sudo: required
46
dist: trusty
@@ -23,21 +25,10 @@ matrix:
2325
allow_failures:
2426
- julia: nightly
2527

28+
# Set the password for Neo4j to neo4j:test
2629
before_script:
2730
- sleep 10
2831
- curl -v POST http://neo4j:neo4j@localhost:7474/user/neo4j/password -d"password=test"
29-
# script:
30-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
31-
# - julia --project --check-bounds=yes -e 'using UUIDs; write("Project.toml", replace(read("Project.toml", String), r"uuid = .*?\n" =>"uuid = \"$(uuid4())\"\n"));
32-
# import Pkg; Pkg.build("DistributedFactorGraphs"); Pkg.test("DistributedFactorGraphs"; coverage=true)'
33-
34-
# script:
35-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
36-
# - julia --check-bounds=yes -e 'using Pkg; Pkg.clone(pwd()); Pkg.build("DistributedFactorGraphs"); Pkg.test("DistributedFactorGraphs"; coverage=true)'
37-
38-
# can be used if master of package is required
39-
# script:
40-
# - julia --project --color=yes --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(name="MetaGraphs", rev="master")); Pkg.build(); Pkg.test(coverage=true)'
4132

4233
after_success:
4334
- julia -e 'using Pkg; cd(Pkg.dir("DistributedFactorGraphs")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder()); Coveralls.submit(process_folder())'
@@ -53,3 +44,10 @@ jobs:
5344
Pkg.instantiate()'
5445
- julia --project=docs/ docs/make.jl
5546
after_success: skip
47+
48+
- stage: "IIF Driver Tests"
49+
julia: 1.2
50+
os: linux
51+
script:
52+
- julia -e 'import Pkg; Pkg.add("IncrementalInference"); Pkg.test("DistributedFactorGraphs")'
53+
after_success: skip

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@ 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"
3533

3634
[targets]
37-
test = ["Test", "GraphPlot", "Neo4j", "IncrementalInference"]
35+
test = ["Test", "GraphPlot", "Neo4j"]

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/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.type != b.type && @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

test/Project.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[deps]
2+
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
3+
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
4+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
5+
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
6+
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
7+
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
8+
IncrementalInference = "904591bb-b899-562f-9e6f-b8df64c7d480"
9+
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
10+
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
11+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
12+
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
13+
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
14+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
15+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
16+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
17+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
18+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/obsolete_nowinRoME/cloudGraphsDFGTests.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
## Sandboxing for CloudgraphsDFG
2-
3-
## Requires local Neo4j with user/pass neo4j:test
4-
# To run the Docker image
5-
# Install: docker pull neo4j
6-
# Run: sudo docker run --publish=7474:7474 --publish=7687:7687 --env NEO4J_AUTH=neo4j/test neo4j
7-
82
using Revise
93
using Neo4j
104
using DistributedFactorGraphs

test/runtests.jl

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ using Test
22
using GraphPlot # For plotting tests
33
using Neo4j
44
using DistributedFactorGraphs
5-
using IncrementalInference
5+
using Pkg
6+
7+
## To run the IIF tests, you need a local Neo4j with user/pass neo4j:test
8+
# To run a Docker image
9+
# Install: docker pull neo4j
10+
# Run: docker run --publish=7474:7474 --publish=7687:7687 --env NEO4J_AUTH=neo4j/test neo4j
11+
##
612

713
# Instantiate the APIs that you would like to test here
814
# Can do duplicates with different parameters.
@@ -48,6 +54,43 @@ end
4854
@test_throws UndefVarError MetaGraphsDFG{NoSolverParams}()
4955
end
5056

57+
if haskey(Pkg.installed(), "IncrementalInference")
58+
@info "------------------------------------------------------------------------"
59+
@info "These tests are using IncrementalInference to do additional driver tests"
60+
@info "------------------------------------------------------------------------"
61+
62+
using IncrementalInference
63+
64+
apis = [
65+
# GraphsDFG{NoSolverParams}(),
66+
# LightDFG{NoSolverParams}(),
67+
# MetaGraphsDFG{NoSolverParams}(),
68+
# SymbolDFG{NoSolverParams}(),
69+
CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
70+
"testUser", "testRobot", "testSession",
71+
nothing,
72+
nothing,
73+
IncrementalInference.decodePackedType,
74+
IncrementalInference.rebuildFactorMetadata!,
75+
solverParams=SolverParams())
76+
]
77+
for api in apis
78+
@testset "Testing Driver: $(typeof(api))" begin
79+
@info "Testing Driver: $(api)"
80+
global dfg = deepcopy(api)
81+
include("iifInterfaceTests.jl")
82+
end
83+
end
84+
else
85+
@warn "Skipping IncrementalInference driver tests"
86+
end
87+
88+
Test that we don't export LightDFG and MetaGraphsDFG
89+
@testset "Deprecated Drivers Test" begin
90+
@test_throws UndefVarError SymbolDFG{NoSolverParams}()
91+
@test_throws UndefVarError MetaGraphsDFG{NoSolverParams}()
92+
end
93+
5194
# Test special cases
5295

5396
@testset "Plotting Tests" begin

0 commit comments

Comments
 (0)