Skip to content

Commit 5165a3f

Browse files
authored
Merge branch 'master' into 22Q4/api/packvarsimpler
2 parents f4fcf1d + 0a5eab9 commit 5165a3f

File tree

15 files changed

+250
-46
lines changed

15 files changed

+250
-46
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
version:
2121
- '1.6'
2222
- '1.8'
23+
- '~1.9.0-0'
2324
- 'nightly'
2425
os:
2526
- ubuntu-latest
@@ -81,7 +82,6 @@ jobs:
8182
fail-fast: false
8283
matrix:
8384
version:
84-
- '1.6'
8585
- '1.8'
8686
os:
8787
- ubuntu-latest

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.18.8"
3+
version = "0.19.0"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -17,6 +17,7 @@ ManifoldsBase = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
1717
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1818
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
1919
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
20+
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
2021
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
2122
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2223
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -40,6 +41,7 @@ ManifoldsBase = "0.11, 0.12, 0.13"
4041
Neo4j = "2"
4142
OrderedCollections = "1.4"
4243
Pkg = "1.4, 1.5"
44+
ProgressMeter = "1"
4345
RecursiveArrayTools = "2"
4446
Reexport = "1"
4547
Requires = "1"

src/Common.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ DevNotes
105105
106106
"""
107107
getVariableLabelNumber(vs::Symbol, prefix=string(vs)[1]) = parse(Int, string(vs)[(length(prefix)+1):end])
108+
109+
110+
## =================================
111+
## Additional Downstream dispatches
112+
## =================================
113+
114+
function solveGraph! end
115+
function solveGraphParametric! end

src/DataBlobs/entities/AbstractDataEntries.jl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,33 @@ struct BlobStoreEntry <: AbstractDataEntry
3131
createdTimestamp::ZonedDateTime # of when the entry was created
3232
end
3333

34+
_fixtimezone(cts::NamedTuple) = ZonedDateTime(cts.utc_datetime*"+00")
35+
36+
# needed for deserialization from JSON during DFG v0.19 transition, see #867
37+
function BlobStoreEntry(;
38+
label,
39+
id,
40+
blobstore,
41+
hash,
42+
origin,
43+
description,
44+
mimeType,
45+
createdTimestamp,
46+
kwargs... # drop excessive fields
47+
)
48+
#
49+
BlobStoreEntry(
50+
Symbol(label),
51+
UUID(id),
52+
Symbol(blobstore),
53+
hash,
54+
origin,
55+
description,
56+
mimeType,
57+
_fixtimezone(createdTimestamp),
58+
)
59+
end
60+
3461
# TODO
3562
"""
3663
$(TYPEDEF)

src/DataBlobs/services/AbstractDataEntries.jl

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,25 @@ function getDataEntry(var::AbstractDFGVariable, blobId::UUID)
4141
return v
4242
end
4343
end
44-
error("No dataEntry with blobId $(blobId) found in variable $(getLabel(var))")
44+
throw(
45+
KeyError("No dataEntry with blobId $(blobId) found in variable $(getLabel(var))")
46+
)
4547
end
48+
function getDataEntry(var::AbstractDFGVariable, key::Regex)
49+
for (k,v) in var.dataDict
50+
if occursin(key, string(v.label))
51+
return v
52+
end
53+
end
54+
throw(
55+
KeyError("No dataEntry with label matching regex $(key) found in variable $(getLabel(var))")
56+
)
57+
end
58+
getDataEntry(var::AbstractDFGVariable, key::AbstractString) = getDataEntry(var,Regex(key))
59+
4660

47-
getDataEntry(dfg::AbstractDFG, label::Symbol, key::UUID) = getDataEntry(getVariable(dfg, label), key)
48-
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getDataEntry(getVariable(dfg, label), key)
61+
getDataEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:AbstractString, Regex}) = getDataEntry(getVariable(dfg, label), key)
62+
# getDataEntry(dfg::AbstractDFG, label::Symbol, key::Symbol) = getDataEntry(getVariable(dfg, label), key)
4963

5064

5165
"""
@@ -196,8 +210,11 @@ function mergeDataEntries!(
196210
des = _makevec(des_)
197211
# don't add data entries that already exist
198212
dde = listDataEntries(dst, dlbl)
199-
uids = (s->s.id).(dde)
200-
filter!(s -> !(s.id in uids), des)
213+
# HACK, verb list should just return vector of Symbol. NCE36
214+
_getid(s) = s
215+
_getid(s::AbstractDataEntry) = s.id
216+
uids = _getid.(dde) # (s->s.id).(dde)
217+
filter!(s -> !(_getid(s) in uids), des)
201218
# add any data entries not already in the destination variable, by uuid
202219
addDataEntry!.(dst, dlbl, des)
203220
end
@@ -212,9 +229,67 @@ function mergeDataEntries!(
212229
des = listDataEntries(src, slbl)
213230
# don't add data entries that already exist
214231
dde = listDataEntries(dst, dlbl)
215-
uids = (s->s.id).(dde)
216-
filter!(s -> !(s.id in uids), des)
232+
# HACK, verb list should just return vector of Symbol. NCE36
233+
_getid(s) = s
234+
_getid(s::AbstractDataEntry) = s.id
235+
uids = _getid.(dde) # (s->s.id).(dde)
236+
filter!(s -> !(_getid(s) in uids), des)
217237
if 0 < length(des)
218238
union(((s->mergeDataEntries!(dst, dlbl, src, slbl, s.id)).(des))...)
219239
end
220-
end
240+
end
241+
242+
function mergeDataEntries!(
243+
dest::AbstractDFG,
244+
src::AbstractDFG,
245+
w...;
246+
varList::AbstractVector = listVariables(dest) |> sortDFG
247+
)
248+
@showprogress 1 "merging data entries" for vl in varList
249+
mergeDataEntries!(dest, vl, src, vl, w...)
250+
end
251+
varList
252+
end
253+
254+
"""
255+
$SIGNATURES
256+
257+
If the blob label `datalabel` already exists, then this function will return the name `datalabel_1`.
258+
If the blob label `datalabel_1` already exists, then this function will return the name `datalabel_2`.
259+
"""
260+
function incrDataLabelSuffix(
261+
dfg::AbstractDFG,
262+
vla,
263+
bllb::S;
264+
datalabel=Ref("")
265+
) where {S <: Union{Symbol, <:AbstractString}}
266+
count = 1
267+
hasund = false
268+
len = 0
269+
try
270+
de,_ = getData(dfg, Symbol(vla), bllb)
271+
bllb = string(bllb)
272+
# bllb *= bllb[end] != '_' ? "_" : ""
273+
datalabel[] = string(de.label)
274+
dlb = match(r"\d*", reverse(datalabel[]))
275+
# slightly complicated search if blob name already has an underscore number suffix, e.g. `_4`
276+
count, hasund, len = if occursin(Regex(dlb.match*"_"), reverse(datalabel[]))
277+
parse(Int, dlb.match |> reverse)+1, true, length(dlb.match)
278+
else
279+
1, datalabel[][end] == '_', 0
280+
end
281+
catch err
282+
# append latest count
283+
if !(err isa KeyError)
284+
throw(err)
285+
end
286+
end
287+
# the piece from old label without the suffix count number
288+
bllb = datalabel[][1:(end-len)]
289+
if !hasund || bllb[end] != '_'
290+
bllb *= "_"
291+
end
292+
bllb *= string(count)
293+
294+
S(bllb)
295+
end

src/DataBlobs/services/BlobStores.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function getDataBlob(dfg::AbstractDFG, entry::BlobStoreEntry)
1717
end
1818
throw(
1919
KeyError(
20-
"could not find $(entry.label), uuid $(entry.id)) in any of the listed blobstores:\n $((s->getKey(s)).(stores))"
20+
"could not find $(entry.label), uuid $(entry.id)) in any of the listed blobstores:\n $([s->getKey(s) for (s,v) in stores]))"
2121
)
2222
)
2323
end
@@ -84,7 +84,7 @@ function getData(
8484
dfg::AbstractDFG,
8585
blobstore::AbstractBlobStore,
8686
label::Symbol,
87-
key::Union{Symbol,UUID};
87+
key::Union{Symbol,UUID, <:AbstractString, Regex};
8888
hashfunction = sha256,
8989
checkhash::Bool=true
9090
)

src/DataBlobs/services/DataEntryBlob.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ end
114114
function getData(
115115
dfg::AbstractDFG,
116116
vlabel::Symbol,
117-
key::Union{Symbol,UUID};
117+
key::Union{Symbol,UUID, <:AbstractString, Regex};
118118
hashfunction = sha256,
119119
checkhash::Bool=true
120120
)

src/DistributedFactorGraphs.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using SparseArrays
3030
using UUIDs
3131
using Pkg
3232
using TensorCast
33+
using ProgressMeter
3334

3435
# used for @defVariable
3536
import ManifoldsBase
@@ -192,12 +193,14 @@ export getSolvedCount, isSolved, setSolvedCount!, isInitialized, isMarginalized,
192193
export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
193194
export findFactorsBetweenNaive
194195
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
195-
# Big Data
196+
197+
# Entry Blob Data
196198
##------------------------------------------------------------------------------
197199
export addDataEntry!, getDataEntry, updateDataEntry!, deleteDataEntry!, getDataEntries, listDataEntries, hasDataEntry, hasDataEntry
198200
export listDataEntrySequence
199201
# convenience wrappers
200202
export addDataEntry!, mergeDataEntries!
203+
export incrDataLabelSuffix
201204
# aliases
202205
export addData!
203206

src/FileDFG/services/FileDFG.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ function saveDFG(folder::AbstractString, dfg::AbstractDFG)
4343
for v in variables
4444
vPacked = packVariable(dfg, v)
4545
io = open("$varFolder/$(v.label).json", "w")
46-
JSON2.write(io, vPacked)
46+
println(io,JSON.json(vPacked))
4747
close(io)
4848
end
4949
# Factors
5050
for f in factors
5151
fPacked = packFactor(dfg, f)
5252
io = open("$factorFolder/$(f.label).json", "w")
53-
JSON2.write(io, fPacked)
53+
println(io,JSON.json(fPacked))
5454
close(io)
5555
end
5656

@@ -130,10 +130,11 @@ function loadDFG!(dfgLoadInto::AbstractDFG, dst::AbstractString)
130130
varFiles = readdir(varFolder)
131131
factorFiles = readdir(factorFolder)
132132
for varFile in varFiles
133-
open("$varFolder/$varFile") do io
134-
packedData = JSON2.read(io, Dict{String, Any})
133+
packedData = JSON.parsefile("$varFolder/$varFile"; dicttype=Dict{String, Any})
134+
# open("$varFolder/$varFile") do io
135+
# packedData = JSON.parse(io; dicttype=Dict{String, Any})
135136
push!(variables, unpackVariable(dfgLoadInto, packedData))
136-
end
137+
# end
137138
end
138139
@info "Loaded $(length(variables)) variables - $(map(v->v.label, variables))"
139140
@info "Inserting variables into graph..."

src/entities/DFGFactor.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ abstract type AbstractPackedFactor end
88

99
abstract type AbstractPrior <: AbstractFactor end
1010
abstract type AbstractRelative <: AbstractFactor end
11-
abstract type AbstractRelativeRoots <: AbstractRelative end
11+
abstract type AbstractRelativeRoots <: AbstractRelative end # NOTE Cannot be used for partials
1212
abstract type AbstractRelativeMinimize <: AbstractRelative end
1313
abstract type AbstractManifoldMinimize <: AbstractRelative end # FIXME move here from IIF
1414

0 commit comments

Comments
 (0)