Skip to content

AbstractPPL 0.11 + change prefixing behaviour #830

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

Merged
merged 2 commits into from
Mar 28, 2025

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Mar 5, 2025

Update to AbstractPPL 0.11.

This version of AbstractPPL also lets us prefix variables in submodels differently (and, imo, more intuitively). Excerpt from the release notes:

using DynamicPPL, Distributions
@model inner() = x ~ Normal()
@model outer() = a ~ to_submodel(inner())

In previous versions, the inner variable x would be saved as a.x.
However, this was represented as a single symbol Symbol("a.x"):

julia> dump(keys(VarInfo(outer()))[1])
VarName{Symbol("a.x"), typeof(identity)}
  optic: identity (function of type typeof(identity))

Now, the inner variable is stored as a field x on the VarName a:

julia> dump(keys(VarInfo(outer()))[1])
VarName{:a, Accessors.PropertyLens{:x}}
  optic: Accessors.PropertyLens{:x} (@o _.x)

@penelopeysm penelopeysm changed the base branch from main to breaking March 5, 2025 11:45
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84.85%. Comparing base (324e623) to head (68e8c8e).
Report is 3 commits behind head on breaking.

Files with missing lines Patch % Lines
src/utils.jl 60.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           breaking     #830      +/-   ##
============================================
- Coverage     84.87%   84.85%   -0.02%     
============================================
  Files            34       34              
  Lines          3815     3817       +2     
============================================
+ Hits           3238     3239       +1     
- Misses          577      578       +1     

☔ 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.

@penelopeysm penelopeysm self-assigned this Mar 17, 2025
@penelopeysm penelopeysm force-pushed the py/abstractppl-0.11 branch 2 times, most recently from 73d000b to e6d84db Compare March 22, 2025 15:45
Copy link
Contributor

github-actions bot commented Mar 22, 2025

Benchmark Report for Commit 68e8c8e

Computer Information

Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 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 |                 10.1 |                 1.5 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                711.9 |                39.2 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                430.7 |                51.3 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1244.1 |                29.9 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               4001.6 |                20.8 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1487.2 |                29.0 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                963.6 |                 5.5 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5833.7 |                 4.0 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |               1165.9 |                 8.1 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              64168.0 |                 3.8 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               9510.1 |                11.6 |
|               Dynamic |        10 |    mooncake |             typed |   true |                145.5 |                12.0 |
|              Submodel |         1 |    mooncake |             typed |   true |                 26.9 |                 8.1 |
|                   LDA |        12 | reversediff |             typed |   true |                397.9 |                 7.2 |

@penelopeysm penelopeysm force-pushed the py/abstractppl-0.11 branch 2 times, most recently from 82462cd to 5d52f6b Compare March 22, 2025 21:25
@penelopeysm penelopeysm force-pushed the py/abstractppl-0.11 branch from 5d52f6b to cab48c6 Compare March 22, 2025 22:09
@penelopeysm penelopeysm requested a review from sunxd3 March 26, 2025 12:03
@penelopeysm penelopeysm marked this pull request as ready for review March 26, 2025 12:03
src/contexts.jl Outdated
Comment on lines 279 to 281
prefix(ctx::AbstractContext, vn::VarName) = prefix(NodeTrait(ctx), ctx, vn)
prefix(::IsLeaf, ::AbstractContext, vn::VarName) = vn
prefix(::IsParent, ctx::AbstractContext, vn::VarName) = prefix(childcontext(ctx), vn)
function prefix_with_context(ctx::AbstractContext, vn::VarName)
return prefix_with_context(NodeTrait(ctx), ctx, vn)
end
prefix_with_context(::IsLeaf, ::AbstractContext, vn::VarName) = vn
function prefix_with_context(::IsParent, ctx::AbstractContext, vn::VarName)
return prefix_with_context(childcontext(ctx), vn)
end
Copy link
Member Author

@penelopeysm penelopeysm Mar 26, 2025

Choose a reason for hiding this comment

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

I had to change the name of this function because Aqua was complaining about method ambiguities. I'm not entirely sure why but I think it's because AbstractPPL defines prefix(::VarName, ::VarName) and if we also defined prefix(::AbstractContext, ::VarName) here, it's probably something to do with the fact that AbstractContext is an abstract type. I still don't entirely see why this is a problem but changing the name did fix it 😅

Copy link
Member

Choose a reason for hiding this comment

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

Do we actually need

import AbstractPPL: predict, prefix

?

Copy link
Member

Choose a reason for hiding this comment

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

(I am thinking that maybe we don't need to extend AbstractPPL.prefix? Otherwise, the name prefix_with_context is fine.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ehhh, I think that's fair. I think I tried that route as well, and the only thing I didn't entirely like is that it means that in DynamicPPL we have to be explicit every time we write prefix - we would have to write either DynamicPPL.prefix or AbstractPPL.prefix. Do you have a preference?

(Personally, I actually think it's better if they are separate - semantically they are different things. Also, it's a nightmare trying to pull up docstrings for the right function when packages just keep extending it - this is the case with sample for example. But historically we have done a lot of this overloading-functions-from-base-packages thing so extending it was kind of in line with that.)

Copy link
Member

Choose a reason for hiding this comment

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

I prefer they have separate names -- not a huge fun of name overloading, I think this is abusing multiple dispatch. So totally agree with you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, we'll go with DynamicPPL.prefix :)

Copy link
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

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

otherwise looks good to me

@penelopeysm penelopeysm force-pushed the py/abstractppl-0.11 branch from a30a088 to 68e8c8e Compare March 28, 2025 15:53
@penelopeysm penelopeysm requested a review from sunxd3 March 28, 2025 16:35
Copy link
Member

@sunxd3 sunxd3 left a comment

Choose a reason for hiding this comment

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

Looks great!

@penelopeysm
Copy link
Member Author

Thanks :)

@penelopeysm penelopeysm merged commit fc32398 into breaking Mar 28, 2025
16 of 18 checks passed
@penelopeysm penelopeysm deleted the py/abstractppl-0.11 branch March 28, 2025 17:01
@penelopeysm penelopeysm mentioned this pull request Apr 8, 2025
8 tasks
github-merge-queue bot pushed a commit that referenced this pull request Apr 24, 2025
* Release 0.36

* AbstractPPL 0.11 + change prefixing behaviour (#830)

* AbstractPPL 0.11; change prefixing behaviour

* Use DynamicPPL.prefix rather than overloading

* Remove VarInfo(VarInfo, params) (#870)

* Unify `{untyped,typed}_{vector_,}varinfo` constructor functions (#879)

* Unify {Untyped,Typed}{Vector,}VarInfo constructors

* Update invocations

* NTVarInfo

* Fix tests

* More fixes

* Fixes

* Fixes

* Fixes

* Use lowercase functions, don't deprecate VarInfo

* Rewrite VarInfo docstring

* Fix methods

* Fix methods (really)

* Link varinfo by default in AD testing utilities; make test suite run on linked varinfos (#890)

* Link VarInfo by default

* Tweak interface

* Fix tests

* Fix interface so that callers can inspect results

* Document

* Fix tests

* Fix changelog

* Test linked varinfos

Closes #891

* Fix docstring + use AbstractFloat

* Fix `condition` and `fix` in submodels (#892)

* Fix conditioning in submodels

* Simplify contextual_isassumption

* Add documentation

* Fix some tests

* Add tests; fix a bunch of nested submodel issues

* Fix fix as well

* Fix doctests

* Add unit tests for new functions

* Add changelog entry

* Update changelog

Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>

* Finish docs

* Add a test for conditioning submodel via arguments

* Clean new tests up a bit

* Fix for VarNames with non-identity lenses

* Apply suggestions from code review

Co-authored-by: Markus Hauru <markus@mhauru.org>

* Apply suggestions from code review

* Make PrefixContext contain a varname rather than symbol (#896)

---------

Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Co-authored-by: Markus Hauru <markus@mhauru.org>

---------

Co-authored-by: Markus Hauru <mhauru@turing.ac.uk>
Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
Co-authored-by: Markus Hauru <markus@mhauru.org>
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