Skip to content

InitContext, part 2 - Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict #980

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

Draft
wants to merge 5 commits into
base: breaking
Choose a base branch
from

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jul 9, 2025

Part 1: Adding hasvalue and getvalue to AbstractPPL

This is Part 2/N of splitting #967 up into manageable bits.


In Part 1 we defined the following methods in AbstractPPL:

hasvalue(::NamedTuple, ::VarName[, ::Distribution])
hasvalue(::AbstractDict{<:VarName}, ::VarName[, ::Distribution])
getvalue(::NamedTuple, ::VarName[, ::Distribution])
getvalue(::AbstractDict{<:VarName}, ::VarName[, ::Distribution])

This PR removes them (and their helper functions) from the DynamicPPL codebase.

In DynamicPPL, their type bounds for Dict arguments were too lax: they used to take AbstractDict{<:Any} as the first argument. The AbstractPPL versions have tighter bounds. This PR therefore switches all overly-loosely-typed Dicts to use a key type of VarName.

Closes #791

@penelopeysm penelopeysm changed the base branch from main to breaking July 9, 2025 21:33
Copy link
Contributor

github-actions bot commented Jul 9, 2025

Benchmark Report for Commit 21cf568

Computer Information

Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 7763 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

Benchmark Results

|                 Model | Dimension |  AD Backend |      VarInfo Type | Linked | Eval Time / Ref Time | AD Time / Eval Time |
|-----------------------|-----------|-------------|-------------------|--------|----------------------|---------------------|
| Simple assume observe |         1 | forwarddiff |             typed |  false |                  8.2 |                 1.5 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                663.4 |                39.1 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                421.9 |                49.2 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |                977.4 |                36.4 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               6558.5 |                24.9 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1055.9 |                38.5 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |               1027.4 |                 4.2 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               6007.7 |                 3.9 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |                993.5 |                 9.0 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              67201.0 |                 3.5 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8456.2 |                 9.9 |
|               Dynamic |        10 |    mooncake |             typed |   true |                133.8 |                12.9 |
|              Submodel |         1 |    mooncake |             typed |   true |                 12.7 |                 6.3 |
|                   LDA |        12 | reversediff |             typed |   true |               1452.1 |                 1.7 |

Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.92%. Comparing base (2074657) to head (21cf568).

Additional details and impacted files
@@             Coverage Diff              @@
##           breaking     #980      +/-   ##
============================================
- Coverage     82.67%   81.92%   -0.75%     
============================================
  Files            38       37       -1     
  Lines          4022     3994      -28     
============================================
- Hits           3325     3272      -53     
- Misses          697      722      +25     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

github-actions bot commented Jul 9, 2025

DynamicPPL.jl documentation for PR #980 is available at:
https://TuringLang.github.io/DynamicPPL.jl/previews/PR980/

@penelopeysm penelopeysm changed the title Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict{VarName} instances InitContext II - Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict{VarName} instances Jul 10, 2025
@penelopeysm penelopeysm changed the title InitContext II - Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict{VarName} instances InitContext, part 2 - Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict{VarName} instances Jul 10, 2025
@penelopeysm penelopeysm changed the title InitContext, part 2 - Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict{VarName} instances InitContext, part 2 - Move hasvalue and getvalue to AbstractPPL; enforce key type of AbstractDict Jul 10, 2025
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.

key type of SimpleVarInfo is underfined
1 participant