FluxML / FluxML/Optimisers.jl

`destructure` doesn't work on Dictionaries

Open
#154 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Julia
Stars
96
Forks
30
PR merge metrics
No merged PRs in 30d

Description

`destructure` uses `map`, I think from before support for Dict was added elsewhere, hence this fails:
```julia
julia> d = Dict(
:a => Dict(
:b => Dict(
:c => 1,
:d => 2,
),
:e => 3,
),
:f => 4,
)
Dict{Symbol, Any} with 2 entries:
:a => Dict{Symbol, Any}(:b=>Dict(:d=>2, :c=>1), :e=>3)
:f => 4

julia> destructure(d)
ERROR: map is not defined on dictionaries
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] map(f::Function, ::Dict{Symbol, Any})
@ Base ./abstractarray.jl:3303
[3] (::Optimisers._TrainableStructWalk)(recurse::Function, x::Dict{Symbol, Any})
@ Optimisers ~/.julia/packages/Optimisers/F7eR3/src/destructure.jl:81
[4] (::Functors.ExcludeWalk{…})(::Function, ::Dict{…})
@ Functors ~/.julia/packages/Functors/rlD70/src/walks.jl:106
[5] (::Functors.CachedWalk{…})(::Functors.var"#recurse#19"{…}, ::Dict{…})
@ Functors ~/.julia/packages/Functors/rlD70/src/walks.jl:146 [inlined]
[6] execute(::Functors.CachedWalk{Functors.ExcludeWalk{…}, Functors.NoKeyword}, ::Dict{Symbol, Any})
@ Functors ~/.julia/packages/Functors/rlD70/src/walks.jl:38
[7] fmap(::Function, ::Dict{…}; exclude::Function, walk::Optimisers._TrainableStructWalk, cache::IdDict{…}, prune::Functors.NoKeyword)
@ Functors ~/.julia/packages/Functors/rlD70/src/maps.jl:11
[8] _flatten(x::Dict{Symbol, Any})
@ Optimisers ~/.julia/packages/Optimisers/F7eR3/src/destructure.jl:69 [inlined]
[9] destructure(x::Dict{Symbol, Any})
@ Optimisers ~/.julia/packages/Optimisers/F7eR3/src/destructure.jl:30
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the nested-Dictionary example and read src/destructure.jl, especially _TrainableStructWalk and the map call identified in the stack trace. Done means destructure(d) handles the shown Dict structure without the “map is not defined on dictionaries” error; add or run a regression test if the repository’s existing test layout supports it.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.