Skip to content

Commit 3e96d0e

Browse files
authored
Merge pull request #949 from JuliaRobotics/23Q1/fix/tryquickkwfix
Fix constructor CI bug, JL1.9, drop Unmarshal, and more
2 parents 7a81f52 + 6dd3cad commit 3e96d0e

File tree

7 files changed

+133
-75
lines changed

7 files changed

+133
-75
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
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.19.2"
3+
version = "0.19.3"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -25,7 +25,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2525
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
2626
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
2727
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
28-
Unmarshal = "cbff2730-442d-58d7-89d1-8e530c41eb02"
2928

3029
[compat]
3130
Colors = "0.10, 0.11, 0.12"
@@ -45,7 +44,6 @@ Reexport = "1"
4544
Requires = "1"
4645
TensorCast = "0.3.3, 0.4"
4746
TimeZones = "1.3.1"
48-
Unmarshal = "0.4"
4947
julia = "1.6"
5048

5149
[extras]

src/DataBlobs/entities/AbstractDataEntries.jl

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,39 @@ General Data Store Entry.
2828
origin::String # E.g. user|robot|session|varlabel
2929
description::String
3030
mimeType::String
31-
metadata::String
31+
metadata::String = ""
3232
timestamp::ZonedDateTime = now(localzone())
3333
_type::String = "BlobStoreEntry"
3434
_version::String = _getDFGVersion()
3535
end
3636

3737
_fixtimezone(cts::NamedTuple) = ZonedDateTime(cts.utc_datetime*"+00")
3838

39-
# needed for deserialization from JSON during DFG v0.19 transition, see #867
40-
function BlobStoreEntry(;
41-
id,
42-
label,
43-
blobstore,
44-
hash,
45-
origin,
46-
description,
47-
mimeType,
48-
timestamp,
49-
kwargs... # drop excessive fields
50-
)
51-
#
52-
BlobStoreEntry(
53-
UUID(id),
54-
Symbol(label),
55-
Symbol(blobstore),
56-
hash,
57-
origin,
58-
description,
59-
mimeType,
60-
_fixtimezone(timestamp),
61-
)
62-
end
39+
# # needed for deserialization from JSON during DFG v0.19 transition, see #867
40+
# # TODO this function can likely be removed, since julia automatically tries type conversion on constructors.
41+
# function BlobStoreEntry(;
42+
# id,
43+
# label,
44+
# blobstore,
45+
# hash,
46+
# origin,
47+
# description,
48+
# mimeType,
49+
# timestamp,
50+
# kwargs... # drop excessive fields
51+
# )
52+
# #
53+
# BlobStoreEntry(;
54+
# id=UUID(id),
55+
# label=Symbol(label),
56+
# blobstore=Symbol(blobstore),
57+
# hash,
58+
# origin,
59+
# description,
60+
# mimeType,
61+
# timestamp=_fixtimezone(timestamp),
62+
# )
63+
# end
6364

6465
# TODO
6566
"""

src/Deprecated.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ end
6363
## Deprecate before v0.20
6464
##=================================================================================
6565

66+
67+
# Need to implement this to allow Unmarshal to deserialize Nullable UUIDs and ZonedDateTimes
68+
# TODO: Move to JSON3.
69+
# import Unmarshal: unmarshal
70+
71+
function unmarshal(::Type{Union{UUID, Nothing}}, x, verbose :: Bool = false, verboseLvl :: Int = 0)
72+
if x !== nothing
73+
return UUID(x)
74+
else
75+
return nothing
76+
end
77+
end
78+
function unmarshal(::Type{Union{ZonedDateTime, Nothing}}, x, verbose :: Bool = false, verboseLvl :: Int = 0)
79+
if x !== nothing
80+
return ZonedDateTime(x)
81+
else
82+
return nothing
83+
end
84+
end
85+
6686
export DefaultDFG
6787

6888
const DefaultDFG = GraphsDFG

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using TimeZones
2323
using Distributions
2424
using Reexport
2525
using JSON
26-
using Unmarshal
26+
# using Unmarshal
2727
using JSON2 # JSON2 requires all properties to be in correct sequence, can't guarantee that from DB.
2828
using JSON3
2929
using LinearAlgebra

src/GraphsDFG/entities/GraphsDFG.jl

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,40 @@ Create an in-memory GraphsDFG with the following parameters:
2929
- V: Variable type
3030
- F: Factor type
3131
"""
32-
function GraphsDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
33-
description::String="Graphs.jl implementation",
34-
userLabel::String="DefaultUser",
35-
robotLabel::String="DefaultRobot",
36-
sessionLabel::String="Session_$(string(uuid4())[1:6])",
37-
userData::Dict{Symbol, String} = Dict{Symbol, String}(),
38-
robotData::Dict{Symbol, String} = Dict{Symbol, String}(),
39-
sessionData::Dict{Symbol, String} = Dict{Symbol, String}(),
40-
solverParams::T=T(),
41-
blobstores=Dict{Symbol, AbstractBlobStore}()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
42-
# Validate the userLabel, robotLabel, and sessionLabel
43-
!isValidLabel(userLabel) && error("'$userLabel' is not a valid User label")
44-
!isValidLabel(robotLabel) && error("'$robotLabel' is not a valid Robot label")
45-
!isValidLabel(sessionLabel) && error("'$sessionLabel' is not a valid Session label")
46-
return GraphsDFG{T,V,F}(g, description, userLabel, robotLabel, sessionLabel, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
32+
function GraphsDFG{T,V,F}(
33+
g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
34+
description::String="Graphs.jl implementation",
35+
userLabel::String="DefaultUser",
36+
robotLabel::String="DefaultRobot",
37+
sessionLabel::String="Session_$(string(uuid4())[1:6])",
38+
userData::Dict{Symbol, String} = Dict{Symbol, String}(),
39+
robotData::Dict{Symbol, String} = Dict{Symbol, String}(),
40+
sessionData::Dict{Symbol, String} = Dict{Symbol, String}(),
41+
solverParams::T=T(),
42+
blobstores=Dict{Symbol, AbstractBlobStore}(),
43+
# deprecating
44+
userId::Union{Nothing, String} = nothing,
45+
robotId::Union{Nothing, String} = nothing,
46+
sessionId::Union{Nothing, String} = nothing,
47+
) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
48+
# Validate the userLabel, robotLabel, and sessionLabel
49+
if userId !== nothing
50+
@error "Obsolete use of userId::String with GraphsDFG, use userLabel::String instead" maxlog=10
51+
userLabel = userId
52+
end
53+
if robotId !== nothing
54+
@error "Obsolete use of robotId::String with GraphsDFG, use robotLabel::String instead" maxlog=10
55+
robotLabel = robotId
56+
end
57+
if sessionId !== nothing
58+
@error "Obsolete use of sessionId::String with GraphsDFG, use sessionLabel::String instead" maxlog=10
59+
sessionLabel = sessionId
60+
end
61+
62+
!isValidLabel(userLabel) && error("'$userLabel' is not a valid User label")
63+
!isValidLabel(robotLabel) && error("'$robotLabel' is not a valid Robot label")
64+
!isValidLabel(sessionLabel) && error("'$sessionLabel' is not a valid Session label")
65+
return GraphsDFG{T,V,F}(g, description, userLabel, robotLabel, sessionLabel, userData, robotData, sessionData, Symbol[], solverParams, blobstores)
4766
end
4867

4968
# GraphsDFG{T}(; kwargs...) where T <: AbstractParams = GraphsDFG{T,DFGVariable,DFGFactor}(;kwargs...)

src/entities/DFGVariable.jl

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,63 @@ Fields:
1717
$(TYPEDFIELDS)
1818
"""
1919
Base.@kwdef mutable struct VariableNodeData{T<:InferenceVariable, P}
20+
"""
21+
Globally unique identifier.
22+
"""
2023
id::Union{UUID, Nothing} = nothing # If it's blank it doesn't exist in the DB.
24+
"""
25+
Vector of on-manifold points used to represent a ManifoldKernelDensity (or parametric) belief.
26+
"""
2127
val::Vector{P}
28+
"""
29+
Common kernel bandwith parameter used with ManifoldKernelDensity, and as legacy also stores covariance until a dedicated field is created for parametric case.
30+
"""
2231
bw::Matrix{Float64} = zeros(0,0)
2332
BayesNetOutVertIDs::Vector{Symbol} = Symbol[]
24-
dimIDs::Vector{Int} = Int[] # Likely deprecate
33+
dimIDs::Vector{Int} = Int[] # TODO Likely deprecate
2534

2635
dims::Int = 0
36+
"""
37+
Flag used by junction (Bayes) tree construction algorith to know whether this variable has yet been included in the tree construction.
38+
"""
2739
eliminated::Bool = false
2840
BayesNetVertID::Symbol = :NOTHING # Union{Nothing, }
2941
separator::Vector{Symbol} = Symbol[]
30-
42+
"""
43+
Variables each have a type, such as Position1, or RoME.Pose2, etc.
44+
"""
3145
variableType::T
46+
"""
47+
False if initial numerical values are not yet available or stored values are not ready for further processing yet.
48+
"""
3249
initialized::Bool = false
3350
"""
34-
Replacing previous `inferdim::Float64`, new `.infoPerCoord::Vector{Float64}` will in
35-
future stores the amount information (per measurement dimension) captured in each
36-
coordinate dimension.
51+
Stores the amount information (per measurement dimension) captured in each coordinate dimension.
3752
"""
3853
infoPerCoord::Vector{Float64} = Float64[0.0;]
54+
"""
55+
Should this variable solveKey be treated as marginalized in inference computations.
56+
"""
3957
ismargin::Bool = false
40-
58+
"""
59+
Shoudl this variable solveKey always be kept fluid and not be automatically marginalized.
60+
"""
4161
dontmargin::Bool = false
62+
"""
63+
Convenience flag on whether a solver is currently busy working on this variable solveKey.
64+
"""
4265
solveInProgress::Int = 0
66+
"""
67+
How many times has a solver updated this variable solveKey estimte.
68+
"""
4369
solvedCount::Int = 0
70+
"""
71+
solveKey identifier associated with thsi VariableNodeData object.
72+
"""
4473
solveKey::Symbol
45-
74+
"""
75+
Future proofing field for when more multithreading operations on graph nodes are implemented, these conditions are meant to be used for atomic write transactions to this VND.
76+
"""
4677
events::Dict{Symbol,Threads.Condition} = Dict{Symbol,Threads.Condition}()
4778
#
4879
end
@@ -62,10 +93,6 @@ function VariableNodeData(variableType::T; solveKey::Symbol=:default) where T <:
6293
bw = zeros(0,0)
6394
# bw[1] = zeros(getDimension(T))
6495
VariableNodeData(; val, bw, solveKey, variableType )
65-
# VariableNodeData( nothing, P0, BW, Symbol[], Int[],
66-
# 0, false, :NOTHING, Symbol[],
67-
# variableType, false, [0.0], false,
68-
# false, 0, 0, solveKey )
6996
end
7097

7198

src/services/Serialization.jl

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,9 @@ import JSON.Writer: StructuralContext, JSONContext, show_json
1212
import JSON.Serializations: CommonSerialization, StandardSerialization
1313
JSON.show_json(io::JSONContext, serialization::CommonSerialization, uuid::UUID) = print(io.io, "\"$uuid\"")
1414

15-
# Need to implement this to allow Unmarshal to deserialize Nullable UUIDs and ZonedDateTimes
16-
# TODO: Move to JSON3.
17-
import Unmarshal: unmarshal
18-
19-
function unmarshal(::Type{Union{UUID, Nothing}}, x, verbose :: Bool = false, verboseLvl :: Int = 0)
20-
if x !== nothing
21-
return UUID(x)
22-
else
23-
return nothing
24-
end
25-
end
26-
function unmarshal(::Type{Union{ZonedDateTime, Nothing}}, x, verbose :: Bool = false, verboseLvl :: Int = 0)
27-
if x !== nothing
28-
return ZonedDateTime(x)
29-
else
30-
return nothing
31-
end
32-
end
3315

3416
## Version checking
17+
# FIXME return VersionNumber
3518
function _getDFGVersion()
3619
if haskey(Pkg.dependencies(), Base.UUID("b5cc3c7e-6572-11e9-2517-99fb8daf2f04"))
3720
return string(Pkg.dependencies()[Base.UUID("b5cc3c7e-6572-11e9-2517-99fb8daf2f04")].version)
@@ -81,7 +64,7 @@ end
8164
function standardizeZDTStrings!(T, interm::Dict)
8265

8366
for (name, typ) in zip(fieldnames(T), T.types)
84-
if typ <: ZonedDateTime
67+
if typ <: ZonedDateTime && haskey(interm, name)
8568
namestr = string(name)
8669
interm[namestr] = getStandardZDTString(interm[namestr])
8770
end
@@ -144,6 +127,14 @@ end
144127
$SIGNATURES
145128
Should be a highly reusable function for any transcoding of intermediate type (or dict) to a desired output type.
146129
130+
Notes:
131+
- Using Base.@kwdef and JSON3.jl probably has better conversion logic than this function.
132+
- This function was written to reduce dependency on Unmarshal.jl which was becoming stale.
133+
134+
DevNotes
135+
- See if this function just be deprecated to use JSON3 or similar.
136+
- Do better with Union{Nothing, T} types (if this function is not replaced by JSON3)
137+
147138
examples
148139
```julia
149140
Base.@kwdef struct HardType
@@ -200,6 +191,7 @@ function transcodeType(
200191
# specializations as inner functions (don't have to be inners)
201192
# these few special cases came up with examples below, note recursions
202193
_instance(S::Type, x) = S(x)
194+
_instance(S::Type{Union{Nothing, UUID}}, x::String) = UUID(x) # special case
203195
_instance(_::Type{S}, x::S) where S = x # if ambiguous, delete and do alternative `_instance(S::Type, x) = S===Any ? x : S(x)`
204196
_instance(S::Type{I}, x::AbstractString) where I <: Number = Base.parse(I, x)
205197
_instance(S::Type{E}, x::AbstractVector) where E <: AbstractVector = _instance.(eltype(E),x)
@@ -452,7 +444,8 @@ function unpackVariable(
452444
interm = _doparse(bdeInter) # JSON.parse(bdeInter) # bdeInter
453445
objType = getfield(DistributedFactorGraphs, Symbol(dataElemTypes[k]))
454446
standardizeZDTStrings!(objType, interm)
455-
fullVal = Unmarshal.unmarshal(objType, interm)
447+
fullVal = transcodeType(objType, interm)
448+
# fullVal = Unmarshal.unmarshal(objType, interm)
456449
variable.dataDict[k] = fullVal
457450
end
458451
end

0 commit comments

Comments
 (0)