Skip to content

Commit

Permalink
Replace old Gibbs sampler with the experimental one. (#2328)
Browse files Browse the repository at this point in the history
* Replace old Gibbs sampler with the experimental one.

* Remove dead references to experimental

* Remove mention of experimental from JuliaFormatter conf

* Add tests for deprecated constructor

* Fix deprecated Gibbs constructors. Add HISTORY entry.

* Bump version to 0.35.0

* Add Gibbs constructor test for repeat samplers

* Fix typo in test/mcmc/ess.jl

* Use provided rng to initialise VarInfo in Gibbs

* Fix a typo in GibbsContext

* Fix the Gibbs sampler

* Fix the Gibbs sampler more

* Remove mentions of old Gibbs sampler from MH docs

Co-authored-by: Penelope Yong <penelopeysm@gmail.com>

* Bump DPPL to 0.28.6

* Redesign GibbsContext, work in progress

* Fixing new Gibbs, adding a broken test

* Document and clean up GibbsContext

* Code style and docs improvements to Gibbs

* Change how AdvancedHMC Gibbs state treats momenta

* Remove unnecessary invlinking

* Change how AdvancedHMC Gibbs state treats momenta, again

* Use setparams!! rather than reset_state!!

* Don't overload setparams\!\! with VarInfo

* A fix for ESS in Gibbs

* Remove recompute_logprob!!

* Fix setparams_varinfo!! for MH

* Stop hard coding the leafcontext for MH setparams_varinfo!!

* Fix setparams_varinfo!! for ESS

* Fix the context used by setparams_varinfo!! ESS

* Add GibbsContext type stability tests

* Apply suggestions from code review

Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com>

* Add clarifying comment

* Add setparams_varinfo!! type bounds

* Fix an import

* Style improvement

* Improve GibbsContext type stability test

* Add comment to constructor tests

* Fix a Gibbs test

* Document the methods of `varinfo` better

* Check whether a sampler is a valid Gibbs component

* Move varinfo methods where they belong

* Fix calling of child context in GibbsContext

* Fix Selectors and type stability of Gibbs

* Fix broken short circuit in MH

* Stop unnecessary use of Val in GibbsContext

* Enforce GibbsContext being next to a leaf

* Fix setparams_varinfo!! for ESS

* Fix a small Gibbs bug

* Fix Gibbs sampler test

* Add back tests that were accidentally commented out

* Relax a test tolerance

* Add a Gibbs test for dynamic model with ESS

* Use ESS in Gibbs DEMO_MODELS tests

* Add Gibbs component call order test

* Fix Gibbs linking bug, add tests

* Make Gibbs constructor more flexible

* Introduce RepeatSampler

* Switch gold standard sample Gibbs test back to HMC

I tried using ESS instead, because I thought it would test behavior a
bit more broadly, given similarities between HMC and NUTS. It worked
locally, but the KS test fails in one or two cases on CI.

* Clean up RepeatSamplerTests preamble

* Fix RepeatSampler in Gibbs bug

* Rename a function in Gibbs

* Test HMCDA in Gibbs tests

* Simplify is_target_varname

* Add suggestions from code review

Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com>

* Add a couple of issue references

* Restructure Gibbs inference tests and reduce iteration counts

* Reduce another iter count in Gibbs tests

* Add an info print to Gibbs tests

* Use StableRNG, relax test tolerance

* Fix a kwarg

---------

Co-authored-by: Penelope Yong <penelopeysm@gmail.com>
Co-authored-by: Tor Erlend Fjelde <tor.erlend95@gmail.com>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 2707d12 commit 9e5467a
Show file tree
Hide file tree
Showing 30 changed files with 1,457 additions and 1,116 deletions.
8 changes: 0 additions & 8 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
style="blue"
format_markdown = true
import_to_using = false
# TODO
# We ignore these files because when formatting was first put in place they were being worked on.
# These ignores should be removed once the relevant PRs are merged/closed.
ignore = [
# https://github.com/TuringLang/Turing.jl/pull/2328/files
"src/experimental/gibbs.jl",
"test/experimental/gibbs.jl",
]
4 changes: 1 addition & 3 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ jobs:
args: "mcmc/abstractmcmc.jl"
- name: "mcmc/Inference"
args: "mcmc/Inference.jl"
- name: "experimental/gibbs"
args: "experimental/gibbs.jl"
- name: "mcmc/ess"
args: "mcmc/ess.jl"
- name: "everything else"
args: "--skip essential/ad.jl mcmc/gibbs.jl mcmc/hmc.jl mcmc/abstractmcmc.jl mcmc/Inference.jl experimental/gibbs.jl mcmc/ess.jl"
args: "--skip essential/ad.jl mcmc/gibbs.jl mcmc/hmc.jl mcmc/abstractmcmc.jl mcmc/Inference.jl mcmc/ess.jl"
runner:
# Default
- version: '1'
Expand Down
16 changes: 16 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Release 0.36.0

## Breaking changes

0.36.0 introduces a new Gibbs sampler. It's been included in several previous releases as `Turing.Experimental.Gibbs`, but now takes over the old Gibbs sampler, which gets removed completely.

The new Gibbs sampler supports the same user-facing interface as the old one. However, given
that the internals of it having been completely rewritten in a very different manner, there
may be accidental breakage that we haven't anticipated. Please report any you find.

`GibbsConditional` has also been removed. It was never very user-facing, but it was exported, so technically this is breaking.

The old Gibbs constructor relied on being called with several subsamplers, and each of the constructors of the subsamplers would take as arguments the symbols for the variables that they are to sample, e.g. `Gibbs(HMC(:x), MH(:y))`. This constructor has been deprecated, and will be removed in the future. The new constructor works by assigning samplers to either symbols or `VarNames`, e.g. `Gibbs(; x=HMC(), y=MH())` or `Gibbs(@varname(x) => HMC(), @varname(y) => MH())`. This allows more granular specification of which sampler to use for which variable.

Likewise, the old constructor for calling one subsampler more often than another, `Gibbs((HMC(0.01, 4, :x), 2), (MH(:y), 1))` has been deprecated. The new way to do this is to use `RepeatSampler`, also introduced at this version: `Gibbs(@varname(x) => RepeatSampler(HMC(0.01, 4), 2), @varname(y) => MH())`.

# Release 0.35.0

## Breaking changes
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.35.5"
version = "0.36.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -49,7 +49,7 @@ TuringOptimExt = "Optim"

[compat]
ADTypes = "1.9"
AbstractMCMC = "5.2"
AbstractMCMC = "5.5"
Accessors = "0.1"
AdvancedHMC = "0.3.0, 0.4.0, 0.5.2, 0.6"
AdvancedMH = "0.8"
Expand Down
3 changes: 1 addition & 2 deletions src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ using .Variational
include("optimisation/Optimisation.jl")
using .Optimisation

include("experimental/Experimental.jl")
include("deprecated.jl") # to be removed in the next minor version release

###########
Expand Down Expand Up @@ -88,7 +87,6 @@ export @model, # modelling
Emcee,
ESS,
Gibbs,
GibbsConditional,
HMC, # Hamiltonian-like sampling
SGLD,
SGHMC,
Expand All @@ -99,6 +97,7 @@ export @model, # modelling
SMC,
CSMC,
PG,
RepeatSampler,
vi, # variational inference
ADVI,
sample, # inference
Expand Down
16 changes: 0 additions & 16 deletions src/experimental/Experimental.jl

This file was deleted.

Loading

0 comments on commit 9e5467a

Please sign in to comment.