Skip to content

Makie interactivity #514

Open
Micki-D wants to merge 26 commits into
mainfrom
makie_recipies
Open

Makie interactivity #514
Micki-D wants to merge 26 commits into
mainfrom
makie_recipies

Conversation

@Micki-D

@Micki-D Micki-D commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

[Experimental][WIP] Add an extension for Makie.jl plotting

This is based on PR #477 using @philippeller 's custom Makie plotting but with dedicated BAT.jl infrastructure for handling the marginalization of samples.

This implements an extension module with reactive Makie.jl recipies that offer more flexible visualization and enable live plotting of MCMC data during sampling.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an experimental Makie.jl-based plotting/visualization extension to BAT, including a new BATVisualizer infrastructure that can be wired into MCMC sampling to enable live/interactive plotting.

Changes:

  • Introduces BATVisualizer / BATVisBackend and integrates it into BATContext, plus adds visualizer update hooks to the MCMC iteration loop.
  • Adds the BATMakieExt package extension and Makie “recipes” implemented via Makie’s ComputeGraph + SpecApi to render corner-style plots and overlays.
  • Adds helper utilities for marginalization/index selection and plumbs Makie extension debug logging.

Reviewed changes

Copilot reviewed 19 out of 23 changed files in this pull request and generated 24 comments.

Show a summary per file
File Description
src/utils/error_log.jl Adds BATMakieExt to debug logging module set; minor formatting.
src/samplers/mcmc/multi_cycle_burnin.jl Passes callback through to mcmc_iterate!! during burn-in cycles.
src/samplers/mcmc/mcmc_state.jl Mostly formatting/whitespace; no functional changes noted.
src/samplers/mcmc/mcmc_sample.jl Initializes/upgrades visualizer integration during sampling; adds output merge/append helpers.
src/samplers/mcmc/mcmc_algorithm.jl Adds update_visualizer + callback kwargs to mcmc_iterate!! and invokes them each step.
src/samplers/mcmc/chain_pool_init.jl Keyword formatting changes; no functional changes noted.
src/plotting/vsel_processing.jl Formatting changes; marginalization utilities unchanged logically.
src/plotting/valueshapes_utils_internal.jl Minor signature formatting; adjusts unshaped error message (currently buggy).
src/extdefs/makie_defs.jl Adds Makie-related public type/function stubs for the extension.
src/extdefs/extdefs.jl Includes makie_defs.jl.
src/algotypes/bat_visualizer.jl Introduces BATVisualizer and backend abstractions.
src/algotypes/bat_context.jl Adds visualizer::BATVisualizer to BATContext and updates constructors/helpers.
src/algotypes/algotypes.jl Includes new bat_visualizer.jl.
Project.toml Adds Makie as a weak dep + extension entry.
ext/BATMakieExt.jl New Makie extension module wiring in Makie impl files and defining extension entrypoint.
ext/makie_impl/makie_plotting.jl Includes Makie implementation files and imports Makie.
ext/makie_impl/bat_makie_recipe.jl Defines recipe/cell status machinery and generic API hooks.
ext/makie_impl/makie_visualizer.jl Implements the live Makie visualizer using ComputeGraph and async updates.
ext/makie_impl/makie_stats.jl Implements stats overlay recipes (mean/std/cov/errorbars/pdf) for Makie.
ext/makie_impl/makie_scatter.jl Implements scatter recipe.
ext/makie_impl/makie_kde.jl Implements KDE + quantile KDE recipes.
ext/makie_impl/makie_hist.jl Implements histogram + quantile histogram + hexbin recipes.
ext/makie_impl/makie_plot_samples.jl Adds a Makie recipe (convert_arguments) and a bat_makie_plot helper for samples.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 158 to +162
@debug "Merge samples of chains and transform to original space."

# close(context.visualizer.content.update_channel)
context.visualizer.content.is_live[] = false

return names[idx]
else
throw(ArgumentError("Samples are unshaped. Key :$name cannot be matched. Use index instead."))
throw(ArgumentError("Samples are unshaped. Key :$names cannot be matched. Use index instead."))
Comment on lines +10 to +12
) where {RS<:RecipeStatus,CS<:CellStatus}
return (x=SubArray(), y=SubArray(), weights=SubArray())
end
::CS,
::NamedTuple
) where {RS<:RecipeStatus,CS<:CellStatus}
return (xy_data=Vector{Point{2,Float32}}(), widths=Vector{Float64}, stairs_data=Vector{Point{2,Float32}}(), bin_colors=Vector{RGBA{Float32}}())
Comment on lines +108 to +112
heat = S.Heatmap(
centers_x, centers_y, weights;
alpha=alpha,
)
return [heat]
Comment on lines +529 to +538
(; buffer_lock, output_buffer, chain_ids, n_buffer_samples) = vis.content
output_id = findfirst(x -> x == chain_state.info.id, chain_ids)
n_smpls_start = sum(length.(output_buffer[output_id]))
get_samples!(output_buffer[output_id], chain_state, nonzero_weights)
n_smpls_end = sum(length.(output_buffer[output_id]))

lock(buffer_lock)
n_new = n_smpls_end - n_smpls_start
n_buffer_samples[] += n_new
unlock(buffer_lock)
vsel::Vector{<:Integer}=[1, 2, 3],
N_max::Integer=3,
)
triagonal_config = (
N_max::Integer=3,
)
# TODO: MD, Discuss config handling and passing of user attribute overwrites
triagonal_config = (
Comment on lines +147 to 156
init_visualizer!(context.visualizer; mcmc_states=mcmc_states, outputs=chain_outputs, f_pretransform=f_pretransform)

@info "Generate main samples using $(length(mcmc_states)) MCMC chain(s)."
mcmc_states = mcmc_iterate!!(
chain_outputs,
mcmc_states;
max_nsteps = samplingalg.nsteps,
nonzero_weights = samplingalg.nonzero_weights
max_nsteps=samplingalg.nsteps,
nonzero_weights=samplingalg.nonzero_weights,
update_visualizer=true # TODO: MD; discuss the whole update pipeline for visualizer
)
Comment on lines +346 to +350
(; nsigma) = config
w_prob = ProbabilityWeights(weights)
μ = mean(marg_coords, w_prob)
σ = std(marg_coords, w_prob)
return (μ=[μ], err=[σ * nsigma])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants