Skip to content

Conversation

@penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jun 16, 2025

See #2555

Pending #2588

@penelopeysm penelopeysm changed the base branch from main to py/ldf-hmc June 16, 2025 15:07
@github-actions
Copy link
Contributor

Turing.jl documentation for PR #2590 is available at:
https://TuringLang.github.io/Turing.jl/previews/PR2590/

@codecov
Copy link

codecov bot commented Jun 16, 2025

Codecov Report

❌ Patch coverage is 88.09524% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.27%. Comparing base (e08f548) to head (ec885a4).
⚠️ Report is 1 commits behind head on py/ldf-hmc.

Files with missing lines Patch % Lines
src/mcmc/mh.jl 85.00% 3 Missing ⚠️
src/mcmc/abstractmcmc.jl 75.00% 1 Missing ⚠️
src/mcmc/ess.jl 94.44% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           py/ldf-hmc    #2590       +/-   ##
===============================================
+ Coverage       42.32%   74.27%   +31.95%     
===============================================
  Files              22       22               
  Lines            1498     1493        -5     
===============================================
+ Hits              634     1109      +475     
+ Misses            864      384      -480     

☔ 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 force-pushed the py/ldf-ess branch 2 times, most recently from 84e8b7e to 393234b Compare June 16, 2025 20:57
@penelopeysm penelopeysm force-pushed the py/ldf-ess branch 2 times, most recently from fa0f068 to 22c2e9a Compare June 17, 2025 12:37
@penelopeysm penelopeysm changed the title sample with LogDensityFunction: part 2 - ess.jl sample with LogDensityFunction: part 2 - ess.jl + mh.jl Jun 17, 2025
Comment on lines 79 to 83
ctx = if ldf.context isa SamplingContext
ldf.context
else
SamplingContext(rng, spl)
SamplingContext(rng, spl, ldf.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.

otherwise the existing context won't be obeyed

Comment on lines -142 to -153
# Some of the proposals require working in unconstrained space.
transform_maybe(proposal::AMH.Proposal) = proposal
function transform_maybe(proposal::AMH.RandomWalkProposal)
return AMH.RandomWalkProposal(Bijectors.transformed(proposal.proposal))
end

function MH(model::Model; proposal_type=AMH.StaticProposal)
priors = DynamicPPL.extract_priors(model)
props = Tuple([proposal_type(prop) for prop in values(priors)])
vars = Tuple(map(Symbol, collect(keys(priors))))
priors = map(transform_maybe, NamedTuple{vars}(props))
return AMH.MetropolisHastings(priors)
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 code was broken for a long time and nobody bothered to update it. the idea would be that this would return an AMH.MetropolisHastings which then needed to be wrapped in an ExternalSampler. however the external sampler would break (see tests below) I just removed it because it wasn't documented and wasn't working.

Comment on lines -42 to -48
# s6 = externalsampler(MH(gdemo_default, proposal_type=AdvancedMH.RandomWalkProposal))
# c6 = sample(gdemo_default, s6, N)

# NOTE: Broken because MH doesn't really follow the `logdensity` interface, but calls
# it with `NamedTuple` instead of `AbstractVector`.
# s7 = externalsampler(MH(gdemo_default, proposal_type=AdvancedMH.StaticProposal))
# c7 = sample(gdemo_default, s7, N)
Copy link
Member Author

Choose a reason for hiding this comment

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

these were the corresponding tests

Comment on lines -228 to -229
@testset "MH link/invlink" begin
vi_base = DynamicPPL.VarInfo(gdemo_default)
Copy link
Member Author

Choose a reason for hiding this comment

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

these tests covered by requires_unconstrained_space

Comment on lines -283 to +284
check_numerical(chain, [:s, :m], [mean(InverseGamma(2, 3)), 0]; atol=0.3)
@test mean(chain[:a]) 0.0 atol = 0.1
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 test was annoyingly difficult to get right. with the gdemo model i had to bump this up to 50000 samples to get it to work reasonably often. I replaced it with a simpler model for which it's obvious when it's being sampled from the prior (a = 0) rather than the posterior (a = 2.5).

@penelopeysm
Copy link
Member Author

Closing as it's too out of date; but the code will probably be recycled into a new PR at some point.

@penelopeysm penelopeysm closed this Sep 8, 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.

2 participants