Skip to content

Unify {untyped,typed}_{vector_,}varinfo constructor functions #879

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 12 commits into from
Apr 9, 2025

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Apr 1, 2025

Partly solves #862 (There's still the SimpleVarInfos; but this PR is big enough).

Why

There are a couple of issues that this PR attempts to solve.

First is the ambiguous meaning of TypedVarInfo. Its literal definition is:

const TypedVarInfo = VarInfo{<:NamedTuple}

This was fine in a pre-VarNamedVector world, because UntypedVarInfo meant VarInfo with Metadata, and TypedVarInfo (implicitly) meant VarInfo with NamedTuple of Metadata. However, with VNV now on board, a VarInfo with a NT of VNV also falls under TypedVarInfo. This means that sometimes TypedVarInfo means "VarInfo with NT of anything" (paricularly when used in type signatures), but sometimes it still means "VarInfo with NT of Metadata" (see e.g. the similarly named typed_varinfo function).

Second is the inconsistent interface between different VarInfo constructors. We used to have VarInfo(rng, model, ...) as a very convenient way of constructing a TypedVarInfo (read: a VarInfo with NT of Metadata). None of the other possibilities had equally convenient methods.

What

This PR therefore does the following:

  1. Introduces 4 new functions:
    • untyped_varinfo([rng, ]model[, sampler, context]) --> VarInfo with Metadata
    • typed_varinfo([rng, ]model[, sampler, context]) --> VarInfo with NT of Metadata
    • untyped_vector_varinfo([rng, ]model[, sampler, context]) --> VarInfo with VNV
    • typed_vector_varinfo([rng, ]model[, sampler, context]) --> VarInfo with NT of VNV

Note that all four functions are implemented such that if the rng is the same, the values will be the same, regardless of which type of VarInfo is requested. None of these functions are exported.

  1. The metadata argument in VarInfo(rng, model, sampler, context, metadata) no longer works. It was basically being used to specify whether it should be a Metadata or a VarNamedVector inside. If you wanted Metadata (the default) then use DynamicPPL.{untyped,typed}_varinfo; if you wanted VarNamedVector then use DynamicPPL.{untyped,typed}_vector_varinfo.

  2. TypedVarInfo is no longer a type, it has been renamed to NTVarInfo. It is also no longer a function (use typed_varinfo instead).

  3. The type VectorVarInfo = VarInfo{<:VarNamedVector} has been renamed to UntypedVectorVarInfo for consistency. This was not exported (and still isn't).

Copy link
Contributor

github-actions bot commented Apr 1, 2025

Benchmark Report for Commit dbddb2f

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 |                  9.2 |                 1.6 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                730.7 |                33.1 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                406.7 |                44.7 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1202.1 |                26.7 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               3807.4 |                19.6 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1400.3 |                29.1 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                914.5 |                 5.3 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5582.4 |                 3.9 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |               1058.3 |                 8.4 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              60953.3 |                 3.6 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8483.3 |                10.3 |
|               Dynamic |        10 |    mooncake |             typed |   true |                129.9 |                11.9 |
|              Submodel |         1 |    mooncake |             typed |   true |                 24.8 |                 9.3 |
|                   LDA |        12 | reversediff |             typed |   true |                473.8 |                 5.0 |

@penelopeysm penelopeysm changed the title Unify {Untyped,Typed}{Vector,}VarInfo constructors Unify {Untyped,Typed}{Vector,}VarInfo 'constructors' Apr 1, 2025
Copy link

codecov bot commented Apr 1, 2025

Codecov Report

Attention: Patch coverage is 76.00000% with 30 lines in your changes missing coverage. Please review.

Please upload report for BASE (breaking@cc5e581). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/varinfo.jl 74.57% 30 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             breaking     #879   +/-   ##
===========================================
  Coverage            ?   84.82%           
===========================================
  Files               ?       34           
  Lines               ?     3849           
  Branches            ?        0           
===========================================
  Hits                ?     3265           
  Misses              ?      584           
  Partials            ?        0           

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

src/varinfo.jl Outdated
symbols have been observed. `VarInfo{<:NamedTuple}` is aliased `TypedVarInfo`.
symbols have been observed. `VarInfo{<:NamedTuple}` is aliased `NTVarInfo`.
Copy link
Member Author

Choose a reason for hiding this comment

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

Unsurprisingly, the changes are pretty much restricted to this file. The rest of the changes are pretty much just updating VarInfo -> TypedVarInfo.

Comment on lines 94 to +97
logp::Base.RefValue{Tlogp}
num_produce::Base.RefValue{Int}
end
const VectorVarInfo = VarInfo{<:VarNamedVector}
VarInfo(meta=Metadata()) = VarInfo(meta, Ref{LogProbType}(0.0), Ref(0))
Copy link
Member Author

@penelopeysm penelopeysm Apr 1, 2025

Choose a reason for hiding this comment

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

The idea going forward is that VarInfo is purely a low-level constructor for the struct itself, i.e., it is used to construct the VarInfo object from its fields, rather than doing something to instantiate those fields. Thus, one should not expect to be using it except at the very lowest levels of DynamicPPL, e.g. if one is testing basic properties of VarInfo objects.

src/varinfo.jl Outdated
Comment on lines 173 to 188
function UntypedVarInfo(
model::Model,
sampler::AbstractSampler=SampleFromPrior(),
context::AbstractContext=DefaultContext(),
)
# No rng
return UntypedVarInfo(Random.default_rng(), model, sampler, context)
end
function UntypedVarInfo(rng::Random.AbstractRNG, model::Model, context::AbstractContext)
# No sampler
return UntypedVarInfo(rng, model, SampleFromPrior(), context)
end
function UntypedVarInfo(model::Model, context::AbstractContext)
# No sampler, no rng
return UntypedVarInfo(model, SampleFromPrior(), context)
end
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 kinda dislike that i had to copy-paste this 4 times, once for each function. But I don't see a better way around it beyond doing indiscriminate f(args...) = f(g(args...)).

We could make it quite a bit simpler by forbidding f(rng, model, context) and f(model, context), i.e., if we want to specify a context then you also have to specify a sampler.

src/varinfo.jl Outdated
"""
function untyped_varinfo(
function TypedVarInfo(vi::UntypedVarInfo)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is all shifted from lower in the file, it's not new code

@penelopeysm penelopeysm marked this pull request as ready for review April 2, 2025 00:14
@penelopeysm penelopeysm requested a review from mhauru April 2, 2025 09:23
@mhauru
Copy link
Member

mhauru commented Apr 2, 2025

I need to do a proper review, but some thoughts and questions based on just the description of changes:

If {Typed,Untyped}VarInfo is no longer a type, but a function, should its name be lowercase?

The Vector versions are not exported, which I think is good. I view UntypedVectorVarInfo as the king-in-waiting, that will replace UntypedVarInfo once #881 is done. I also dream of a future where all VarInfos are typed, which we could handle using BangBang functions: If new elements need to be added to the NamedTuple we do so by creating a new object, otherwise we operate in-place. In that case I think we would have plain VarInfo be the only user-facing constructor. Do others have thoughts on the future external interface of this stuff?

@penelopeysm
Copy link
Member Author

penelopeysm commented Apr 2, 2025

Yup - TypedVarInfo and TypedVectorVarInfo aren't types. I'm not opposed to making them lowercase but I guess for consistency everything should be lowercased so untyped_varinfo, typed_varinfo, untyped_vector_varinfo, typed_vector_varinfo. We did use to have the first two (I deleted them in this PR in favour of the type-lookalikes) but for some reason they weren't used very widely - it wouldn't be too hard to change the names.

(I'd actually prefer if it was md_varinfo, nt_md_varinfo, vnv_varinfo, and nt_vnv_varinfo)

About interface: part of the thing I had in mind with this PR was to keep the interface relatively easy to change in the future. For example replacing MD with VNV is quite straightforward and basically means deleting the existing {Unt,T}ypedVarInfo methods and renaming {Unt,T}ypedVectorVarInfo to them. Personally I view this PR as for the here and now - partly motivated by the need for this in AD testing.

However, if we think that ultimately we just have a single VarInfo() then I could leave that method in instead of deprecating it and then re-introducing it later. Maybe edit the docstring to add a warning that it's an implementation detail as to exactly what form of VarInfo this will return.

@mhauru
Copy link
Member

mhauru commented Apr 2, 2025

I think if this was the final word on VarInfo, we should make the function names lowercase, because it's a pretty clear violation of Julia style conventions. However, I can see an argument for keeping them as they are to have less disruption if/when we change these again.

Personally I view this PR as for the here and now

This sounds fair to me.

However, if we think that ultimately we just have a single VarInfo() then I could leave that method in instead of deprecating it and then re-introducing it later. Maybe edit the docstring to add a warning that it's an implementation detail as to exactly what form of VarInfo this will return.

I like this idea, assuming others are onboard with my vision of a future with only a single VarInfo type.

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

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

I like this, way more consistent. Some tiny details to note, and the above questions of whether to capitalise and/or deprecate. I could be happy keeping those as they are, just want to make sure we make a conscious decision.

src/varinfo.jl Outdated
Comment on lines 191 to 200
TypedVarInfo([rng, ]model[, sampler, context, metadata])

Return an untyped varinfo object for the given `model` and `context`.
Return a VarInfo object for the given `model` and `context`, which has a NamedTuple of
`Metadata` structs as its metadata field.

# Arguments
- `model::Model`: The model for which to create the varinfo object.
- `context::AbstractContext`: The context in which to evaluate the model. Default: `SamplingContext()`.
- `metadata::Union{Metadata,VarNamedVector}`: The metadata to use for the varinfo object.
Default: `Metadata()`.
- `rng::Random.AbstractRNG`: The random number generator to use during model evaluation
- `model::Model`: The model for which to create the varinfo object
- `sampler::AbstractSampler`: The sampler to use for the model. Defaults to `SampleFromPrior()`.
- `context::AbstractContext`: The context in which to evaluate the model. Defaults to `DefaultContext()`.
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to have this docstring here, rather than attached to the method it documents?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, probably just me still trying to figure out exactly when Documenter works and exactly when it doesn't. Changed now

@penelopeysm penelopeysm self-assigned this Apr 8, 2025
@penelopeysm
Copy link
Member Author

@mhauru What do you think of this overall approach?

  • Lowercase the functions
  • Don't export any of the functions (not even typed / untyped)
  • Don't deprecate VarInfo, but put a gigantic warning in the docstring saying that the internal implementation of this type may change when you call this constructor and if you need specific types, use the unexported functions

@mhauru
Copy link
Member

mhauru commented Apr 8, 2025

I think I'm happy with that. I hesitated with the middle point, but I guess the lowercase versions weren't exported before either. Is the idea to avoid breakage if we one day move to only having one VarInfo type?

@penelopeysm
Copy link
Member Author

penelopeysm commented Apr 8, 2025

Exactly (or in the case where people relied on VarInfo returning, specifically, a TypedVarInfo, at least we warned them).

@penelopeysm penelopeysm mentioned this pull request Apr 8, 2025
8 tasks
@penelopeysm penelopeysm changed the title Unify {Untyped,Typed}{Vector,}VarInfo 'constructors' Unify {untyped,typed}_{vector_,}varinfo constructor functions Apr 8, 2025
@penelopeysm penelopeysm force-pushed the py/varinfo branch 3 times, most recently from c8f9073 to 04a2009 Compare April 8, 2025 16:07
@penelopeysm
Copy link
Member Author

Bonus: The diff is much more readable now that VarInfo(...) isn't deprecated 😅

Copy link
Member

@mhauru mhauru 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!

@penelopeysm penelopeysm merged commit b9c368b into breaking Apr 9, 2025
17 of 18 checks passed
@penelopeysm penelopeysm deleted the py/varinfo branch April 9, 2025 10:35
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 <[email protected]>

* 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 <[email protected]>

* Apply suggestions from code review

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

---------

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

---------

Co-authored-by: Markus Hauru <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>
mhauru added a commit that referenced this pull request May 2, 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)

* Draft of accumulators

* Fix some variable names

* Fix pointwise_logdensities, gut tilde_observe, remove resetlogp!!

* Map rather than broadcast

Co-authored-by: Tor Erlend Fjelde <[email protected]>

* Start documenting accumulators

* Use Val{symbols} instead of AccTypes to index

* More documentation for accumulators

* 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 resetlogp!! and type stability for accumulators

* Fix type rigidity of LogProbs and NumProduce

* Fix uses of getlogp and other assorted issues

* setaccs!! nicer interface and logdensity function fixes

* Revert back to calling the macro @addlogprob!

* Remove a dead test

* Clarify a comment

* Implement split/combine for PointwiseLogdensityAccumulator

* Switch ThreadSafeVarInfo.accs_by_thread to be a tuple

* 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 <[email protected]>

* 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 <[email protected]>

* Apply suggestions from code review

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

---------

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

* Revert ThreadSafeVarInfo back to Vectors and fix some AD type casting in (Simple)VarInfo

* Improve accumulator docs

* Add test/accumulators.jl

* Docs fixes

* Various small fixes

* Make DynamicTransformation not use accumulators other than LogPrior

* Fix variable order and name of map_accumulator!!

* Typo fixing

* Small improvement to ThreadSafeVarInfo

* Fix demo_dot_assume_observe_submodel prefixing

* Typo fixing

* Miscellaneous small fixes

* HISTORY entry and more miscellanea

* Add more tests for accumulators

* Improve accumulators docstrings

* Fix a typo

* Expand HISTORY entry

* Add accumulators to API docs

* Remove unexported functions from API docs

* Add NamedTuple methods for get/set/acclogp

* Fix setlogp!! with single scalar to error

* Export AbstractAccumulator, fix a docs typo

* Apply suggestions from code review

Co-authored-by: Penelope Yong <[email protected]>

* Rename LogPrior -> LogPriorAccumulator, and Likelihood and NumProduce

* Type bound log prob accumulators with T<:Real

* Add @addlogprior! and @addloglikelihood!

* Apply suggestions from code review

Co-authored-by: Penelope Yong <[email protected]>

* Move default accumulators to default_accumulators.jl

* Fix some tests

* Introduce default_accumulators()

* Go back to only having @addlogprob!

* Fix tilde_observe!! prefixing

* Fix default_accumulators internal type

* Make unflatten more type stable, and add a test for it

* Always print all benchmark results

* Move NumProduce VI functions to abstract_varinfo.jl

---------

Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
github-merge-queue bot pushed a commit that referenced this pull request Aug 7, 2025
* Bump minor version to 0.37.0

* Accumulators, stage 1 (#885)

* 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)

* Draft of accumulators

* Fix some variable names

* Fix pointwise_logdensities, gut tilde_observe, remove resetlogp!!

* Map rather than broadcast

Co-authored-by: Tor Erlend Fjelde <[email protected]>

* Start documenting accumulators

* Use Val{symbols} instead of AccTypes to index

* More documentation for accumulators

* 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 resetlogp!! and type stability for accumulators

* Fix type rigidity of LogProbs and NumProduce

* Fix uses of getlogp and other assorted issues

* setaccs!! nicer interface and logdensity function fixes

* Revert back to calling the macro @addlogprob!

* Remove a dead test

* Clarify a comment

* Implement split/combine for PointwiseLogdensityAccumulator

* Switch ThreadSafeVarInfo.accs_by_thread to be a tuple

* 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 <[email protected]>

* 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 <[email protected]>

* Apply suggestions from code review

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

---------

Co-authored-by: Hong Ge <[email protected]>
Co-authored-by: Markus Hauru <[email protected]>

* Revert ThreadSafeVarInfo back to Vectors and fix some AD type casting in (Simple)VarInfo

* Improve accumulator docs

* Add test/accumulators.jl

* Docs fixes

* Various small fixes

* Make DynamicTransformation not use accumulators other than LogPrior

* Fix variable order and name of map_accumulator!!

* Typo fixing

* Small improvement to ThreadSafeVarInfo

* Fix demo_dot_assume_observe_submodel prefixing

* Typo fixing

* Miscellaneous small fixes

* HISTORY entry and more miscellanea

* Add more tests for accumulators

* Improve accumulators docstrings

* Fix a typo

* Expand HISTORY entry

* Add accumulators to API docs

* Remove unexported functions from API docs

* Add NamedTuple methods for get/set/acclogp

* Fix setlogp!! with single scalar to error

* Export AbstractAccumulator, fix a docs typo

* Apply suggestions from code review

Co-authored-by: Penelope Yong <[email protected]>

* Rename LogPrior -> LogPriorAccumulator, and Likelihood and NumProduce

* Type bound log prob accumulators with T<:Real

* Add @addlogprior! and @addloglikelihood!

* Apply suggestions from code review

Co-authored-by: Penelope Yong <[email protected]>

* Move default accumulators to default_accumulators.jl

* Fix some tests

* Introduce default_accumulators()

* Go back to only having @addlogprob!

* Fix tilde_observe!! prefixing

* Fix default_accumulators internal type

* Make unflatten more type stable, and add a test for it

* Always print all benchmark results

* Move NumProduce VI functions to abstract_varinfo.jl

---------

Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: Hong Ge <[email protected]>

* Replace PriorExtractorContext with PriorDistributionAccumulator (#907)

* Implement values_as_in_model using an accumulator (#908)

* Implement values_as_in_model using an accumulator

* Make make_varname_expression a function

* Refuse to combine ValuesAsInModelAccumulators with different include_colon_eqs

* Fix nested context test

* Bump DynamicPPL versions

* Fix merge (1)

* Add benchmark Pkg source

* [no ci] Don't need to dev again

* Disable use_closure for ReverseDiff

* Revert "Disable use_closure for ReverseDiff"

This reverts commit 3cb47cd.

* Fix LogDensityAt struct

* Try not duplicating

* Update comment pointing to closure benchmarks

* Remove `context` from model evaluation (use `model.context` instead) (#952)

* Change `evaluate!!` API, add `sample!!`

* Fix literally everything else that I broke

* Fix some docstrings

* fix ForwardDiffExt (look, multiple dispatch bad...)

* Changelog

* fix a test

* Fix docstrings

* use `sample!!`

* Fix a couple more cases

* Globally rename `sample!!` -> `evaluate_and_sample!!`, add changelog warning

* Mark function as Const for Enzyme tests (#957)

* Move submodel code to submodel.jl; remove `@submodel` (#959)

* Move submodel code to submodel.jl

* Remove `@submodel`

* Fix missing field tests for 1.12 (#961)

* Remove 3-argument `{_,}evaluate!!`; clean up submodel code (#960)

* Clean up submodel code, remove 3-arg `_evaluate!!`

* Remove 3-argument `evaluate!!` as well

* Update changelog

* Improve submodel error message

* Fix doctest

* Add error hint for three-argument evaluate!!

* Improve API for AD testing (#964)

* Rework API for AD testing

* Fix test

* Add `rng` keyword argument

* Use atol and rtol

* remove unbound type parameter (?)

* Don't need to do elementwise check

* Update changelog

* Fix typo

* DebugAccumulator (plus tiny bits and pieces) (#976)

* DebugContext -> DebugAccumulator

* Changelog

* Force `conditioned` to return a dict

* fix conditioned implementation

* revert `conditioned` bugfix (will merge this to main instead)

* fix show

* Fix doctests

* fix doctests 2

* Make VarInfo actually mandatory in check_model

* Re-implement `missing` check

* Revert `combine` signature in docstring

* Revert changes to `Base.show` on AccumulatorTuple

* Add TODO comment about VariableOrderAccumulator

Co-authored-by: Markus Hauru <[email protected]>

* Fix doctests

---------

Co-authored-by: Markus Hauru <[email protected]>

* VariableOrderAccumulator (#940)

* Turn NumProduceAccumulator into VariableOrderAccumulator

* Add comparison methods

* Make VariableOrderAccumulator use regular Dict

* Use copy rather than deepcopy for accumulators

* Minor docstring touchup

* Remove unnecessary use of NumProduceAccumulator

* Fix split(VariableOrderAccumulator)

* Remove NumProduceAcc from Debug

* Fix set_retained_vns_del!

---------

Co-authored-by: Penelope Yong <[email protected]>

* Accumulators stage 2 (#925)

* Give LogDensityFunction the getlogdensity field

* Allow missing LogPriorAccumulator when linking

* Trim whitespace

* Run formatter

* Fix a few typos

* Fix comma -> semicolon

* Fix `LogDensityAt` invocation

* Fix one last test

* Fix tests

---------

Co-authored-by: Penelope Yong <[email protected]>

* Implement more consistent tracking of logp components via `LogJacobianAccumulator` (#998)

* logjac accumulator

* Fix tests

* Fix a whole bunch of stuff

* Fix final tests

* Fix docs

* Fix docs/doctests

* Fix maths in LogJacobianAccumulator docstring

* Twiddle with a comment

* Add changelog

* Fix accumulator docstring

* logJ -> logjac

* Fix logjac accumulation for StaticTransformation

* Fix behaviour of `set_retained_vns_del!` for `num_produce == 0` (#1000)

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

* point to unmerged AbstractPPL branch

* Remove code that was moved to AbstractPPL

* Remove Dictionaries with Any key type

* Fix bad merge conflict resolution

* Fix doctests

* Point to [email protected]

This reverts commit 709dc9e.

* Fix doctests

* Fix docs AbstractPPL bound

* Remove stray `Pkg.update()`

* Accumulator miscellanea: Subset, merge, acclogp, and LogProbAccumulator (#999)

* logjac accumulator

* Fix tests

* Fix a whole bunch of stuff

* Fix final tests

* Fix docs

* Fix docs/doctests

* Fix maths in LogJacobianAccumulator docstring

* Twiddle with a comment

* Add changelog

* Simplify accs with LogProbAccumulator

* Replace + with accumulate for LogProbAccs

* Introduce merge and subset for accs

* Improve acc tests

* Fix docstring typo.

Co-authored-by: Penelope Yong <[email protected]>

* Fix merge

---------

Co-authored-by: Penelope Yong <[email protected]>

* Minor tweak to changelog wording

---------

Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Tor Erlend Fjelde <[email protected]>
Co-authored-by: Hong Ge <[email protected]>
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