Skip to content

Allow structured parameter containers in ParamsWithStats#212

Merged
sunxd3 merged 5 commits into
mainfrom
sunxd/vnt-params
Jul 22, 2026
Merged

Allow structured parameter containers in ParamsWithStats#212
sunxd3 merged 5 commits into
mainfrom
sunxd/vnt-params

Conversation

@sunxd3

@sunxd3 sunxd3 commented Jul 13, 2026

Copy link
Copy Markdown
Member

ParamsWithStats required params to be a NamedTuple, so parameter containers with non-Symbol keys could not be stored without lossy conversion. This PR relaxes the struct to ParamsWithStats{P,S<:NamedTuple,E<:NamedTuple}: the parameter container can be any type implementing pairs and isempty, with keys that have a meaningful string form so name-based filtering and logging work. It also adds a two-argument constructor ParamsWithStats(params, stats) (empty extras) and documents that pairs(pws) may yield mixed key types, so consumers should iterate generically.

This is intended to be non-breaking: existing constructors and the Vector{<:Real}/Vector{<:Pair} normalizations are unchanged, and equality keeps the default struct behavior. Bumps the version to 5.16.0.

@github-actions

Copy link
Copy Markdown
Contributor

AbstractMCMC.jl documentation for PR #212 is available at:
https://TuringLang.github.io/AbstractMCMC.jl/previews/PR212/

The final assertion in the Equality testset used NaN-containing params, so
the params term already forced `==` to false regardless of extras — it never
actually tested that a differing field makes two wrappers unequal. Replace it
with a NaN-free comparison plus a matching equal case, and normalise `==`
formatting to blue style.

Co-Authored-By: Claude Code <noreply@anthropic.com>

@yebai yebai left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, @sunxd3 - good work!

sunxd3 added 2 commits July 22, 2026 09:29
…only

The wrapper keeps the default struct equality it had before this branch,
so the parameter container only needs to implement pairs and isempty.
Tests now use a VarName-like stand-in (StructuredKey/StructuredParams)
with non-Symbol keys and cover mixed-key iteration, NameFilter on
stringified keys, and container preservation through the extraction
constructor.
Merge the overlapping structured-params testsets, drop the StructuredState
wrapper by letting the container act as its own state, and simplify
StructuredParams to a concrete field. Same code paths covered with one
setup per testset.
@sunxd3

sunxd3 commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

This should allow us to start trying to use AbstractMCMC.ParamsWithStats in DynamicPPL (currently the two ParamsWithStats are different type).

@sunxd3
sunxd3 merged commit 974d1fb into main Jul 22, 2026
15 checks passed
@sunxd3
sunxd3 deleted the sunxd/vnt-params branch July 22, 2026 09:07
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