Makie interactivity #514
Open
Micki-D wants to merge 26 commits into
Open
Conversation
…() for density samples
There was a problem hiding this comment.
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/BATVisBackendand integrates it intoBATContext, plus adds visualizer update hooks to the MCMC iteration loop. - Adds the
BATMakieExtpackage extension and Makie “recipes” implemented via Makie’sComputeGraph+SpecApito 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[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.