Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing tonamedtuple #526

Merged
merged 6 commits into from
Sep 1, 2023
Merged

Replacing tonamedtuple #526

merged 6 commits into from
Sep 1, 2023

Conversation

torfjelde
Copy link
Member

This PR introduces varname_and_value_leaves which is similar to varname_leaves: it returns a flattened iterator over pairs (varname, value) in such a way that value is a Real.

See the docs for examples.

Equipped with this, we can effectively remove all usage of tonamedtuple in Turing.jl which has the benefits of:

  1. Simplification.
  2. Allows us to defer usage of strings until we convert to MCMCChains.Chains or similar (also opening the potential of maybe using VarName in place of strings to preserve more structure in the keys).

Together with #525 we this will allow significant simplifications in Turing.jl when it comes to moving from a Turing.Inference.Transition to MCMCChains.Chains (or similars) by using immutable invlink (introduced in #525) and varname_and_value_leaves (introduced in this PR).

@torfjelde torfjelde force-pushed the torfjelde/tonamedtuple-replacement branch from 0153a99 to 0f4914d Compare August 31, 2023 19:36
@torfjelde torfjelde force-pushed the torfjelde/tonamedtuple-replacement branch from 0f4914d to 5a43012 Compare August 31, 2023 19:39
@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.16% 🎉

Comparison is base (549d9b1) 80.40% compared to head (ba667dc) 80.56%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #526      +/-   ##
==========================================
+ Coverage   80.40%   80.56%   +0.16%     
==========================================
  Files          24       24              
  Lines        2776     2799      +23     
==========================================
+ Hits         2232     2255      +23     
  Misses        544      544              
Files Changed Coverage Δ
src/DynamicPPL.jl 100.00% <ø> (ø)
src/utils.jl 80.73% <100.00%> (+2.00%) ⬆️

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

@coveralls
Copy link

coveralls commented Aug 31, 2023

Pull Request Test Coverage Report for Build 6048260621

  • 23 of 23 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 80.564%

Totals Coverage Status
Change from base Build 6018544130: 0.2%
Covered Lines: 2255
Relevant Lines: 2799

💛 - Coveralls

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.

Good work - please take a look below for a few clarity comments.

"""
varname_and_value_leaves(vn::VarName, val)

Return an iterator over all varname-value pairs that are represented by `vn` on `val`.
Copy link
Member

@yebai yebai Sep 1, 2023

Choose a reason for hiding this comment

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

Suggested change
Return an iterator over all varname-value pairs that are represented by `vn` on `val`.
Return an iterator over all (varname::VarName, value::Real) pairs represented by `vn` on `val`. Common types for `val`, including Array, NamedTuple, Real and Cholesky, are supported by default. Handling for new types can be added by overloading `varname_and_value_leaves` methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I specifically didn't add any documentation about this, as we'd then also have to add docs to varname_and_value_leaves_inner.

IMO this should be a user-facing method and thus should be "simple" in what it describes (since we are exporting it). People who would potentially be interested in overloading this can eaisly just look at the source code and immediately understand that they need to overload varnames_and_value_leaves_inner for their type.

Copy link
Member Author

@torfjelde torfjelde Sep 1, 2023

Choose a reason for hiding this comment

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

And it doesn't always return (varname:::VarName, value::Real) btw; value could also be Missing.

src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@yebai yebai disabled auto-merge September 1, 2023 12:14
@yebai yebai enabled auto-merge September 1, 2023 12:14
@yebai
Copy link
Member

yebai commented Sep 1, 2023

Disabled and re-enabled auto merging after new commits.

@yebai yebai added this pull request to the merge queue Sep 1, 2023
Merged via the queue into master with commit 866eb6f Sep 1, 2023
13 of 14 checks passed
@yebai yebai deleted the torfjelde/tonamedtuple-replacement branch September 1, 2023 15:55
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.

None yet

3 participants