Skip to content

Add some interface functions to support the new Gibbs sampler in Turing #280

Add some interface functions to support the new Gibbs sampler in Turing

Add some interface functions to support the new Gibbs sampler in Turing #280

Triggered via pull request October 1, 2024 17:25
Status Failure
Total duration 2m 45s
Artifacts

Docs.yml

on: pull_request
Fit to window
Zoom out
Zoom in

Annotations

9 errors, 2 warnings, and 1 notice
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:45-53 ```@example gibbs_example using AbstractMCMC: AbstractMCMC, LogDensityProblems # hide using Distributions # hide using Random # hide using AbstractMCMC: AbstractMCMC # hide using AbstractPPL: AbstractPPL # hide using BangBang: constructorof # hide using AbstractPPL: AbstractPPL ``` exception = ArgumentError: Package Distributions not found in current path. - Run `import Pkg; Pkg.add("Distributions")` to install the Distributions package. Stacktrace: [1] macro expansion @ ./loading.jl:1772 [inlined] [2] macro expansion @ ./lock.jl:267 [inlined] [3] __require(into::Module, mod::Symbol) @ Base ./loading.jl:1753 [4] #invoke_in_world#3 @ ./essentials.jl:926 [inlined] [5] invoke_in_world @ ./essentials.jl:923 [inlined] [6] require(into::Module, mod::Symbol) @ Base ./loading.jl:1746 [7] eval @ ./boot.jl:385 [inlined] [8] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [9] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [10] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [11] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [12] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [13] with_logger @ ./logging.jl:627 [inlined] [14] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [15] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:102-106 ```@example gibbs_example function AbstractPPL.condition(hn::HierNormal, conditioned_values::NamedTuple) return ConditionedHierNormal(hn.data, conditioned_values) end ``` exception = UndefVarError: `AbstractPPL` not defined Stacktrace: [1] top-level scope @ state_interface.md:103 [2] eval @ ./boot.jl:385 [inlined] [3] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [4] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [5] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [6] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [7] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [8] with_logger @ ./logging.jl:627 [inlined] [9] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [10] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:188-272 ```@example gibbs_example """ RandomWalkMH{T} <: AbstractMCMC.AbstractSampler A random walk Metropolis-Hastings sampler with a normal proposal distribution. The field σ is the standard deviation of the proposal distribution. """ struct RandomWalkMH{T} <: AbstractMHSampler σ::T end """ IndependentMH{T} <: AbstractMCMC.AbstractSampler A Metropolis-Hastings sampler with an independent proposal distribution. """ struct IndependentMH{T} <: AbstractMHSampler proposal_dist::T end # the first step of the sampler function AbstractMCMC.step( rng::AbstractRNG, logdensity_model::AbstractMCMC.LogDensityModel, sampler::AbstractMHSampler, args...; initial_params, kwargs..., ) logdensity_function = logdensity_model.logdensity transition = MHTransition(initial_params) state = MHState( initial_params, only(LogDensityProblems.logdensity(logdensity_function, initial_params)), ) return transition, state end @inline get_proposal_dist(sampler::RandomWalkMH, current_params::Vector{Float64}) = MvNormal(current_params, sampler.σ) @inline get_proposal_dist(sampler::IndependentMH, current_params::Vector{T}) where {T} = sampler.proposal_dist # the subsequent steps of the sampler function AbstractMCMC.step( rng::AbstractRNG, logdensity_model::AbstractMCMC.LogDensityModel, sampler::AbstractMHSampler, state::MHState, args...; kwargs..., ) logdensity_function = logdensity_model.logdensity current_params = state.params proposal_dist = get_proposal_dist(sampler, current_params) proposed_params = rand(rng, proposal_dist) logp_proposal = only( LogDensityProblems.logdensity(logdensity_function, proposed_params) ) if log(rand(rng)) < compute_log_acceptance_ratio(sampler, state, proposed_params, logp_proposal) return MHTransition(proposed_params), MHState(proposed_params, logp_proposal) else return MHTransition(current_params), MHState(current_params, state.logp) end end function compute_log_acceptance_ratio( ::RandomWalkMH, state::MHState, ::Vector{Float64}, logp_proposal::Float64 ) return min(0, logp_proposal - state.logp) end function compute_log_acceptance_ratio( sampler::IndependentMH, state::MHState, proposal::Vector{T}, logp_proposal::Float64 ) where {T} return min( 0, logp_proposal - state.logp + logpdf(sampler.proposal_dist, state.params) - logpdf(sampler.proposal_dist, proposal), ) end ``` exception = UndefVarError: `AbstractMHSampler` not defined Stacktrace: [1] top-level scope @ state_interface.md:189 [2] eval @ ./boot.jl:385 [inlined] [3] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [4] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [5] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [6] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [7] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [8] with_logger @ ./logging.jl:627 [inlined] [9] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [10] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:276-430 ```@example gibbs_example struct Gibbs{T<:NamedTuple} <: AbstractMCMC.AbstractSampler "Maps variables to their samplers." sampler_map::T end struct GibbsState{TraceNT<:NamedTuple,StateNT<:NamedTuple,SizeNT<:NamedTuple} "Contains the values of all parameters up to the last iteration." trace::TraceNT "Maps parameters to their sampler-specific MCMC states." mcmc_states::StateNT "Maps parameters to their sizes." variable_sizes::SizeNT end struct GibbsTransition{ValuesNT<:NamedTuple} "Realizations of the parameters, this is considered a \"sample\" in the MCMC chain." values::ValuesNT end """ update_trace(trace::NamedTuple, gibbs_state::GibbsState) Update the trace with the values from the MCMC states of the sub-problems. """ function update_trace( trace::NamedTuple{trace_names}, gibbs_state::GibbsState{TraceNT,StateNT,SizeNT} ) where {trace_names,TraceNT,StateNT,SizeNT} for parameter_variable in fieldnames(StateNT) sub_state = gibbs_state.mcmc_states[parameter_variable] sub_state_params_values = Base.vec(sub_state) reshaped_sub_state_params_values = reshape( sub_state_params_values, gibbs_state.variable_sizes[parameter_variable] ) unflattened_sub_state_params = NamedTuple{(parameter_variable,)}(( reshaped_sub_state_params_values, )) trace = merge(trace, unflattened_sub_state_params) end return trace end function error_if_not_fully_initialized( initial_params::NamedTuple{ParamNames}, sampler::Gibbs{<:NamedTuple{SamplerNames}} ) where {ParamNames,SamplerNames} if Set(ParamNames) != Set(SamplerNames) throw( ArgumentError( "initial_params must contain all parameters in the model, expected $(SamplerNames), got $(ParamNames)", ), ) end end function AbstractMCMC.step( rng::Random.AbstractRNG, logdensity_model::AbstractMCMC.LogDensityModel, sampler::Gibbs{Tsamplingmap}; initial_params::NamedTuple, kwargs..., ) where {Tsamplingmap} error_if_not_fully_initialized(initial_params, sampler) model_parameter_names = fieldnames(Tsamplingmap) results = map(model_parameter_names) do parameter_variable sub_sampler = sampler.sampler_map[parameter_variable] variables_to_be_conditioned_on = setdiff( model_parameter_names, (parameter_variable,) ) conditioning_variables_values = NamedTuple{Tuple(variables_to_be_conditioned_on)}( Tuple([initial_params[g] for g in variables_to_be_conditioned_on]) ) # LogDensityProblems' `logdensity` function expects a single vector of real numbers # `Gibbs` stores the parameters as a named tuple, thus we need to flatten the sub_problem_parameters_values # and unflatten after the sampling step flattened_sub_problem_parameters_values = vec(initial_params[parameter_variable]) sub_logdensity_model = AbstractMCMC.LogDensityModel( AbstractPPL.condition( logdensity_model.logdensity, conditioning_variables_values ), ) sub_state = last( AbstractMCMC.step( rng, sub_logdensity_model, sub_sampler; initial_params=flattened_sub_problem_parameters_values, kwargs..., ), ) (sub_state, size(initial_params[parameter_variable])) end mcmc_states_tuple = first.(results) variable_sizes_tuple = last.(results) gibbs_state = GibbsState( initial_params, NamedTuple{Tuple(model_parameter_names)}(mcmc_states_tuple), NamedTuple{Tuple(model_parameter_names)}(variable_sizes_tuple), ) trace = update_trace(NamedTuple(), gibbs_state) return GibbsTransition(trace), gibbs_state end # subsequent steps function AbstractMCMC.step( rng::Random.AbstractRNG, logdensity_model::AbstractMCMC.LogDensityModel, sam
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:465-471 ```@example gibbs_example N = 100 # Number of data points mu_true = 0.5 # True mean tau2_true = 2.0 # True variance x_data = rand(Normal(mu_true, sqrt(tau2_true)), N) ``` exception = UndefVarError: `Normal` not defined Stacktrace: [1] top-level scope @ state_interface.md:470 [2] eval @ ./boot.jl:385 [inlined] [3] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [4] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [5] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [6] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [7] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [8] with_logger @ ./logging.jl:627 [inlined] [9] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [10] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:475-477 ```@example gibbs_example hn = HierNormal((x=x_data,)) ``` exception = UndefVarError: `x_data` not defined Stacktrace: [1] top-level scope @ state_interface.md:476 [2] eval @ ./boot.jl:385 [inlined] [3] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [4] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [5] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [6] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [7] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [8] with_logger @ ./logging.jl:627 [inlined] [9] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [10] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:481-491 ```@example gibbs_example samples = sample( hn, Gibbs(( mu=RandomWalkMH(0.3), tau2=IndependentMH(product_distribution([InverseGamma(1, 1)])), )), 10000; initial_params=(mu=[0.0], tau2=[1.0]), ) ``` exception = UndefVarError: `RandomWalkMH` not defined Stacktrace: [1] top-level scope @ state_interface.md:482 [2] eval @ ./boot.jl:385 [inlined] [3] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [4] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [5] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [6] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [7] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [8] with_logger @ ./logging.jl:627 [inlined] [9] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [10] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build: ../../../.julia/packages/Documenter/C1XEF/src/utilities/utilities.jl#L44
failed to run `@example` block in src/state_interface.md:495-502 ```@example gibbs_example mu_samples = [sample.values.mu for sample in samples][20001:end] tau2_samples = [sample.values.tau2 for sample in samples][20001:end] mean(mu_samples) mean(tau2_samples) (mu_mean, tau2_mean) ``` exception = UndefVarError: `samples` not defined Stacktrace: [1] top-level scope @ state_interface.md:496 [2] eval @ ./boot.jl:385 [inlined] [3] #60 @ ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:754 [inlined] [4] cd(f::Documenter.var"#60#62"{Module, Expr}, dir::String) @ Base.Filesystem ./file.jl:112 [5] (::Documenter.var"#59#61"{Documenter.Page, Module, Expr})() @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:753 [6] (::IOCapture.var"#5#9"{DataType, Documenter.var"#59#61"{Documenter.Page, Module, Expr}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}, IOContext{Base.PipeEndpoint}})() @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:170 [7] with_logstate(f::Function, logstate::Any) @ Base.CoreLogging ./logging.jl:515 [8] with_logger @ ./logging.jl:627 [inlined] [9] capture(f::Documenter.var"#59#61"{Documenter.Page, Module, Expr}; rethrow::Type, color::Bool, passthrough::Bool, capture_buffer::IOBuffer, io_context::Vector{Any}) @ IOCapture ~/.julia/packages/IOCapture/Y5rEA/src/IOCapture.jl:167 [10] runner(::Type{Documenter.Expanders.ExampleBlocks}, node::MarkdownAST.Node{Nothing}, page::Documenter.Page, doc::Documenter.Document) @ Documenter ~/.julia/packages/Documenter/C1XEF/src/expander_pipeline.jl:752
build
Process completed with exit code 1.
build
The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/
build
The following actions use a deprecated Node.js version and will be forced to run on node20: actions/checkout@v2, julia-actions/setup-julia@v1. For more info: https://github.blog/changelog/2024-03-07-github-actions-all-actions-will-run-on-node20-instead-of-node16-by-default/
[julia-buildpkg] Caching of the julia depot was not detected
Consider using `julia-actions/cache` to speed up runs https://github.com/julia-actions/cache. To ignore, set input `ignore-no-cache: true`