Skip to content

Commit 25e878d

Browse files
authored
Towards standard VariableDFG/State (#1193)
1 parent b59f877 commit 25e878d

26 files changed

+549
-1170
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
- name: Run tests
5252
env:
53-
IIF_TEST: true
53+
IIF_TEST: false #FIXME skipping until IIF stable again
5454
uses: julia-actions/julia-runtest@latest
5555
- name: Process Coverage
5656
uses: julia-actions/julia-processcoverage@v1

Project.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ version = "0.28.0"
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
77
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
88
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
9-
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
109
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1110
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1211
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
@@ -16,7 +15,6 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1615
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
1716
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1817
ManifoldsBase = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
19-
NanoDates = "46f1a544-deae-4307-8689-c12aa3c955c6"
2018
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
2119
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
2220
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
@@ -29,6 +27,7 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
2927
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
3028
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
3129
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
30+
TimesDates = "bdfc003b-8df8-5c39-adcd-3a9087f5df4a"
3231
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3332

3433
[weakdeps]
@@ -45,7 +44,6 @@ Arrow = "2.7"
4544
Base64 = "1.10"
4645
CSV = "0.10"
4746
CodecZlib = "0.7"
48-
Colors = "0.10, 0.11, 0.12, 0.13"
4947
Dates = "1.10"
5048
Distributions = "0.23, 0.24, 0.25"
5149
DocStringExtensions = "0.8, 0.9"
@@ -57,7 +55,6 @@ JSON = "1.0.0"
5755
LieGroups = "0.1"
5856
LinearAlgebra = "1.10"
5957
ManifoldsBase = "1, 2"
60-
NanoDates = "1.0.3"
6158
OrderedCollections = "1.4"
6259
Pkg = "1.4, 1.5"
6360
ProgressMeter = "1"
@@ -72,6 +69,7 @@ Tar = "1.9"
7269
TensorCast = "0.3.3, 0.4"
7370
Test = "1.10"
7471
TimeZones = "1.3.1"
72+
TimesDates = "0.3.3"
7573
UUIDs = "1.10"
7674
julia = "1.10"
7775

ext/DFGPlots.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module DFGPlots
22

3-
using Colors
43
using Graphs
54
using DocStringExtensions
65
using GraphMakie
7-
6+
using GraphMakie.Makie: @colorant_str, RGB
87
using DistributedFactorGraphs
98

109
import DistributedFactorGraphs: plotDFG

src/Common.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ end
142142
##==============================================================================
143143
## Validation of session, robot, and user labels.
144144
##==============================================================================
145-
global _invalidIds =
146-
["GRAPH", "AGENT", "VARIABLE", "FACTOR", "PPE", "BLOB_ENTRY", "FACTORGRAPH"]
145+
global _invalidIds = ["GRAPH", "AGENT", "VARIABLE", "FACTOR", "BLOB_ENTRY", "FACTORGRAPH"]
147146

148147
const global _validLabelRegex::Regex = r"^[a-zA-Z][-\w\.\@]*$"
149148

src/DataBlobs/entities/BlobEntry.jl

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,26 @@ StructUtils.@kwarg struct Blobentry
4040
""" Additional information that can help a different user of the Blob. """
4141
description::String = ""
4242
""" MIME description describing the format of binary data in the `Blob`, e.g. 'image/png' or 'application/json'. """
43-
mimetype::String = "application/octet-stream" #FIXME ::MIME = MIME("application/octet-stream")
43+
mimetype::MIME = MIME("application/octet-stream")
4444
""" Storage for a couple of bytes directly in the graph. Use with caution and keep it small and simple."""
4545
metadata::JSONText = JSONText("{}")
4646
""" When the Blob itself was first created. Serialized as an ISO 8601 string."""
47-
timestamp::NanoDate = ndnow(UTC) & (json = (lower = timestamp,),)
47+
timestamp::TimeDateZone = TimeDateZone(now(localzone()))
4848
""" Type version of this Blobentry."""
49-
version::VersionNumber = version(Blobentry)
49+
version::VersionNumber = DFG.version(Blobentry)
5050
end
5151
version(::Type{Blobentry}) = v"0.1.0"
5252

53-
function Blobentry(label::Symbol, blobstore = :default; kwargs...)
54-
return Blobentry(; label, blobstore, kwargs...)
53+
function Blobentry(
54+
label::Symbol,
55+
blobstore = :default;
56+
metadata = JSONText("{}"),
57+
kwargs...,
58+
)
59+
if !(metadata isa JSONText)
60+
metadata = JSONText(JSON.json(metadata))
61+
end
62+
return Blobentry(; label, blobstore, metadata, kwargs...)
5563
end
5664
# construction helper from existing Blobentry for user overriding via kwargs
5765
function Blobentry(
@@ -123,3 +131,18 @@ function Base.setproperty!(x::Blobentry, f::Symbol, val)
123131
end
124132

125133
const Blobentries = OrderedDict{Symbol, Blobentry}
134+
135+
function StructUtils.lower(entries::Blobentries)
136+
return map(collect(values(entries))) do (entry)
137+
return StructUtils.lower(entry)
138+
end
139+
end
140+
141+
function StructUtils.makedict(s::StructUtils.StructStyle, T::Type{Blobentries}, json_vector)
142+
entries = T()
143+
foreach(json_vector) do obj
144+
entry, _ = StructUtils.make(s, Blobentry, obj)
145+
return push!(entries, Symbol(obj.label[]) => entry)
146+
end
147+
return entries, nothing
148+
end

src/DataBlobs/services/BlobEntry.jl

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ Also see: [`addBlobentry!`](@ref), [`getBlob`](@ref), [`listBlobentries`](@ref)
6767
"""
6868
function getBlobentry(var::AbstractGraphVariable, key::Symbol)
6969
if !hasBlobentry(var, key)
70-
throw(LabelNotFoundError("Blobentry", key, collect(keys(var.dataDict))))
70+
throw(LabelNotFoundError("Blobentry", key, collect(keys(var.blobentries))))
7171
end
72-
return var.dataDict[key]
72+
return var.blobentries[key]
7373
end
7474

75-
function getBlobentry(var::VariableDFG, key::Symbol)
76-
if !hasBlobentry(var, key)
77-
throw(LabelNotFoundError("Blobentry", key))
78-
end
79-
return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
80-
end
75+
# function getBlobentry(var::VariableDFG, key::Symbol)
76+
# if !hasBlobentry(var, key)
77+
# throw(LabelNotFoundError("Blobentry", key))
78+
# end
79+
# return var.blobEntries[findfirst(x -> x.label == key, var.blobEntries)]
80+
# end
8181

8282
"""
8383
$(SIGNATURES)
@@ -131,18 +131,19 @@ Should be extended if DFG variable is not returned by reference.
131131
Also see: [`getBlobentry`](@ref), [`addBlob!`](@ref), [`mergeBlobentry!`](@ref)
132132
"""
133133
function addBlobentry!(var::VariableCompute, entry::Blobentry)
134-
haskey(var.dataDict, entry.label) && throw(LabelExistsError("Blobentry", entry.label))
135-
var.dataDict[entry.label] = entry
136-
return entry
137-
end
138-
139-
function addBlobentry!(var::VariableDFG, entry::Blobentry)
140-
entry.label in getproperty.(var.blobEntries, :label) &&
134+
haskey(var.blobentries, entry.label) &&
141135
throw(LabelExistsError("Blobentry", entry.label))
142-
push!(var.blobEntries, entry)
136+
var.blobentries[entry.label] = entry
143137
return entry
144138
end
145139

140+
# function addBlobentry!(var::VariableDFG, entry::Blobentry)
141+
# entry.label in getproperty.(var.blobEntries, :label) &&
142+
# throw(LabelExistsError("Blobentry", entry.label))
143+
# push!(var.blobEntries, entry)
144+
# return entry
145+
# end
146+
146147
function addBlobentry!(dfg::AbstractDFG, vLbl::Symbol, entry::Blobentry)
147148
return addBlobentry!(getVariable(dfg, vLbl), entry)
148149
end
@@ -158,10 +159,10 @@ If the Blobentry does not exist, it will be added.
158159
Notes:
159160
"""
160161
function mergeBlobentry!(var::AbstractGraphVariable, bde::Blobentry)
161-
if !haskey(var.dataDict, bde.label)
162+
if !haskey(var.blobentries, bde.label)
162163
addBlobentry!(var, bde)
163164
else
164-
var.dataDict[bde.label] = bde
165+
var.blobentries[bde.label] = bde
165166
end
166167
return 1
167168
end
@@ -179,15 +180,15 @@ Notes:
179180
"""
180181
function deleteBlobentry!(var::VariableCompute, key::Symbol)
181182
!hasBlobentry(var, key) && throw(LabelNotFoundError("Blobentry", key))
182-
delete!(var.dataDict, key)
183+
delete!(var.blobentries, key)
183184
return 1
184185
end
185186

186-
function deleteBlobentry!(var::VariableDFG, key::Symbol)
187-
!hasBlobentry(var, key) && throw(LabelNotFoundError("Blobentry", key))
188-
deleteat!(var.blobEntries, findfirst(x -> x.label == key, var.blobEntries))
189-
return 1
190-
end
187+
# function deleteBlobentry!(var::VariableDFG, key::Symbol)
188+
# !hasBlobentry(var, key) && throw(LabelNotFoundError("Blobentry", key))
189+
# deleteat!(var.blobEntries, findfirst(x -> x.label == key, var.blobEntries))
190+
# return 1
191+
# end
191192

192193
function deleteBlobentry!(dfg::AbstractDFG, label::Symbol, key::Symbol)
193194
return deleteBlobentry!(getVariable(dfg, label), key)
@@ -223,24 +224,24 @@ end
223224
224225
Does a blob entry exist with `blobLabel`.
225226
"""
226-
hasBlobentry(v::VariableCompute, blobLabel::Symbol) = haskey(v.dataDict, blobLabel)
227+
hasBlobentry(v::VariableCompute, blobLabel::Symbol) = haskey(v.blobentries, blobLabel)
227228

228-
function hasBlobentry(v::VariableDFG, label::Symbol)
229-
return label in getproperty.(v.blobEntries, :label)
230-
end
229+
# function hasBlobentry(v::VariableDFG, label::Symbol)
230+
# return label in getproperty.(v.blobEntries, :label)
231+
# end
231232

232233
"""
233234
$(SIGNATURES)
234235
235236
Get blob entries, returns a `Vector{Blobentry}`.
236237
"""
237238
function getBlobentries(v::VariableCompute)
238-
return collect(values(v.dataDict))
239+
return collect(values(v.blobentries))
239240
end
240241

241-
function getBlobentries(v::VariableDFG)
242-
return copy(v.blobEntries)
243-
end
242+
# function getBlobentries(v::VariableDFG)
243+
# return copy(v.blobEntries)
244+
# end
244245

245246
function getBlobentries(
246247
v::AbstractGraphVariable;
@@ -289,12 +290,12 @@ const collectBlobentries = gatherBlobentries
289290
List the blob entries associated with a particular variable.
290291
"""
291292
function listBlobentries(var::AbstractGraphVariable)
292-
return collect(keys(var.dataDict))
293+
return collect(keys(var.blobentries))
293294
end
294295

295-
function listBlobentries(var::VariableDFG)
296-
return getproperty.(var.blobEntries, :label)
297-
end
296+
# function listBlobentries(var::VariableDFG)
297+
# return getproperty.(var.blobEntries, :label)
298+
# end
298299

299300
function listBlobentries(dfg::AbstractDFG, label::Symbol)
300301
return listBlobentries(getVariable(dfg, label))

src/Deprecated.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function getSolveInProgress(
5252
)
5353
# Variable
5454
if var isa VariableCompute
55-
if haskey(getSolverDataDict(var), solveKey)
56-
return getSolverDataDict(var)[solveKey].solveInProgress
55+
if haskey(refStates(var), solveKey)
56+
return refStates(var)[solveKey].solveInProgress
5757
else
5858
return 0
5959
end
@@ -148,6 +148,15 @@ function _getDuplicatedEmptyDFG(
148148
# DFG.setDescription!(newDfg, "(Copy of) $(DFG.getDescription(dfg))")
149149
return newDfg
150150
end
151+
152+
#TODO is Type correct
153+
@deprecate getVariableType(args...) getStateType(args...)
154+
155+
function getVariableTypeName(v::VariableSummary)
156+
Base.depwarn("getVariableTypeName is deprecated.", :getVariableTypeName)
157+
return v.statetype
158+
end
159+
151160
## ================================================================================
152161
## Deprecated in v0.28
153162
##=================================================================================
@@ -190,7 +199,7 @@ function setSolverData!(v::VariableCompute, data::State, key::Symbol = :default)
190199
:setSolverData!,
191200
)
192201
@assert key == data.solveKey "State.solveKey=:$(data.solveKey) does not match requested :$(key)"
193-
return v.solverDataDict[key] = data
202+
return v.states[key] = data
194203
end
195204

196205
@deprecate mergeVariableSolverData!(args...; kwargs...) mergeState!(args...; kwargs...)
@@ -289,7 +298,7 @@ end
289298

290299
# Related
291300

292-
# [`listSolveKeys`](@ref), [`getSolverDataDict`](@ref), [`listVariables`](@ref)
301+
# [`listSolveKeys`](@ref), [`refStates`](@ref), [`listVariables`](@ref)
293302
# """
294303
function listSolveKeys(
295304
variable::VariableCompute,
@@ -298,7 +307,7 @@ function listSolveKeys(
298307
)
299308
Base.depwarn("listSolveKeys is deprecated, use listStates instead.", :listSolveKeys)
300309
#
301-
for ky in keys(getSolverDataDict(variable))
310+
for ky in keys(refStates(variable))
302311
push!(skeys, ky)
303312
end
304313

@@ -328,7 +337,7 @@ function listSolveKeys(
328337
#
329338
skeys = Set{Symbol}()
330339
varList = listVariables(dfg, filterVariables; tags = tags, solvable = solvable)
331-
for vs in varList #, ky in keys(getSolverDataDict(getVariable(dfg, vs)))
340+
for vs in varList #, ky in keys(refStates(getVariable(dfg, vs)))
332341
listSolveKeys(dfg, vs, filterSolveKeys, skeys)
333342
end
334343

0 commit comments

Comments
 (0)