Skip to content

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Oct 10, 2025

This PR adds some private sections of the AbstractChains interface.

The current interface consists of three things: the AbstractChains abstract type, chainscat, and chainsstack. These are preserved as part of the public interface, which can be directly accessed as AbstractMCMC.(...) and are in src/chains.jl.

The new portion of the interface contains a number of new functions which are explicitly considered experimental and thus subject to change (see the docstrings). These must all be accessed via AbstractMCMC.Chains.(...) and are in src/experimental/chains.jl.

Since nothing here is breaking (none of the existing tests failed, I added one more test for the AbstractChains interface) it's just a minor version bump.

This PR alone will resolve the immediate name conflicts arising from plotting functions TuringLang/Turing.jl#2681 (we don't need to have concrete implementations of them, we just need to have a shared function exported from one place).

@penelopeysm
Copy link
Member Author

@yebai Tagging you for overall comments on the approach.

Copy link
Contributor

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

Copy link
Member

@yebai yebai left a comment

Choose a reason for hiding this comment

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

Thanks, @penelopeysm —I left a few comments below.

using Test

"""
AbstractMCMC.Chains.get_data(chn, key)
Copy link
Member

Choose a reason for hiding this comment

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

Since this function always returns AbstractMatrix, maybe rename it to to_array for clarity:

Suggested change
AbstractMCMC.Chains.get_data(chn, key)
AbstractMCMC.Chains.to_array(chn, key)

Copy link
Member Author

Choose a reason for hiding this comment

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

It's more like a dictionary get because it requires a key. IMO, to_array sounds like you're converting the entire chain to an array.

"""
AbstractMCMC.Chains.iter_indices(chn)

Obtain the indices of each iteration for the `AbstractChains` object `chn`.
Copy link
Member

Choose a reason for hiding this comment

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

This is not very clear to me. Maybe add a working example to this and related APIs below for readability?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really see how to add an example without a concrete implementation. I'll flesh out the docstring though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added more words!

end
end

# Plotting functions; to be extended by individual chain libraries
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we want to define the plotting APIs in AbstractMCMC. Let's focus on Chain type and core interface only.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem here is if AbstractMCMC owns the chains type, then any plotting recipe that uses it also has to belong in AbstractMCMC. Otherwise, if you shifted the plotting functionality to a separate library, then defining something like plot(chn::AbstractChains) or density(chn::AbstractChains) would be type piracy, since AbstractChains is owned by AbstractMCMC.jl, and plot or density are owned by Plots.jl. This is the same issue that ChainsMakie has/had. If you wanted to move the plotting functionality to a separate library, then I would strongly suggest that everything should be in that separate library i.e. just make AbstractChains.jl hold all of it.

Of course, there are differing levels of type piracy. Maybe it's not so bad for a package in TuringLang to pirate a type that is owned by a separate package in TuringLang. But I still think it's bad.

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