Skip to content

Move VarNamedTuple from DynamicPPL into AbstractPPL#178

Open
sunxd3 wants to merge 3 commits into
mainfrom
sunxd/varnamedtuple-migration
Open

Move VarNamedTuple from DynamicPPL into AbstractPPL#178
sunxd3 wants to merge 3 commits into
mainfrom
sunxd/varnamedtuple-migration

Conversation

@sunxd3

@sunxd3 sunxd3 commented Jul 13, 2026

Copy link
Copy Markdown
Member

Motivation

VarNamedTuple is a lossless, VarName-keyed parameter container that currently lives in DynamicPPL. Other frontends want to use it without depending on DynamicPPL's compiler stack: JuliaBUGS needs it to return structured samples (as AbstractMCMC.ParamsWithStats with VarNamedTuple parameters — companion PRs: TuringLang/AbstractMCMC.jl#212 and TuringLang/JuliaBUGS.jl#517), and FlexiChains' DynamicPPL extension already carries a TODO anticipating exactly this move.

VarNamedTuple is keyed by VarName and dispatches on AbstractPPL's optic types throughout, so it cannot live in a package below AbstractPPL; a standalone package would add a registry hop without decoupling anything. AbstractPPL is its natural home, and there is precedent — the of type system moved here from JuliaBUGS in 0.15.3.

What this PR does

  • Moves src/varnamedtuple.jl and src/varnamedtuple/ (VNT core, PartialArray/GrowableArray machinery, mapping/densification/skeleton helpers, @vnt, show methods) from DynamicPPL into AbstractPPL, with the full test suite carried over (test/varnamedtuple.jl, ~2,200 lines; export parity with DynamicPPL's copy verified).
  • New exports: VarNamedTuple, @vnt, map_pairs!!, map_values!!, apply!!, densify!!, skeleton, subset, NoTemplate, SkipTemplate. templated_setindex!! and the VarNamedTuples module are public but not exported, matching DynamicPPL.
  • ComponentArrays integration is provided by a new package extension (AbstractPPLComponentArraysExt).
  • The Distribution-aware hasvalue/getvalue methods (including the LKJCholesky reconstruction path) live in the existing Distributions package extension instead of being hard-wired, so the core gains no new dependency. Behavior is equivalent whenever Distributions is loaded.
  • Adds a docs page (docs/src/varnamedtuple.md) and a HISTORY.md entry.
  • Bumps the version to 0.16.0.

Intentional deltas from DynamicPPL's copy

Beyond namespacing, there are two deliberate differences — noted here so the follow-up DynamicPPL migration doesn't rediscover them as regressions:

  1. Base.similar(ga::GrowableArray, sz::Tuple) is narrowed to sz::Tuple{Vararg{Union{Integer,Base.OneTo}}} (DynamicPPL's copy accepts any Tuple).
  2. The Distribution-aware hasvalue/getvalue methods moved from hard-wired code into the Distributions package extension (see above).

A stale docstring advertising a nonexistent allow_new=Val(true) keyword was also fixed.

What might break

  • Nothing in the existing API. This release is purely additive over 0.15.4 — no existing name was removed or changed — so downstream packages can widen their compat bound to "0.15, 0.16" with zero code changes.
  • Export overlap with DynamicPPL (transitional). The ten new exports are names DynamicPPL currently also exports for its own copy of this functionality. Code that does using DynamicPPL, AbstractPPL (both unqualified) will see ambiguous bindings on use of those names once DynamicPPL's compat admits 0.16, until DynamicPPL migrates to re-export AbstractPPL's implementation. DynamicPPL itself is unaffected (its explicit imports shadow the implicit ones), and Turing imports AbstractPPL qualified, so it is unaffected too.
  • subset becomes a generic function here. DynamicPPL exports its own subset; its migration should extend AbstractPPL.subset rather than define a parallel function.

Suggested sequencing

  1. Merge and register this PR (AbstractPPL 0.16.0).
  2. FlexiChains widens its AbstractPPL compat (no code changes needed; unblocks JuliaBUGS's FlexiChains extension).
  3. JuliaBUGS PR adopting VarNamedTuple for structured sample output.
  4. DynamicPPL migration: delete its copy, use/re-export AbstractPPL's, merge its subset into AbstractPPL.subset, and move the remaining VNT design docs over. Until that lands, DynamicPPL's src/varnamedtuple/ is best treated as frozen, with fixes landing here first and back-ported as needed.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.85469% with 160 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.67%. Comparing base (b093e7d) to head (68b04e8).

Files with missing lines Patch % Lines
src/varnamedtuple/show.jl 0.00% 68 Missing ⚠️
src/varnamedtuple/partial_array.jl 85.85% 43 Missing ⚠️
src/varnamedtuple/getset.jl 89.59% 18 Missing ⚠️
src/varnamedtuple.jl 67.64% 11 Missing ⚠️
src/varnamedtuple/map.jl 94.95% 11 Missing ⚠️
src/varnamedtuple/macro.jl 89.13% 5 Missing ⚠️
ext/AbstractPPLDistributionsExt.jl 87.50% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
- Coverage   92.14%   89.67%   -2.47%     
==========================================
  Files          17       26       +9     
  Lines        2100     3090     +990     
==========================================
+ Hits         1935     2771     +836     
- Misses        165      319     +154     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

AbstractPPL.jl documentation for PR #178 is available at:
https://TuringLang.github.io/AbstractPPL.jl/previews/PR178/

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