Remove 3-argument {_,}evaluate!!; clean up submodel code#960
Conversation
_evaluate!!; clean up submodel code{_,}evaluate!!; clean up submodel code
3dc22f4 to
4bb2526
Compare
Benchmark Report for Commit aaf0bc6Computer InformationBenchmark Results |
4bb2526 to
55f838f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## breaking #960 +/- ##
============================================
- Coverage 82.85% 82.77% -0.09%
============================================
Files 38 38
Lines 4031 4011 -20
============================================
- Hits 3340 3320 -20
Misses 691 691 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dcd5c9d to
31b0caa
Compare
|
DynamicPPL.jl documentation for PR #960 is available at: |
31b0caa to
039a523
Compare
039a523 to
bfa48b3
Compare
mhauru
left a comment
There was a problem hiding this comment.
Seems good to me, just had a few questions to check/inform myself.
| function AbstractPPL.evaluate!!( | ||
| model::Model, varinfo::AbstractVarInfo, context::AbstractContext | ||
| ) | ||
| Base.depwarn( | ||
| "The `context` argument to evaluate!!(model, varinfo, context) is deprecated.", | ||
| :dynamicppl_evaluate_context, | ||
| ) | ||
| new_ctx = combine_model_and_external_contexts(model.context, context) | ||
| model = contextualize(model, new_ctx) | ||
| return evaluate!!(model, varinfo) | ||
| end |
There was a problem hiding this comment.
Wasn't this deprecation added just a few weeks ago? Or am I mixing this with something else?
There was a problem hiding this comment.
Same as above; but I don't know, I might be open to leaving a helpful error message in (i.e., maybe it shouldn't continue behaving as it does, but it should throw an error message that guides people towards the right answer)? I do know that upstream packages use evaluate!! even though it is internal, pretty sure I've seen it in Pigeons.jl for example, and Turing itself obviously uses evaluate!! quite a lot.
There was a problem hiding this comment.
A manually crafted, more informative error message sounds good to me.
There was a problem hiding this comment.
I added an error hint in src/DynamicPPL.jl, so now this happens:
julia> using DynamicPPL, Distributions
julia> @model f() = x ~ Normal()
f (generic function with 2 methods)
julia> m = f(); v = VarInfo(m); c = DefaultContext()
DefaultContext()
julia> DynamicPPL.evaluate!!(m, v, c)
ERROR: MethodError: no method matching evaluate!!(::Model{…}, ::VarInfo{…}, ::DefaultContext)
The function `evaluate!!` exists, but no method is defined for this combination of argument types.
The method `evaluate!!(model, varinfo, new_ctx)` has been removed. Instead, you should store the `new_ctx` in the `model.context` field using `new_model = contextualize(model, new_ctx)`, and then call `evaluate!!(new_model, varinfo)` on the new model. (Note that, if the model already contained a non-default context, you will need to wrap the existing context.)
Closest candidates are:
evaluate!!(::Model, ::AbstractVarInfo)
@ DynamicPPL ~/ppl/dppl/src/model.jl:868
Stacktrace:
[1] top-level scope
@ REPL[10]:1
Some type information was truncated. Use `show(err)` to see complete types.
mhauru
left a comment
There was a problem hiding this comment.
Thanks @penelopeysm! I didn't know about adding error hints, that's neat.
* 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 <tor.erlend95@gmail.com> * 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 <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> * 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 <penelopeysm@gmail.com> * 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 <penelopeysm@gmail.com> * 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 <penelopeysm@gmail.com> Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com> * 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 <markus@mhauru.org> * Fix doctests --------- Co-authored-by: Markus Hauru <markus@mhauru.org> * 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 <penelopeysm@gmail.com> * 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 <penelopeysm@gmail.com> * 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 AbstractPPL@0.13 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 <penelopeysm@gmail.com> * Fix merge --------- Co-authored-by: Penelope Yong <penelopeysm@gmail.com> * Minor tweak to changelog wording --------- Co-authored-by: Penelope Yong <penelopeysm@gmail.com> Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com> Co-authored-by: Hong Ge <3279477+yebai@users.noreply.github.com>
This PR:
evaluate!!(model, varinfo, context)in the DynamicPPL codebase_evaluate!!(model, varinfo, context)as this method was only being used for submodelsIn return, it introduces:
_evaluate!!(submodel, varinfo, context, left). Yes, yes, I basically moved the implementation from one place to the other; but the whole point is that this was special-case behaviour that was only needed for submodels, so this at least makes it clearer.It also removes a lot of wrapper code for submodels. For example, we don't have this
ReturnedModelWrapperandSampleablething any more, instead, there's justSubmodelwhich wraps a model.I personally don't see the need for more than one layer of indirection for submodels (in terms of the data structure, the only difference between a submodel and a model is that the submodel carries information about whether it should be auto-prefixed). I had mucked around with this before in #815 and I didn't find any real problems with removing the wrappers there (in fact in that PR I went one step further and removed all wrappers, but that would have made it impossible to opt-out of prefixing and that's Bad(TM)).
I didn't add any new tests, but
test/submodel.jlalready contains quite extensive tests to make sure that everything behaves and it passes these tests so I'm quite happy.#959 needs to be merged first.Done.Follow-up from #952
Closes #720 (for good)