-
Notifications
You must be signed in to change notification settings - Fork 36
The big InitContext
PR. Do not merge!
#967
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38652f7
to
bc16e09
Compare
Benchmark Report for Commit 7265885Computer Information
Benchmark Results
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## py/init-prior-uniform #967 +/- ##
=========================================================
- Coverage 33.43% 4.39% -29.05%
=========================================================
Files 38 39 +1
Lines 4023 3802 -221
=========================================================
- Hits 1345 167 -1178
- Misses 2678 3635 +957 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This was referenced Jul 5, 2025
9bdb166
to
a02dfac
Compare
21bcb0b
to
7265885
Compare
DynamicPPL.jl documentation for PR #967 is available at: |
This was referenced Jul 10, 2025
25c1db7
to
32ab1bc
Compare
Note that, apart from being simpler code, Distributions.Uniform also doesn't allow the lower and upper bounds to be exactly equal (but we might like to keep that option open in DynamicPPL, e.g. if the user wants to initialise all values to the same value in linked space).
32ab1bc
to
5f7c77e
Compare
5f7c77e
to
13c14ca
Compare
13c14ca
to
3ab2061
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
This PR has been split up into the following:
Part 1: Adding
hasvalue
andgetvalue
to AbstractPPLPart 2: Removing
hasvalue
andgetvalue
from DynamicPPLPart 3: Introducing
InitContext
andinit!!
Part 4: Using
ParamsInit
to implementpredict
,returned
, andinitialize_values
Part 5: Removing
SamplingContext
,SampleFromPrior
,SampleFromUniform
,assume
, andtilde_assume
Part 6: Documentation (Not written yet.)
This PR largely follows through on the proposal in #955. I would say that the code changes in this PR are ~ 80% representative of the final result. However, I'm trying my best to disentangle the different bits and/or to set out the changes in separate stages, so that it's easier to review.
Removes
SamplingContext
,SampleFromPrior
, andSampleFromUniform
Creates a new leaf context,
InitContext
. Its behaviour is to create new values, or overwrite existing variables in a VarInfo if they exist.Introduces initialisation strategies,
PriorInit
,UniformInit
, andParamsInit
. See docstrings for more info.Changes
evaluate_and_sample!!
(introduced in Removecontext
from model evaluation (usemodel.context
instead) #952) toinit!!
Moves all the VarInfo-initialisation code (used to be in
sampler.jl
) toParamsInit
.Auxiliary changes that follow from the above:
The function
initialsampler
, which was used to specify how initial values were generated for a given sampler, has been removed. The correct replacement isinit_strategy(::AbstractSampler)
; however, that should be in Turing not DynamicPPL.Note that, after deleting the infamous
assume
method forSampleFromPrior
, there is no longer any code that actually reads thedel
flag on VarInfo. There is a fair amount of code that writes to thedel
flag which has to be updated.setval_and_resample!
followed by model evaluation is replaced withParamsInit
with an incomplete set of parameters.setval_and_resample!
used to usenested_setindex_maybe
. The role of this function was to handle cases where the VarName of interest wasx
, but instead of supplyingx
, the user supplied (say)x[1]
andx[2]
. This has now been replaced withhasvalue(dict, vn, dist)
which usesdist
to determine whether the sub-variablesx[1]
andx[2]
provide enough information to reconstruct the full variablex
. For example, this would return true ifdist
isMvNormal(zeros(2), I)
.A long-held goal of mine is to split up
contexts.jl
andcontext_implementations.jl
such that each context is in its own file. To help get us to this stage, I've put all theInitContext
-related code insidesrc/contexts/init.jl
. This should, hopefully, also make reviewing easier.TODO for this PR
ParamsInit
: currently, initialising viaNamedTuple
orDict
is OK, butVector
will fail.set_retained_vns_del!
and whether we can get rid of it too.truncated
Turing.jl#2476)TODO for future PRs
Look at this!:
Closes #859
Closes #955
Closes #797 (indirectly, since
initialize_parameters
is nowinit!!(..., ::ParamsInit)
)Closes #774
Closes #375
Closes #983
Furthermore, once an upstream interface to InitContext is put into Turing, this will also solve:
TuringLang/Turing.jl#2476 (sampling)
TuringLang/Turing.jl#1775 (mode estimation)