Skip to content

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented Jul 14, 2025

Closes #2583, where the logp from externalsampler was not being correctly set in varinfo and hence the chain.

Plots shown below:
Before = logp was never updated, so logp is just a flat line.
After = logp changes with the parameters.

These were run using AdvancedMH. I've tested with AdvancedHMC and SliceSampling (cf. TuringLang/SliceSampling.jl#15) and similar improvements are observed.

using Turing, Plots, AdvancedMH

@model function test_model(y)
    a ~ Normal(0, 1)
    y ~ Normal(a, 1)
end

y = rand(Normal(0.5, 1), 100)
model = test_model(y)

chain_1 = sample(model, externalsampler(AdvancedMH.RWMH(1)), 100);

plot(chain_1, [:a, :lp], seriestype = :traceplot)

Before

Screenshot 2025-07-14 at 15 39 09

After

Screenshot 2025-07-14 at 15 39 48

Copy link
Contributor

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

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

Attention: Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.

Project coverage is 85.46%. Comparing base (1aa95ac) to head (1e85c00).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/mcmc/external_sampler.jl 86.66% 2 Missing ⚠️
src/mcmc/gibbs.jl 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2616      +/-   ##
==========================================
- Coverage   85.60%   85.46%   -0.15%     
==========================================
  Files          22       22              
  Lines        1459     1465       +6     
==========================================
+ Hits         1249     1252       +3     
- Misses        210      213       +3     

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

@coveralls
Copy link

coveralls commented Jul 14, 2025

Pull Request Test Coverage Report for Build 16291041266

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 14 of 18 (77.78%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 85.519%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/mcmc/external_sampler.jl 13 15 86.67%
src/mcmc/gibbs.jl 1 3 33.33%
Totals Coverage Status
Change from base Build 16154040908: -0.1%
Covered Lines: 1252
Relevant Lines: 1464

💛 - Coveralls

@penelopeysm penelopeysm marked this pull request as ready for review July 14, 2025 14:40
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.

Good stuff, just one trivial typo.


There are a few more optional functions which you can implement to improve the integration with Turing.jl:

- `Turing.Inference.isgibbscomponent(::MySampler)`: If you want your sampler to function as a component in Turing's Gibbs sampler, you should make this to `true`.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `Turing.Inference.isgibbscomponent(::MySampler)`: If you want your sampler to function as a component in Turing's Gibbs sampler, you should make this to `true`.
- `Turing.Inference.isgibbscomponent(::MySampler)`: If you want your sampler to function as a component in Turing's Gibbs sampler, you should make this evaluate to `true`.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed, thanks!

@penelopeysm
Copy link
Member Author

There's another bug that is quite closely related #2617, but that one looks harder to diagnose and I think I'd like to leave it for a separate PR, so I'll merge this first so that we have a first-order solution to the original bug. Thanks @mhauru!

@penelopeysm penelopeysm enabled auto-merge July 15, 2025 10:41
@penelopeysm penelopeysm disabled auto-merge July 15, 2025 10:41
@penelopeysm penelopeysm merged commit add8870 into main Jul 15, 2025
29 of 30 checks passed
@penelopeysm penelopeysm deleted the py/external-sampler-logp branch July 15, 2025 10:41
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.

Gibbs sampler does not carry through log-prob from an external sampler
3 participants