-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfileDFGTests.jl
177 lines (156 loc) · 5.5 KB
/
fileDFGTests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using DistributedFactorGraphs
using IncrementalInference
using Test
using TimeZones
using UUIDs
##
@testset "FileDFG Tests" begin
for filename in ["/tmp/fileDFG", "/tmp/FileDFGExtension.tar.gz"]
global dfg
dfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
# Same graph as iifInterfaceTests.jl
numNodes = 5
# Arranging some random data
verts = map(
n -> addVariable!(dfg, Symbol("x$n"), ContinuousScalar; tags = [:POSE]),
1:numNodes,
)
map(v -> setSolvable!(v, Int(round(rand()))), verts)
map(v -> getSolverData(verts[4]).solveInProgress = Int(round(rand())), verts)
map(v -> setSolvedCount!(v, Int(round(10 * rand()))), verts)
# Add some data entries
map(
v -> addBlobEntry!(
v,
BlobEntry(;
blobId = uuid4(),
label = :testing,
blobstore = :store,
hash = "",
origin = "",
description = "",
mimeType = "",
timestamp = now(localzone()),
),
),
verts,
)
map(
v -> addBlobEntry!(
v,
BlobEntry(;
blobId = uuid4(),
label = :testing2,
blobstore = :store,
hash = "",
origin = "",
description = "",
mimeType = "",
timestamp = ZonedDateTime(2014, 5, 30, 21, tz"UTC-4"),
),
),
verts,
)
# Add some PPEs
ppe1 = MeanMaxPPE(:default, [1.0], [0.2], [3.456])
ppe2 = MeanMaxPPE(;
solveKey = :other,
suggested = [1.0],
mean = [0.2],
max = [3.456],
createdTimestamp = ZonedDateTime(2014, 5, 30, 21, tz"UTC-4"),
)
map(v -> addPPE!(dfg, getLabel(v), deepcopy(ppe1)), verts)
map(v -> addPPE!(dfg, getLabel(v), deepcopy(ppe2)), verts)
#call update to set it on cloud
updateVariable!.(dfg, verts)
facts = map(
n -> addFactor!(
dfg,
[verts[n], verts[n + 1]],
LinearRelative(Normal(50.0, 2.0)),
),
1:(numNodes - 1),
)
map(f -> setSolvable!(f, Int(round(rand()))), facts)
map(f -> f.solverData.eliminated = rand() > 0.5, facts)
map(f -> f.solverData.potentialused = rand() > 0.5, facts)
updateFactor!.(dfg, facts)
#test multihypo
addFactor!(
dfg,
[:x1, :x2, :x3],
LinearRelative(Normal(50.0, 2.0));
multihypo = [1, 0.3, 0.7],
)
#test user/robot/session metadata
#test user/robot/session blob entries
be = BlobEntry(;
blobId = uuid4(),
label = :testing2,
blobstore = :store,
hash = "",
origin = "",
description = "",
mimeType = "",
timestamp = ZonedDateTime(2023, 2, 3, 20, tz"UTC+1"),
)
addGraphBlobEntry!(dfg, be)
#TODO addAgentBlobEntry!(dfg, be)
smallRobotData = Dict{Symbol, SmallDataTypes}(:a => "43", :b => "small_robot")
smallSessionData = Dict{Symbol, SmallDataTypes}(:a => "44", :b => "small_session")
setAgentMetadata!(dfg, smallRobotData)
setGraphMetadata!(dfg, smallSessionData)
# Save and load the graph to test.
saveDFG(filename, dfg)
@info "Going to load $filename"
copyDfg = DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg)
@test_throws AssertionError loadDFG!(
DistributedFactorGraphs._getDuplicatedEmptyDFG(dfg),
"badfilename",
)
retDFG = loadDFG!(copyDfg, filename)
@test issetequal(ls(dfg), ls(retDFG))
@test issetequal(lsf(dfg), lsf(retDFG))
for var in ls(dfg)
@test getVariable(dfg, var) == getVariable(retDFG, var)
end
for fact in lsf(dfg)
@test compareFactor(
getFactor(dfg, fact),
getFactor(retDFG, fact),
skip = [:timezone, :zone],
) # Timezones
# :hypotheses, :certainhypo, :multihypo, # Multihypo
# :eliminated,
# :potentialused])
end
# Check data entries
for v in ls(dfg)
@test getBlobEntries(getVariable(dfg, v)) ==
getBlobEntries(getVariable(retDFG, v))
@test issetequal(listPPEs(dfg, v), listPPEs(retDFG, v))
for ppe in listPPEs(dfg, v)
@test getPPE(dfg, v, ppe) == getPPE(retDFG, v, ppe)
end
end
# test the duplicate order #581
saveDFG(dfg, filename)
end
end
##
@testset "FileDFG Regression Tests" begin
@info "If any of these tests fail, we have breaking changes"
for file in filter(f -> endswith(f, ".tar.gz"), readdir(joinpath(@__DIR__, "data")))
loadFile = joinpath(@__DIR__, "data", file)
retDFG = loadDFG(loadFile)
# It should have failed if there were any issues.
# Trivial check as well
@test issetequal(ls(retDFG), [:l1, :x0, :x1, :x2, :x3, :x4, :x5, :x6])
@test issetequal(
lsf(retDFG),
[:x0f1, :x0l1f1, :x0x1f1, :x1x2f1, :x2x3f1, :x3x4f1, :x4x5f1, :x5x6f1, :x6l1f1],
)
end
end
##