DIT errors with custom types in contexts
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
Research direction
Start at DifferentiationInterfaceTest/src/scenarios/scenario.jl:78, where zero_contexts handles DI.Constant, and reproduce the shown DIT.Scenario call with MyStruct. Trace how context zero values are constructed and add regression coverage for this custom context; done when the example scenario runs without the shown zero(::MyStruct) error.
Written by the indexing model from the issue text.
Description
import DifferentiationInterface as DI
import DifferentiationInterfaceTest as DIT
struct MyStruct{V}
v::V
end
ms = MyStruct(randn(2))
f(x, ms) = sum(x .* ms.v)
using ForwardDiff
DI.gradient(f, DI.AutoForwardDiff(), randn(2), DI.Constant(ms)) # This is fine
DIT.Scenario{:gradient,:out}(f, randn(2), DI.Constant(ms)) # This errors
Error:
julia> DIT.Scenario{:gradient,:out}(f, randn(2), DI.Constant(ms))
ERROR: MethodError: no method matching zero(::MyStruct{Vector{Float64}})
The function `zero` exists, but no method is defined for this combination of argument types.
Closest candidates are:
zero(::Type{Union{}}, Any...)
@ Base number.jl:359
zero(::Type{LibGit2.GitHash})
@ LibGit2 ~/.julia/juliaup/julia-1.13.0+0.aarch64.apple.darwin14/Julia-1.13.app/Contents/Resources/julia/share/julia/stdlib/v1.13/LibGit2/src/oid.jl:221
zero(::Type{Pkg.Resolve.VersionWeight})
@ Pkg ~/.julia/juliaup/julia-1.13.0+0.aarch64.apple.darwin14/Julia-1.13.app/Contents/Resources/julia/share/julia/stdlib/v1.13/Pkg/src/Resolve/versionweights.jl:15
...
Stacktrace:
[1] call_composed
@ ./operators.jl:1110 [inlined]
[2] (::ComposedFunction{…})(x::DifferentiationInterface.Constant{…}; kw::@Kwargs{})
@ Base ./operators.jl:1107
[3] map
@ ./tuple.jl:354 [inlined]
[4] zero_contexts(contexts::DifferentiationInterface.Constant{MyStruct{Vector{Float64}}})
@ DifferentiationInterfaceTest ~/jl/DifferentiationInterface.jl/DifferentiationInterfaceTest/src/scenarios/scenario.jl:78
[5] (DifferentiationInterfaceTest.Scenario{…})(f::Function, x::Vector{…}, contexts::DifferentiationInterface.Constant{…})
@ DifferentiationInterfaceTest ~/jl/DifferentiationInterface.jl/DifferentiationInterfaceTest/src/scenarios/scenario.jl:81
[6] top-level scope
@ REPL[19]:1
[7] top-level scope
@ REPL:1
Some type information was truncated. Use `show(err)` to see complete types.
- Dominant language
- Julia
- Stars
- 313
- Forks
- 35
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaDiff/DifferentiationInterface.jl
-
bot
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
JuliaDiff/DifferentiationInterface.jl#1011 · 3 comments ·
-
backend wontfix
Difficulty 4/5 3-5 days Newbie friendliness 52/100
JuliaDiff/DifferentiationInterface.jl#1066 · 10 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
backend
Difficulty 4/5 3-5 days Newbie friendliness 52/100
JuliaDiff/DifferentiationInterface.jl#1057 · 1 comment ·
All issues in JuliaDiff/DifferentiationInterface.jl
Similar issues
-
bug 🐞 distributed 🕸️
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
CliMA/Oceananigans.jl#6049 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
JuliaGPU/GPUArrays.jl#780 ·
-
Difficulty 2/5 Half a day Newbie friendliness 76/100
epiforecasts/EpiBranch.jl#304 ·