JuliaGaussianProcesses / Stheno.jl

Probabilistic Programming with Gaussian processes in Julia
Other
338 stars 26 forks source link

"Getting started" example fails #241

Closed martincornejo closed 1 year ago

martincornejo commented 1 year ago

The getting tarted examples from the documentation currently fail for me.

I get the following error in the Optim-BFGS example:

Stacktrace ``` ERROR: MethodError: objects of type Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}} are not callable Stacktrace: [1] macro expansion @ C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [inlined] [2] _pullback(ctx::Zygote.Context{false}, f::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, args::Float64) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:9 [3] rrule_via_ad(::Zygote.ZygoteRuleConfig{Zygote.Context{false}}, ::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\chainrules.jl:260 [4] rrule_via_ad(::Zygote.ZygoteRuleConfig{Zygote.Context{false}}, ::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, ::Vararg{Any}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\chainrules.jl:248 [5] (::ChainRules.var"#1664#1669"{Zygote.ZygoteRuleConfig{Zygote.Context{false}}, Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}})(xᵢ::Float64) @ ChainRules .\none:0 [6] iterate @ .\generator.jl:47 [inlined] [7] collect @ .\array.jl:787 [inlined] [8] rrule(config::Zygote.ZygoteRuleConfig{Zygote.Context{false}}, ::typeof(sum), f::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, xs::Vector{Float64}; dims::Function) @ ChainRules C:\Users\Cornejo\.julia\packages\ChainRules\bEtjZ\src\rulesets\Base\mapreduce.jl:102 [9] rrule(config::Zygote.ZygoteRuleConfig{Zygote.Context{false}}, ::typeof(mean), f::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, x::Vector{Float64}; dims::Function) @ ChainRules C:\Users\Cornejo\.julia\packages\ChainRules\bEtjZ\src\rulesets\Statistics\statistics.jl:28 [10] rrule(config::Zygote.ZygoteRuleConfig{Zygote.Context{false}}, ::typeof(mean), f::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, x::Vector{Float64}) @ ChainRules C:\Users\Cornejo\.julia\packages\ChainRules\bEtjZ\src\rulesets\Statistics\statistics.jl:21 [11] chain_rrule @ C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\chainrules.jl:223 [inlined] [12] macro expansion @ C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [inlined] [13] _pullback(::Zygote.Context{false}, ::typeof(mean), ::Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}, ::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:9 [14] _pullback @ C:\Users\Cornejo\.julia\packages\Stheno\b3pUJ\src\gp\derived_gp.jl:19 [inlined] [15] _pullback(::Zygote.Context{false}, ::typeof(mean), ::Stheno.DerivedGP{Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}}, ::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [16] _pullback @ C:\Users\Cornejo\.julia\packages\AbstractGPs\agvD4\src\abstract_gp.jl:56 [inlined] [17] _pullback(::Zygote.Context{false}, ::typeof(mean_and_cov), ::Stheno.DerivedGP{Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}}, ::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [18] _pullback @ C:\Users\Cornejo\.julia\packages\Stheno\b3pUJ\src\gaussian_process_probabilistic_programme.jl:74 [inlined] [19] _pullback(::Zygote.Context{false}, ::typeof(mean_and_cov), ::Stheno.GaussianProcessProbabilisticProgramme{NamedTuple{(:f1, :f2, :f3), Tuple{Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}}}}}, ::GPPPInput{Symbol, Float64, Vector{Float64}}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [20] _pullback @ C:\Users\Cornejo\.julia\packages\AbstractGPs\agvD4\src\finite_gp_projection.jl:134 [inlined] [21] _pullback(ctx::Zygote.Context{false}, f::typeof(mean_and_cov), args::AbstractGPs.FiniteGP{Stheno.GaussianProcessProbabilisticProgramme{NamedTuple{(:f1, :f2, :f3), Tuple{Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}}}}}, GPPPInput{Symbol, Float64, Vector{Float64}}, Diagonal{Float64, FillArrays.Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}}}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [22] _pullback @ C:\Users\Cornejo\.julia\packages\AbstractGPs\agvD4\src\finite_gp_projection.jl:307 [inlined] [23] _pullback(::Zygote.Context{false}, ::typeof(logpdf), ::AbstractGPs.FiniteGP{Stheno.GaussianProcessProbabilisticProgramme{NamedTuple{(:f1, :f2, :f3), Tuple{Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(+), Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}, Stheno.DerivedGP{Tuple{typeof(*), Float64, Stheno.DerivedGP{Tuple{typeof(∘), Stheno.AtomicGP{GP{ZeroMean{Float64}, SqExponentialKernel{Distances.Euclidean}}}, Stheno.Stretch{Float64}}}}}}}}}}, GPPPInput{Symbol, Float64, Vector{Float64}}, Diagonal{Float64, FillArrays.Fill{Float64, 1, Tuple{Base.OneTo{Int64}}}}}, ::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [24] _pullback @ c:\Users\Cornejo\Documents\GitHub\stheno-examples\inference.jl:94 [inlined] [25] _pullback(ctx::Zygote.Context{false}, f::typeof(nlml), args::NamedTuple{(:l1, :s1, :l2, :s2, :s_noise), NTuple{5, Float64}}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [26] _pullback @ .\operators.jl:1030 [inlined] [27] _pullback(::Zygote.Context{false}, ::Base.var"##_#95", ::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, ::ComposedFunction{typeof(nlml), ComposedFunction{typeof(value), ParameterHandling.var"#unflatten_to_NamedTuple#16"{Float64, NamedTuple{(:l1, :s1, :l2, :s2, :s_noise), NTuple{5, ParameterHandling.Positive{Float64, typeof(exp), Float64}}}, ParameterHandling.var"#unflatten_to_Tuple#14"{Float64, NTuple{5, Int64}, NTuple{5, Int64}, NTuple{5, ParameterHandling.var"#unflatten_Positive#24"{Float64, ParameterHandling.Positive{Float64, typeof(exp), Float64}, ParameterHandling.var"#unflatten_to_Real#2"{Float64, Float64}}}}}}}, ::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [28] _apply @ .\boot.jl:816 [inlined] [29] adjoint @ C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\lib\lib.jl:203 [inlined] [30] _pullback @ C:\Users\Cornejo\.julia\packages\ZygoteRules\OgCVT\src\adjoint.jl:66 [inlined] [31] _pullback @ .\operators.jl:1030 [inlined] [32] _pullback(ctx::Zygote.Context{false}, f::ComposedFunction{typeof(nlml), ComposedFunction{typeof(value), ParameterHandling.var"#unflatten_to_NamedTuple#16"{Float64, NamedTuple{(:l1, :s1, :l2, :s2, :s_noise), NTuple{5, ParameterHandling.Positive{Float64, typeof(exp), Float64}}}, ParameterHandling.var"#unflatten_to_Tuple#14"{Float64, NTuple{5, Int64}, NTuple{5, Int64}, NTuple{5, ParameterHandling.var"#unflatten_Positive#24"{Float64, ParameterHandling.Positive{Float64, typeof(exp), Float64}, ParameterHandling.var"#unflatten_to_Real#2"{Float64, Float64}}}}}}}, args::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface2.jl:0 [33] pullback(f::Function, cx::Zygote.Context{false}, args::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface.jl:44 [34] pullback @ C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface.jl:42 [inlined] [35] gradient(f::Function, args::Vector{Float64}) @ Zygote C:\Users\Cornejo\.julia\packages\Zygote\SuKWp\src\compiler\interface.jl:96 [36] (::var"#33#34")(θ::Vector{Float64}) @ Main c:\Users\Cornejo\Documents\GitHub\stheno-examples\inference.jl:100 [37] (::NLSolversBase.var"#gg!#2"{var"#33#34"})(G::Vector{Float64}, x::Vector{Float64}) @ NLSolversBase C:\Users\Cornejo\.julia\packages\NLSolversBase\kavn7\src\objective_types\inplace_factory.jl:21 [38] (::NLSolversBase.var"#fg!#8"{ComposedFunction{typeof(nlml), ComposedFunction{typeof(value), ParameterHandling.var"#unflatten_to_NamedTuple#16"{Float64, NamedTuple{(:l1, :s1, :l2, :s2, :s_noise), NTuple{5, ParameterHandling.Positive{Float64, typeof(exp), Float64}}}, ParameterHandling.var"#unflatten_to_Tuple#14"{Float64, NTuple{5, Int64}, NTuple{5, Int64}, NTuple{5, ParameterHandling.var"#unflatten_Positive#24"{Float64, ParameterHandling.Positive{Float64, typeof(exp), Float64}, ParameterHandling.var"#unflatten_to_Real#2"{Float64, Float64}}}}}}}, NLSolversBase.var"#gg!#2"{var"#33#34"}})(gx::Vector{Float64}, x::Vector{Float64}) @ NLSolversBase C:\Users\Cornejo\.julia\packages\NLSolversBase\kavn7\src\objective_types\abstract.jl:13 [39] value_gradient!!(obj::OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, x::Vector{Float64}) @ NLSolversBase C:\Users\Cornejo\.julia\packages\NLSolversBase\kavn7\src\interface.jl:82 [40] initial_state(method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, options::Optim.Options{Float64, Nothing}, d::OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, initial_x::Vector{Float64}) @ Optim C:\Users\Cornejo\.julia\packages\Optim\29per\src\multivariate\solvers\first_order\bfgs.jl:94 [41] optimize @ C:\Users\Cornejo\.julia\packages\Optim\29per\src\multivariate\optimize\optimize.jl:36 [inlined] [42] optimize(f::Function, g::Function, initial_x::Vector{Float64}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, options::Optim.Options{Float64, Nothing}; inplace::Bool, autodiff::Symbol) @ Optim C:\Users\Cornejo\.julia\packages\Optim\29per\src\multivariate\optimize\interface.jl:156 [43] top-level scope @ c:\Users\Cornejo\Documents\GitHub\stheno-examples\inference.jl:98 ```

And a similar error in the AdvancedHMC example.

Here is my current environment:

(stheno-examples) pkg> st
Status `C:\Users\Cornejo\Documents\GitHub\stheno-examples\Project.toml`
  [99985d1d] AbstractGPs v0.5.16
  [0bf59076] AdvancedHMC v0.4.5
  [429524aa] Optim v1.7.5
  [2412ca09] ParameterHandling v0.4.6
  [91a5bcdd] Plots v1.38.9
  [8188c328] Stheno v0.8.1
  [e88e6eb3] Zygote v0.6.60
willtebbutt commented 1 year ago

This is unfortunate -- thanks for opening the issue. Will look into this today

martincornejo commented 1 year ago

Could you reproduce the errors? Unfortunately the stacktrace shows some obscure Zygote magic, else I would try to debug them myself.

willtebbutt commented 1 year ago

@martincornejo could you confirm that #244 solves this?

martincornejo commented 1 year ago

Solved. Thanks!