Skip to content

Feature cmdstan version 2.0#181

Closed
Nathaniel-Haines wants to merge 5 commits into
CCS-Lab:masterfrom
Nathaniel-Haines:feature-cmdstan-version-2.0
Closed

Feature cmdstan version 2.0#181
Nathaniel-Haines wants to merge 5 commits into
CCS-Lab:masterfrom
Nathaniel-Haines:feature-cmdstan-version-2.0

Conversation

@Nathaniel-Haines

Copy link
Copy Markdown
Member

hBayesDM 2.0 — modernize stack & toolchain

Top-to-bottom refactor of both the R and Python packages onto
current Stan tooling, plus the supporting work to keep behavior, docs, and
CI in sync.

Highlights

  • Stan backend: rstan → cmdstanr (R) and pystan →
    cmdstanpy (Python).
    CmdStan is now a system dependency installed once via
    cmdstanr::install_cmdstan() /
    cmdstanpy.install_cmdstan(). No install-time
    precompilation; models compile on first use (~30 s) and the
    binary is cached.
  • Languages: R ≥ 4.4, Python ≥ 3.13, pinned in
    .tool-versions.
  • Python tooling: poetry → uv + hatchling
    (Python/pyproject.toml).
  • Stan files: canonicalized (array[N, T] real x, abs
    for fabs) across all 66 models.
  • arviz updated to the post-1.0 API (DataTree,
    plot_dist, ci_prob, LOO-only extract_ic).

Breaking changes

  • result$fit (R) / model.fit (Python) is now a
    CmdStanMCMC/CmdStanVB
    object, not rstan::stanfit. Replace rstan::extract(fit)
    with
    posterior::as_draws_*(fit$draws()) or use the
    already-extracted parVals/par_vals.
  • BUILD_ALL=true install-time precompile flag removed.
  • Python now requires 3.13+; R requires 4.4+.

Latent bugs fixed (no test previously)

  • R additional_args: args[[nm]] <- NULL was deleting
    entries with
    NULL defaults (e.g. banditNarm_2par_lapse Narm,
    pstRT_ddm initQ).
    Switched to args[nm] <- list(NULL) so the entry is
    preserved.
  • R rhat(): name collision with posterior::rhat caused
    cmdstanr's
    $summary("rhat", ...) to recurse into hBayesDM's own
    rhat. Now binds
    posterior::rhat to a local symbol and passes by value.
  • Python vb=True: dict inits were being passed to
    cmdstanpy.variational(), which only accepts
    Optional[float]. Inits are
    now dropped on the VB branch.
  • Python VB idata: was using stan_variables()
    (variational means) and
    producing 1-D arrays. Now uses stan_variables(mean=False)
    for the
    variational sample matrix.

Tests

  • New tests/test_user_facing.{py,R} — fits one small model
    (dd_hyperbolic)
    and exercises plotting (dist/trace/simple), plot_ind,
    rhat,
    extract_ic, print_fit, HDI helpers, plus gng_m1 for
    model_regressor
    and dd_hyperbolic(vb=TRUE) for the VB path.
  • Per-model smoke tests under tests/test_<model>.{py,R}
    unchanged.
  • All 15 Python + 42 R user-facing tests pass.

Docs

  • R/man-roxygen/model-documentation.Rfit description
    updated to
    CmdStanMCMC/CmdStanVB; first-fit compile note added. All
    68 R/man/*.Rd
    regenerated via roxygen2.
  • R/README.Rmd, Python/README.rst, top-level README.md
    install
    instructions, prerequisites, Python/R version requirements.
  • R/NEWS.md — 2.0 entry with breaking changes and migration
    snippets.
  • R/vignettes/getting_started.Rmd — full pass: install steps,
    fitting
    walkthrough, console output, post-fit object description,
    Section 3 plotting
    rewritten around bayesplot, Section 6 VB pointing at
    cmdstanr.
  • R/vignettes/hgf_tutorial.Rmd — link fix.
  • R/cran-comments.md — refreshed for 2.0 submission story.
  • Python/docs/{requirements.txt,conf.py} and
    .readthedocs.yml — bumped to
    Python 3.13 + arviz ≥ 0.20.

CI/CD

  • Removed: .travis.yml and travis/ (xenial, Python
    3.6–3.8, poetry,
    unmaintained). Travis ran R CMD check --no-tests and only
    one Python test.
  • Added .github/workflows/R.yaml — Ubuntu, R 4.4, cached
    CmdStan,
    R CMD check + test_user_facing.R, codecov upload.
  • Added .github/workflows/Python.yaml — Ubuntu + macOS,
    Python 3.13 via
    uv, cached CmdStan, ruff + test_user_facing.py + 2
    representative model
    smoke tests.
  • Updated pkgdown.yaml — pinned R 4.4, installs cmdstanr
    so vignettes
    can re-render in CI.
  • README badges swapped from Travis to the two new GH Actions
    workflows.

Repo hygiene

  • New CLAUDE.md at repo root: layout, toolchain, conventions,
    gotchas
    (additional_args plumbing, the rhat name collision, VB
    inits / sample
    matrix), and the dev loop.
  • Migration-flavored prose stripped from in-code comments —
    comments now
    describe current behavior only; history lives in NEWS.md
    and git log.

Test plan

  • cd Python && uv run pytest tests/test_user_facing.py
    (15/15 pass)
  • NOT_CRAN=true Rscript -e 'testthat::test_file("R/tests/testthat/test_user_facing.R")'
    (42/42 pass)
  • R CMD INSTALL --no-docs --no-test-load R (clean)
  • roxygen2::roxygenize("R") regenerates man pages without
    errors
  • rmarkdown::render("R/vignettes/getting_started.Rmd")
    builds
  • rmarkdown::render("R/vignettes/hgf_tutorial.Rmd")
    builds
  • First push: confirm the new GH Actions workflows are
    green on a real run

Nathaniel-Haines and others added 5 commits May 4, 2026 09:12
Remove three working planning documents from the tracked tree. Files remain
on disk locally but are no longer part of the repository going forward.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.

1 participant