Skip to content

Commit 78d5f54

Browse files
authored
Merge pull request #1693 from JuliaRobotics/23Q1/enh/dropjson12
drop JSON1 and 2
2 parents 4ac23b2 + af67e30 commit 78d5f54

14 files changed

+184
-208
lines changed

Project.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1818
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1919
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
2020
FunctionalStateMachine = "3e9e306e-7e3c-11e9-12d2-8f8f67a2f951"
21-
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
22-
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
2321
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
2422
KernelDensityEstimate = "2472808a-b354-52ea-a80e-1658a3c6056d"
2523
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -52,13 +50,11 @@ ApproxManifoldProducts = "0.6.3"
5250
BSON = "0.2, 0.3"
5351
Combinatorics = "1.0"
5452
DataStructures = "0.16, 0.17, 0.18"
55-
DistributedFactorGraphs = "0.19.3, 0.20"
53+
DistributedFactorGraphs = "0.20"
5654
Distributions = "0.24, 0.25"
5755
DocStringExtensions = "0.8, 0.9"
5856
FileIO = "1"
5957
FunctionalStateMachine = "0.2.9"
60-
JSON = "0.21"
61-
JSON2 = "0.3"
6258
JSON3 = "1"
6359
KernelDensityEstimate = "0.5.6"
6460
Manifolds = "0.8.15"

src/Deprecated.jl

Lines changed: 121 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,34 @@
1+
## ================================================================================================
2+
## Manifolds.jl Consolidation
3+
## TODO: Still to be completed and tested.
4+
## ================================================================================================
5+
# struct ManifoldsVector <: Optim.Manifold
6+
# manis::Vector{Manifold}
7+
# end
18

2-
##==============================================================================
3-
## LEGACY, towards Sidecar
4-
##==============================================================================
5-
6-
"""
7-
Converter: Prior -> PackedPrior::Dict{String, Any}
8-
9-
FIXME see DFG #590 for consolidation with Serialization and Marshaling
10-
"""
11-
function convert(::Type{Dict{String, Any}}, prior::IncrementalInference.Prior)
12-
@error("Obsolete, use pack/unpack converters instead")
13-
z = convert(Type{Dict{String, Any}}, prior.Z)
14-
return Packed_Factor([z], "Prior")
15-
end
16-
17-
"""
18-
Converter: PackedPrior::Dict{String, Any} -> Prior
19-
20-
FIXME see DFG #590 for consolidation on Serialization and Marshaling
21-
"""
22-
function convert(::Type{<:Prior}, prior::Dict{String, Any})
23-
@error("Obsolete, use pack/unpack converters instead")
24-
# Genericize to any packed type next.
25-
z = prior["measurement"][1]
26-
z = convert(DFG.getTypeFromSerializationModule(z["distType"]), z)
27-
return Prior(z)
28-
end
29-
30-
# more legacy, dont delete yet
31-
function Base.getproperty(ccw::CommonConvWrapper, f::Symbol)
32-
if f == :threadmodel
33-
@warn "CommonConvWrapper.threadmodel is obsolete" maxlog=3
34-
return SingleThreaded
35-
elseif f == :params
36-
@warn "CommonConvWrapper.params is deprecated, use .varValsAll instead" maxlog=3
37-
return ccw.varValsAll
38-
elseif f == :vartypes
39-
@warn "CommonConvWrapper.vartypes is deprecated, use typeof.(getVariableType.(ccw.fullvariables) instead" maxlog=3
40-
return typeof.(getVariableType.(ccw.fullvariables))
41-
else
42-
return getfield(ccw, f)
43-
end
44-
end
45-
46-
47-
##==============================================================================
48-
## Deprecate code below before v0.33
49-
##==============================================================================
50-
51-
# export setThreadModel!
52-
# introduced for approximate convolution operations
53-
export SingleThreaded, MultiThreaded
54-
55-
function setThreadModel!(fgl::AbstractDFG; model = IIF.SingleThreaded)
56-
#
57-
@error("Obsolete, ThreadModel types are no longer in use.")
58-
# for (key, id) in fgl.fIDs
59-
# _getCCW(fgl, key).threadmodel = model
60-
# end
61-
return nothing
62-
end
9+
# Base.getindex(mv::ManifoldsVector, inds...) = getindex(mv.mani, inds...)
10+
# Base.setindex!(mv, X, inds...) = setindex!(mv.mani, X, inds...)
6311

64-
# should have been deleted in v0.31 but no harm in keeping this one a bit longer
65-
@deprecate initManual!(w...; kw...) initVariable!(w...; kw...)
12+
# function ManifoldsVector(fg::AbstractDFG, varIds::Vector{Symbol})
13+
# manis = Bool[]
14+
# for k = varIds
15+
# push!(manis, getVariableType(fg, k) |> getManifold)
16+
# end
17+
# ManifoldsVector(manis)
18+
# end
6619

20+
# function Optim.retract!(manis::ManifoldsVector, x)
21+
# for (i,M) = enumerate(manis)
22+
# x[i] = project(M, x[i])
23+
# end
24+
# return x
25+
# end
26+
# function Optim.project_tangent!(manis::ManifoldsVector, G, x)
27+
# for (i, M) = enumerate(manis)
28+
# G[i] = project(M, x[i], G)
29+
# end
30+
# return G
31+
# end
6732

6833

6934
##==============================================================================
@@ -146,34 +111,102 @@ function solveGraphParametric2(
146111
return d, result, flatvar.idx, Σ
147112
end
148113

149-
## ================================================================================================
150-
## Manifolds.jl Consolidation
151-
## TODO: Still to be completed and tested.
152-
## ================================================================================================
153-
# struct ManifoldsVector <: Optim.Manifold
154-
# manis::Vector{Manifold}
155-
# end
156114

157-
# Base.getindex(mv::ManifoldsVector, inds...) = getindex(mv.mani, inds...)
158-
# Base.setindex!(mv, X, inds...) = setindex!(mv.mani, X, inds...)
115+
##==============================================================================
116+
## Deprecate code below before v0.34
117+
##==============================================================================
159118

160-
# function ManifoldsVector(fg::AbstractDFG, varIds::Vector{Symbol})
161-
# manis = Bool[]
162-
# for k = varIds
163-
# push!(manis, getVariableType(fg, k) |> getManifold)
164-
# end
165-
# ManifoldsVector(manis)
119+
# function CommonConvWrapper(
120+
# usrfnc::T,
121+
# fullvariables, #::Tuple ::Vector{<:DFGVariable};
122+
# varValsAll::Tuple,
123+
# X::AbstractVector{P}; #TODO remove X completely
124+
# # xDim::Int = size(X, 1),
125+
# userCache::CT = nothing,
126+
# manifold = getManifold(usrfnc),
127+
# partialDims::AbstractVector{<:Integer} = 1:length(X),
128+
# partial::Bool = false,
129+
# nullhypo::Real = 0,
130+
# inflation::Real = 3.0,
131+
# hypotheses::H = nothing,
132+
# certainhypo = nothing,
133+
# activehypo = collect(1:length(varValsAll)),
134+
# measurement::AbstractVector = Vector(Vector{Float64}()),
135+
# varidx::Int = 1,
136+
# particleidx::Int = 1,
137+
# res::AbstractVector{<:Real} = zeros(manifold_dimension(manifold)), # zDim
138+
# gradients = nothing,
139+
# ) where {T <: AbstractFactor, P, H, CT}
140+
# #
141+
# return CommonConvWrapper(
142+
# usrfnc,
143+
# tuple(fullvariables...),
144+
# varValsAll,
145+
# userCache,
146+
# manifold,
147+
# partialDims,
148+
# partial,
149+
# # xDim,
150+
# float(nullhypo),
151+
# float(inflation),
152+
# hypotheses,
153+
# certainhypo,
154+
# activehypo,
155+
# measurement,
156+
# Ref(varidx),
157+
# Ref(particleidx),
158+
# res,
159+
# gradients,
160+
# )
166161
# end
167162

168-
# function Optim.retract!(manis::ManifoldsVector, x)
169-
# for (i,M) = enumerate(manis)
170-
# x[i] = project(M, x[i])
171-
# end
172-
# return x
163+
# function approxConvOnElements!(
164+
# ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}},
165+
# elements::Union{Vector{Int}, UnitRange{Int}},
166+
# ::Type{<:MultiThreaded},
167+
# _slack = nothing,
168+
# ) where {N_, F <: AbstractRelative, S, T}
169+
# #
170+
# return error(
171+
# "MultiThreaded `approxConvOnElements!` is deprecated and will soon be replaced",
172+
# )
173+
# # Threads.@threads for n in elements
174+
# # # ccwl.thrid_ = Threads.threadid()
175+
# # ccwl.cpt[Threads.threadid()].particleidx = n
176+
177+
# # # ccall(:jl_, Nothing, (Any,), "starting loop, thrid_=$(Threads.threadid()), partidx=$(ccwl.cpt[Threads.threadid()].particleidx)")
178+
# # _solveCCWNumeric!( ccwl, _slack=_slack)
179+
# # end
180+
# # nothing
173181
# end
174-
# function Optim.project_tangent!(manis::ManifoldsVector, G, x)
175-
# for (i, M) = enumerate(manis)
176-
# G[i] = project(M, x[i], G)
177-
# end
178-
# return G
182+
183+
# function approxConvOnElements!(
184+
# ccwl::Union{CommonConvWrapper{F}, CommonConvWrapper{Mixture{N_, F, S, T}}},
185+
# elements::Union{Vector{Int}, UnitRange{Int}},
186+
# _slack = nothing,
187+
# ) where {N_, F <: AbstractRelative, S, T}
188+
# #
189+
# return approxConvOnElements!(ccwl, elements, ccwl.threadmodel, _slack)
179190
# end
191+
192+
# more legacy, dont delete yet
193+
function Base.getproperty(ccw::CommonConvWrapper, f::Symbol)
194+
if f == :threadmodel
195+
error("CommonConvWrapper.threadmodel is obsolete")
196+
# return SingleThreaded
197+
elseif f == :params
198+
error("CommonConvWrapper.params is deprecated, use .varValsAll instead")
199+
return ccw.varValsAll
200+
elseif f == :vartypes
201+
@warn "CommonConvWrapper.vartypes is deprecated, use typeof.(getVariableType.(ccw.fullvariables) instead" maxlog=3
202+
return typeof.(getVariableType.(ccw.fullvariables))
203+
else
204+
return getfield(ccw, f)
205+
end
206+
end
207+
208+
##==============================================================================
209+
## Deprecate code below before v0.35
210+
##==============================================================================
211+
212+
##

src/IncrementalInference.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ using Dates,
4141
ProgressMeter,
4242
DocStringExtensions,
4343
FunctionalStateMachine,
44-
JSON2,
4544
JSON3,
4645
Combinatorics,
4746
UUIDs,

src/Serialization/services/DispatchPackedConversions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function reconstFactorData(
5050
certainhypo = packed.certainhypo,
5151
inflation = packed.inflation,
5252
userCache,
53+
attemptGradients = getSolverParams(dfg).attemptGradients,
5354
# Block recursion if NoSolverParams or if set to not attempt gradients.
5455
_blockRecursion=
5556
getSolverParams(dfg) isa NoSolverParams ||

src/Serialization/services/SerializationMKD.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ end
7575
function Base.convert(::Type{String}, mkd::ManifoldKernelDensity)
7676
#
7777
packedMKD = packDistribution(mkd)
78-
return JSON2.write(packedMKD)
78+
return JSON3.write(packedMKD)
7979
end
8080

8181
# Use general dispatch
@@ -86,7 +86,7 @@ end
8686
# https://discourse.julialang.org/t/converting-string-to-datatype-with-meta-parse/33024/2
8787
# https://discourse.julialang.org/t/is-there-a-way-to-import-modules-with-a-string/15723/6
8888
function Base.convert(::Type{<:ManifoldKernelDensity}, str::AbstractString)
89-
dtr = JSON2.read(str, PackedManifoldKernelDensity)
89+
dtr = JSON3.read(str, PackedManifoldKernelDensity)
9090
return unpackDistribution(dtr)
9191
end
9292

src/Serialization/services/SerializingDistributions.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,18 @@ end
170170
# FIXME ON FIRE, must deprecate nested JSON written fields in all serialization
171171
# TODO is string necessary, because unpacking templated e.g. PackedType{T} has problems, see DFG #668
172172
function convert(::Type{String}, dtr::StringThemSamplableBeliefs)
173-
return JSON2.write(packDistribution(dtr))
173+
return JSON3.write(packDistribution(dtr))
174174
end
175175

176176
function convert(::Type{<:SamplableBelief}, str_obj::AbstractString)
177177
#
178178

179179
# go from stringified to generic packed (no type info)
180-
_pck = JSON2.read(str_obj)
180+
_pck = JSON3.read(str_obj)
181181
# NOTE, get the packed type from strong assumption that field `_type` exists in the
182-
T = DFG.getTypeFromSerializationModule(_pck[:_type])
182+
T = DFG.getTypeFromSerializationModule(_pck._type)
183183
# unpack again to described packedType
184-
pckT = JSON2.read(str_obj, T)
184+
pckT = JSON3.read(str_obj, T)
185185

186186
# unpack to regular <:SamplableBelief
187187
return unpackDistribution(pckT)

src/entities/FactorOperationalMemory.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Related
8080
8181
[`CalcFactor`](@ref), [`CalcFactorMahalanobis`](@ref)
8282
"""
83-
struct CommonConvWrapper{
83+
Base.@kwdef struct CommonConvWrapper{
8484
T <: AbstractFactor,
8585
VT <: Tuple,
8686
NTP <: Tuple,
@@ -101,39 +101,39 @@ struct CommonConvWrapper{
101101
to each hypothesis evaluation event on user function via CalcFactor, #1321 """
102102
varValsAll::NTP
103103
""" dummy cache value to be deep copied later for each of the CalcFactor instances """
104-
dummyCache::CT
104+
dummyCache::CT = nothing
105105
# derived config parameters for this factor
106106
""" Factor manifold definition for frequent use (not the variables manifolds) """
107-
manifold::AM
107+
manifold::AM = getManifold(usrfnc!)
108108
""" Which dimensions does this factor influence. Sensitive (mutable) to both which 'solvefor index' variable and whether the factor is partial dimension """
109-
partialDims::Vector{<:Integer}
109+
partialDims::Vector{<:Integer} = collect(1:manifold_dimension(manifold))
110110
""" is this a partial constraint as defined by the existance of factor field `.partial::Tuple` """
111-
partial::Bool
111+
partial::Bool = false
112112
""" probability that this factor is wholly incorrect and should be ignored during solving """
113-
nullhypo::Float64
113+
nullhypo::Float64 = 0.0
114114
""" inflationSpread particular to this factor (by how much to dispurse the belief initial values before numerical optimization is run). Analogous to stochastic search """
115-
inflation::Float64
115+
inflation::Float64 = 3.0
116116
# multihypo specific field containers for recipe of hypotheses to compute
117117
""" multi hypothesis settings #NOTE no need for a parameter as type is known from `parseusermultihypo` """
118-
hypotheses::HP
118+
hypotheses::HP = nothing
119119
""" categorical to select which hypothesis is being considered during convolution operation """
120-
certainhypo::CH
120+
certainhypo::CH = nothing
121121
""" subsection indices to select which params should be used for this hypothesis evaluation """
122-
activehypo::Vector{Int}
122+
activehypo::Vector{Int} = collect(1:length(varValsAll))
123123
# buffers and indices to point numerical computations to specific memory locations
124124
""" user defined measurement values for each approxConv operation
125125
FIXME make type stable, JT should now be type stable if rest works.
126126
SUPER IMPORTANT, if prior=>point or relative=>tangent, see #1661
127127
can be a Vector{<:Tuple} or more direct Vector{<: pointortangenttype} """
128-
measurement::Vector{MT}
128+
measurement::Vector{MT} = Vector(Vector{Float64}())
129129
""" which index is being solved for in params? """
130-
varidx::Base.RefValue{Int}
130+
varidx::Base.RefValue{Int} = Ref(1)
131131
""" Consolidation from CPT, the actual particle being solved at this moment """
132-
particleidx::Base.RefValue{Int}
132+
particleidx::Base.RefValue{Int} = Ref(1)
133133
""" working memory to store residual for optimization routines """
134-
res::Vector{Float64}
134+
res::Vector{Float64} = zeros(manifold_dimension(manifold))
135135
""" experimental feature to embed gradient calcs with ccw """
136-
_gradients::G
136+
_gradients::G = nothing
137137
end
138138

139139

0 commit comments

Comments
 (0)