-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDistributedFactorGraphs.jl
More file actions
437 lines (338 loc) · 10.3 KB
/
DistributedFactorGraphs.jl
File metadata and controls
437 lines (338 loc) · 10.3 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
"""
DistributedFactorGraphs.jl provides a flexible factor graph API for use in the Caesar.jl ecosystem.
The package supplies:
- A standardized API for interacting with factor graphs
- Implementations of the API for in-memory and database-driven operation
- Visualization extensions to validate the underlying graph
"""
module DistributedFactorGraphs
##==============================================================================
## imports
##==============================================================================
using Base
using Base64
using DocStringExtensions
using Dates
using Random
using TimeZones
using JSON3
using StructTypes
using LinearAlgebra
using SparseArrays
using UUIDs
using Pkg
using TensorCast
using ProgressMeter
using SHA
using FileIO
import Distributions
import Tar
import CodecZlib
using OrderedCollections: OrderedDict
using CSV
using Tables
# used for @defVariable
import ManifoldsBase
using ManifoldsBase: AbstractManifold, manifold_dimension
export AbstractManifold, manifold_dimension
using RecursiveArrayTools: ArrayPartition
export ArrayPartition
using StaticArrays
import Base: getindex
using InteractiveUtils: subtypes
##==============================================================================
# Exports
##==============================================================================
# v1 name, signiture, return, and error checked
# v1 name, signiture, and return
export getFactor, getBlobentry, getGraphBlobentry, getVariableState, getFactorState
# v1 name only
export getVariable, getBlob, addBlob!
##
const DFG = DistributedFactorGraphs
export DFG
export GraphsDFGs, GraphsDFG
##------------------------------------------------------------------------------
## DFG
##------------------------------------------------------------------------------
export AbstractDFG
export AbstractParams, NoSolverParams
export AbstractBlobstore
# accessors & crud
export getDFGInfo
export getDescription,
setDescription!,
getSolverParams,
setSolverParams!,
getAgentMetadata,
setAgentMetadata!,
getGraphMetadata,
setGraphMetadata!,
getAddHistory
export getGraphBlobentries,
addGraphBlobentry!,
addGraphBlobentries!,
mergeGraphBlobentry!,
deleteGraphBlobentry!,
getAgentBlobentry,
getAgentBlobentries,
addAgentBlobentry!,
addAgentBlobentries!,
mergeAgentBlobentry!,
deleteAgentBlobentry!,
listGraphBlobentries,
listAgentBlobentries
export getBlobstore,
addBlobstore!, updateBlobstore!, deleteBlobstore!, emptyBlobstore!, listBlobstores
# TODO Not sure these are needed or should work everywhere, implement in cloud?
# NOTE not exporiting these for now. For consistency `get` and `set` might work better.
# export updateAgentMetadata!,
# updateGraphMetadata!, deleteAgentMetadata!, deleteGraphMetadata!
# export emptyAgentMetadata!, emptyGraphMetadata!
# Graph Types: exported from modules
export InMemoryDFGTypes, LocalDFG
# AbstractDFG Interface
export exists,
addVariable!,
addVariables!,
addFactor!,
addFactors!,
mergeVariable!,
mergeFactor!,
deleteVariable!,
deleteFactor!,
listVariables,
listFactors,
listSolveKeys,
listSupersolves,
getVariables,
getFactors,
isVariable,
isFactor
export getindex
export isConnected
export getBiadjacencyMatrix
export getSummaryGraph
# Abstract Nodes
export DFGNode, AbstractDFGVariable, AbstractDFGFactor
# Variables
export VariableCompute, VariableSummary, VariableSkeleton, VariableDFG
# Factors
export FactorCompute, FactorSummary, FactorSkeleton, FactorDFG
# Common
export getSolvable, setSolvable!, isSolvable
export getVariableLabelNumber
# accessors
export getLabel, getTimestamp, setTimestamp, getTags, setTags!
export getAgentLabel, getGraphLabel
# Node Data
export isSolveInProgress, getSolveInProgress
# CRUD & SET
export listTags, mergeTags!, removeTags!, emptyTags!
##------------------------------------------------------------------------------
# Variable
##------------------------------------------------------------------------------
# Abstract Variable Data
export InferenceVariable
# accessors
export getSolverDataDict, setSolverData!
export getVariableType, getVariableTypeName
export getObservation
export getVariableType
# VariableType functions
export getDimension, getManifold, getPointType
export getPointIdentity, getPoint, getCoordinates
# Small Data CRUD
export SmallDataTypes
export getMetadata,
setMetadata!,
addMetadata!,
updateMetadata!,
deleteMetadata!,
listMetadata,
emptyMetadata!
# CRUD & SET
export getVariableStates,
addVariableState!,
mergeVariableState!,
deleteVariableState!,
listVariableStates,
mergeVariableSolverData!,
cloneSolveKey!
# PPE
##------------------------------------------------------------------------------
# PPE TYPES
export AbstractPointParametricEst
export MeanMaxPPE
export getPPEMax, getPPEMean, getPPESuggested, getLastUpdatedTimestamp
# accessors
export getPPEDict, getVariablePPEDict, getVariablePPE
# CRUD & SET
export getPPE,
getPPEs, getVariablePPE, addPPE!, updatePPE!, deletePPE!, listPPEs, mergePPEs! #TODO look at rename to just mergePPE to match with cloud?
# Variable Node Data
##------------------------------------------------------------------------------
export VariableState, PackedVariableState
export packVariableState, unpackVariableState
export getSolvedCount,
isSolved, setSolvedCount!, isInitialized, isMarginalized, setMarginalized!
export getNeighborhood, listNeighbors, _getDuplicatedEmptyDFG
export findFactorsBetweenNaive
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
# Entry Blob Data
##------------------------------------------------------------------------------
export hasBlobentry,
getfirstBlobentry,
addBlobentry!,
addBlobentries!,
mergeBlobentry!,
deleteBlobentry!,
listBlobentrySequence,
mergeBlobentries!
export incrDataLabelSuffix
export getBlobentries
export getBlobentriesVariables
# convenience wrappers
# aliases
export packBlob, unpackBlob
export @format_str # exported from FileIO
##------------------------------------------------------------------------------
# Factors
##------------------------------------------------------------------------------
# Factor Data
export AbstractFactorObservation, AbstractPackedFactorObservation
export AbstractPrior, AbstractRelative, AbstractRelativeMinimize, AbstractManifoldMinimize
export FactorSolverCache
# accessors
export getVariableOrder
export getFactorType, getFactorFunction
# Node Data
export mergeVariableData!, mergeGraphVariableData!
# Serialization type conversion
export convertPackedType, convertStructType
export pack, unpack, packDistribution, unpackDistribution
##------------------------------------------------------------------------------
## Other utility functions
##------------------------------------------------------------------------------
# Sort
export natural_lt, sortDFG
# Validation
export isValidLabel
## List
export ls, lsf, ls2
export lsTypes, lsfTypes, lsTypesDict, lsfTypesDict
export lsWho
export isPrior, lsfPriors
export hasTags, hasTagsNeighbors
## Finding
export findClosestTimestamp, findVariableNearTimestamp
# Serialization
export packVariable, unpackVariable, packFactor, unpackFactor
export rebuildFactorCache!
export @defVariable
# File import and export
export saveDFG, loadDFG!, loadDFG
export toDot, toDotFile
# shortest path
export findShortestPathDijkstra
export isPathFactorsHomogeneous
# Comparisons
export compare,
compareField,
compareFields,
compareAll,
compareVariable,
compareFactor,
compareAllVariables,
compareSimilarVariables,
compareSimilarFactors,
compareFactorGraphs
## Deprecated exports should be listed in Deprecated.jl if possible, otherwise here
## CustomPrinting.jl
export printFactor, printVariable, printNode
# Data Blobs
export InMemoryBlobstore
export FolderStore
export Blobentry
export updateBlob!, deleteBlob!, hasBlob, listBlobentries
export listBlobs
export Blobentry
# export copyStore
export getId, getHash, getTimestamp
# convenience wrappers
export getData, addData!, updateData!, deleteData!
export plotDFG
## TODO maybe move to DFG
# addAgent!
# deleteAgent!
# listAgents
# addGraph!
# deleteGraph!
# listGraphs
# getAgents
# getModel
# getModels
# addModel!
# getGraphs
##==============================================================================
## Files Includes
##==============================================================================
# Entities
include("errors.jl")
include("entities/AbstractDFG.jl")
# Data Blob extensions
include("DataBlobs/entities/BlobEntry.jl")
include("DataBlobs/entities/BlobStores.jl")
include("entities/DFGFactor.jl")
include("entities/DFGVariable.jl")
include("entities/Agent.jl")
include("services/AbstractDFG.jl")
#Blobs
include("DataBlobs/services/BlobEntry.jl")
include("DataBlobs/services/BlobStores.jl")
include("DataBlobs/services/BlobPacking.jl")
include("DataBlobs/services/HelpersDataWrapEntryBlob.jl")
# In Memory Types
include("GraphsDFG/GraphsDFG.jl")
using .GraphsDFGs
#supported in Memory fg types
const InMemoryDFGTypes = Union{GraphsDFG}
const LocalDFG = GraphsDFG
# Common includes
include("services/CommonAccessors.jl")
include("services/Serialization.jl")
include("services/DFGVariable.jl")
include("services/DFGFactor.jl")
include("Deprecated.jl")
include("services/CompareUtils.jl")
# Include the FilesDFG API.
include("FileDFG/FileDFG.jl")
# Custom show and printing for variable factor etc.
include("services/CustomPrinting.jl")
# To be moved as necessary.
include("Common.jl")
include("weakdeps_prototypes.jl")
#TODO start off as just an alias before deprecating
# Starting Variable-level nouns-adjective standardisation
export SkeletonDFGVariable
const SkeletonDFGVariable = VariableSkeleton
export DFGVariableSummary
const DFGVariableSummary = VariableSummary
export DFGVariable
const DFGVariable = VariableCompute
export PackedVariable
const PackedVariable = VariableDFG
export Variable
const Variable = VariableDFG
# Starting Factor-level noun-adjective standardisation
export SkeletonDFGFactor
const SkeletonDFGFactor = FactorSkeleton
export DFGFactorSummary
const DFGFactorSummary = FactorSummary
export DFGFactor
const DFGFactor = FactorCompute
export PackedFactor
const PackedFactor = FactorDFG
export Factor
const Factor = FactorDFG
end