-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom getproperty of mutable struct fails #685
Comments
Also running into this issue. Prevents use of Zygote with matrices wrapped as tables using In my case the struct is immutable and the error is still there (Zygote = v0.5.6): struct Foo
z::Float64
end
Base.propertynames(Foo) = (:z_squared,)
Base.getproperty(f::Foo, s::Symbol) =
s in propertynames(Foo) ? getfield(f, :z)^2 : throw(ArgumentError)
foo = Foo(2.0)
julia> foo.z_squared
4.0
loss(x) = x*getfield(foo, :z)
julia> loss(3)
6.0
julia> gradient(loss, 1.0)
ERROR: ArgumentError
Stacktrace:
[1] getproperty(::Foo, ::Symbol) at ./REPL[11]:1
[2] adjoint at /Users/anthony/.julia/packages/Zygote/Xgcgs/src/lib/lib.jl:197 [inlined]
[3] _pullback(::Zygote.Context, ::typeof(ZygoteRules.literal_getproperty), ::Foo, ::Val{:z at /Users/anthony/.julia/packages/ZygoteRules/6nssF/src/adjoint.jl:47
[4] _pullback(::Zygote.Context, ::typeof(getfield), ::Foo, ::Symbol) at /Users/anthony/.julia/packages/Zygote/Xgcgs/src/lib/lib.jl:214
[5] loss at ./REPL[20]:1 [inlined]
[6] _pullback(::Zygote.Context, ::typeof(loss), ::Float64) at /Users/anthony/.julia/packages/Zygote/Xgcgs/src/compiler/interface2.jl:0
[7] _pullback(::Function, ::Float64) at /Users/anthony/.julia/packages/Zygote/Xgcgs/src/compiler/interface.jl:38
[8] pullback(::Function, ::Float64) at /Users/anthony/.julia/packages/Zygote/Xgcgs/src/compiler/interface.jl:44
[9] gradient(::Function, ::Float64) at /Users/anthony/.julia/packages/Zygote/Xgcgs/src/compiler/interface.jl:53
[10] top-level scope at REPL[23]:1
[11] eval(::Module, ::Any) at ./boot.jl:331
[12] eval_user_input(::Any, ::REPL.REPLBackend) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
[13] run_backend(::REPL.REPLBackend) at /Users/anthony/.julia/packages/Revise/BqeJF/src/Revise.jl:1184
julia> versioninfo()
Julia Version 1.4.2 |
Both MWEs from this issue appear fixed with at least Zygote v0.6.11 (maybe before, I havent bisected), so closing this issue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a MWE on 0.4.20, basically I'm adding a custom property
foo.x
:which fails with:
Note if I make the struct immutable its fine. Another solution appears to be defining the following, but I really don't know what I'm doing here so maybe this is not correct in general:
The text was updated successfully, but these errors were encountered: