Migrate to ArviZ v1#31
Open
haeussma wants to merge 11 commits into
Open
Conversation
ArviZ v1 removed the "arviz-doc" matplotlib style and requires Python 3.12+. The style call was happening at import time in five package __init__.py files; drop it entirely rather than swap to a v1 style (users can apply their own style if they want one). Add h5netcdf so InferenceData.to_netcdf works out-of-the-box without the user installing a backend separately. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The repo's .gitignore excludes specs/. The previous commit (89f83bf) slipped in specs/update-arviz-v1.md; remove it from tracking. The file remains on disk locally for reference during the migration. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
az.hdi(...) renamed its credible-interval kwarg from hdi_prob to prob in ArviZ v1; switch the four internal call sites in Model.from_samples and Model.from_arviz. The public Catalax kwarg hdi_prob is preserved — only the inner call changes. Also retype Model.from_arviz's samples parameter as xarray.DataTree (the v1 replacement for arviz.InferenceData, which now just warns and aliases to DataTree). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Keep migration spec drafts and other working notes outside version control. Spawned from the ArviZ v1 migration work — specs/update-arviz-v1.md lives there for active reference but isn't repo content. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
az.plot_posterior is gone in ArviZ v1 — replace the internal call inside catalax's plot_posterior wrapper with az.plot_dist (the v1 distribution-plot replacement). The catalax public function name stays plot_posterior. az.plot_ess no longer supports kind="evolution" or the v0 color/extra_kwargs styling; swap the internal call inside catalax's plot_ess wrapper to az.plot_ess_evolution and drop the v0 styling overrides. v1 styling now flows through visuals= and is out of scope for this migration. az.summary renamed hdi_prob → ci_prob and changed its default ci_kind from "hdi" to "eti"; pass ci_prob=hdi_prob and ci_kind="hdi" to preserve v0 semantics. With ci_kind="hdi" and default fmt="wide", the return type narrows to pd.DataFrame — update annotation and drop the now-unused xarray import. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ArviZ v1's to_netcdf on an xarray.DataTree needs an explicit engine; pass "h5netcdf" since we already declare it as a dep. h5netcdf 1.8 stopped pulling in h5py automatically — add h5py to dependencies so the round-trip works on a fresh install. Also retire references to "arviz.InferenceData" in HMCResults docstrings; the v1 successor is xarray.DataTree. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
corner.corner() doesn't know about ArviZ v1's DataTree — it falls back to expecting a numpy array or DataFrame. v0 worked because corner had built-in interop with arviz.InferenceData. Stack the parameter samples into an (N, P) numpy array directly from mcmc.get_samples() and pass it with labels=. This drops the divergences=True overlay (no divergence info without a DataTree), which is an acceptable loss; it can be reintroduced once corner adds DataTree support upstream. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
az.hdi in ArviZ v1 requires at least a (chain, draw)-shaped input. mcmc.get_samples() returns a dict of flat 1-D arrays per parameter (no chain axis), which raises ValueError when handed straight to az.hdi. Add a leading singleton chain dim before the two az.hdi calls so the input is shaped (1, N). Downstream indexing (hdi[name][0], hdi[name][1]) is unchanged because az.hdi still emits a Dataset with a single ci_bound axis. Add a unit test that exercises the path with a synthetic 1-D dict to lock in the behaviour and catch any future regression. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
HMCResults docstrings still mentioned arviz.plot_posterior and hdi_prob kwargs that no longer exist in ArviZ v1; rewrite them to reference plot_dist and ci_probs. Narrow summary's return type to pd.DataFrame to match the wrapped call. Drop the now-unused xarray and Union imports. Bound h5py upper at <4 to match the project's pinning style. Bump README badge, prerequisites, and CI matrix from Python 3.11 to 3.12 since arviz>=1.1 requires 3.12+. Add trailing newline to .gitignore. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Removed the `corner` dependency from `pyproject.toml`. - Added `matplotlib` configuration for higher DPI in `catalax/__init__.py`. - Refactored `plot_corner` in `catalax/mcmc/plotting.py` to use `arviz.plot_pair` for improved visualization of posterior parameters, including KDE marginals and HDI intervals. - Updated `HMCResults.plot_corner` method to align with the new `plot_corner` signature and functionality. - Made minor adjustments to Jupyter notebooks to reflect execution count changes and added a new column for 'type' in data tables. This commit enhances the plotting capabilities and streamlines dependencies in preparation for future updates.
Bump the project version to 0.6.0 to reflect recent changes and improvements. This update ensures consistency across project files.
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.
Migrate to ArviZ v1
Why
In April 2026, ArviZ released v1.0 (Catalax currently pins v0.x). The
v1 release is a substantial rewrite that splits the package into
arviz-base,arviz-stats, andarviz-plots, and ships breaking changes tothe public API (
InferenceData→xarray.DataTree,hdi_prob→prob/ci_prob,plot_posterior→plot_dist,plot_ess(kind="evolution")→plot_ess_evolution, and so on). Pinning v0.x is no longer viable: itprevents Catalax from coexisting in the same environment as other Bayesian
modelling tools that have already migrated (notably Chromhander, which we
routinely use together with Catalax).
This PR migrates Catalax to ArviZ v1 so the library stays current and
installable alongside the wider ArviZ-v1 ecosystem.
Impact for Catalax users
entrypoints keep their existing signatures
(
HMCResults.plot_posterior(...),Model.from_samples(..., hdi_prob=...),summary(mcmc, hdi_prob=...), etc.). Existing notebooks and downstreamcode continue to work without edits.
requires Python ≥ 3.12, so we have no choice here. Bumping the floor is
necessary to make Catalax installable in the same environment as
Chromhander and other ArviZ-v1-based tools that are typically used
together with Catalax in a single venv.
What changed
Dependency / packaging
pyproject.tomlrequires-python = ">=3.12,<3.15"(was>=3.11).arviz>=1.1.0,<2.0(was>=0.22,<0.30).h5netcdf>=1.6.4,<2andh5py>=3.10,<4: ArviZ v1 writes NetCDFvia
h5netcdfand the latter no longer pulls inh5pyautomatically.corner>=2.2.2,<3: thecornerlibrary is not compatible withxarray.DataTree, so the pair plot is now built witharviz.plot_pair.README.md: badge, prerequisites and CI section updated to Python 3.12+..github/workflows/tests.yml: test matrix['3.12', '3.13'](dropped3.11).
.github/workflows/test-publish.yml: build runs on 3.12.Internal adaptation to ArviZ v1
Public Catalax signatures are unchanged; only the calls Catalax makes into
ArviZ were updated.
catalax/model/model.pysamples: az.InferenceData→samples: xarray.DataTree.az.hdi(..., hdi_prob=...)calls converted toaz.hdi(..., prob=...).Model.from_samplesnow reshapes raw 1-D dict samples to(1, -1)before passing to
az.hdi, becauseaz.hdiin v1 expects sampledimensions to be present. A regression test was added for this path
(
tests/unit/model/test_from_samples.py).catalax/mcmc/plotting.pyplot_posteriornow callsaz.plot_dist(v0az.plot_posteriorwasremoved in v1).
plot_essbody simplified to a directaz.plot_ess_evolution(...)call (v0plot_ess(kind="evolution")was removed in v1).summaryusesci_prob=hdi_prob, ci_kind="hdi"(v0hdi_probkwargwas renamed).
plot_cornerwas rewritten on top ofarviz.plot_pair:point-estimate text (controlled via
stats.ci_kind="hdi",stats.ci_prob=hdi_prob,stats.point_estimate="median"scoped viaaz.rc_contextso user rcParams are not modified).cmap="Blues",levels=6) with a thin matching contour line on top to hide softfill transitions, a faint grey scatter underlay so tail samples
outside the lowest contour remain visible, and divergent transitions
overlaid by
arviz.plot_pairitself.catalax/mcmc/results.pyto_netcdf(...)now passesengine="h5netcdf"(the defaultnetcdf4engine is no longer bundled with ArviZ v1).
arviz.plot_posterior→arviz.plot_dist,hdi_prob→
ci_probs,InferenceData→DataTree.catalax/__init__.py,catalax/dataset/__init__.py,catalax/mcmc/__init__.py,catalax/model/__init__.py,catalax/neural/__init__.pyimport arviz as az+az.style.use("arviz-doc")frompackage init modules (the v0 style is gone in v1 and we intentionally
do not override the user's matplotlib / arviz style).
catalax/__init__.pymatplotlib.rcParams["figure.dpi"] = 300andsavefig.dpi = 300so all plots Catalax produces (and saved files) render at 300 dpi.
Tests / examples
tests/unit/model/test_from_samples.pycovers thereshape path in
Model.from_samplesthat v1az.hdiforced.HMC.ipynb,InhomogeneousData.ipynb, etc.) werere-executed against ArviZ v1 and the resulting JSON /
.eqxartefactsrefreshed. Notebook code itself only changed where the Catalax API was
not the entrypoint (e.g. direct ArviZ calls inside the notebook).
Verification
uv run ruff check catalax tests— clean.uv run pytest -m "not expensive"— 62 passed, 2 deselected (= 64total, including the new
from_samplesregression test).examples/HMC.ipynbruns end-to-end onarviz==1.1.0.import catalaxproduces noFutureWarning/MigrationWarningfromArviZ.
Known minor visual differences
az.summarycolumn names changed upstream (hdi_2.5%→hdi95_lb).Visible in the summary DataFrame; unavoidable from the ArviZ side.
the
cornerlibrary, so styling is slightly different. The replacementshows the same information (HDI, median, divergences) and additionally
displays joint KDE density rather than just scatter clouds.