In an attempt to replicate what I saw here: " The impact of differentiable programming: how ∂P is enabling new science in Julia"
function g(x)
if x < 0
print("Enter function name: ")
getfield(Base, Symbol(readline()))(x)
else
2*x^3 + 4*x^2 +5*x
end
end
julia> g'(4)
133
julia> g'(-pi/6)
Enter function name: sin
ERROR: Can't differentiate foreigncall expression
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] Symbol at ./boot.jl:438 [inlined]
[3] (::typeof(∂(Symbol)))(::Nothing) at /home/user/.julia/packages/Zygote/ggM8Z/src/compiler/interface2.jl:0
[4] g at /home/user/julia_control/cm_control.jl:17 [inlined]
[5] (::typeof(∂(g)))(::Float64) at /home/user/.julia/packages/Zygote/ggM8Z/src/compiler/interface2.jl:0
[6] (::Zygote.var"#41#42"{typeof(∂(g))})(::Float64) at /home/user/.julia/packages/Zygote/ggM8Z/src/compiler/interface.jl:40
[7] gradient(::Function, ::Float64) at /home/user/.julia/packages/Zygote/ggM8Z/src/compiler/interface.jl:49
[8] (::Zygote.var"#43#44"{typeof(g)})(::Float64) at /home/user/.julia/packages/Zygote/ggM8Z/src/compiler/interface.jl:52 [9] top-level scope at none:1
Why am I getting this error and how to resolve it?
using Flux
using Zygote
using Trebuchet
function shoot(wind, angle, weight)
Trebuchet.shoot((wind, Trebuchet.deg2rad(angle), weight))[2]
end
julia> shoot'(5,50,220)
ERROR: MethodError: no method matching (::Zygote.var"#43#44"{typeof(shoot)})(::Int64, ::Int64, ::Int64)
It seems like Zygote doesn’t like (::Int64, ::Int64, ::Int64)
. How to fix it?
Also, tried this:
function shoot(pars)
Trebuchet.shoot((pars[1], Trebuchet.deg2rad(pars[2]), pars[3]))[2]
end
got this error:
julia> shoot'([5,55,200])
ERROR: Compiling Tuple{typeof(Trebuchet.shoot),Tuple{Int64,Float64,Int64}}: try/catch is not supported.