Skip to content

Commit 3f861bf

Browse files
committed
Merge branch 'master' into tor/state-transition-related
2 parents d9480d1 + fc8cfa6 commit 3f861bf

File tree

10 files changed

+465
-103
lines changed

10 files changed

+465
-103
lines changed

.github/workflows/DocsNav.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Add Navbar
2+
3+
on:
4+
page_build: # Triggers the workflow on push events to gh-pages branch
5+
workflow_dispatch: # Allows manual triggering
6+
schedule:
7+
- cron: '0 0 * * 0' # Runs every week on Sunday at midnight (UTC)
8+
9+
jobs:
10+
add-navbar:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
steps:
15+
- name: Checkout gh-pages
16+
uses: actions/checkout@v4
17+
with:
18+
ref: gh-pages
19+
fetch-depth: 0
20+
21+
- name: Download insert_navbar.sh
22+
run: |
23+
curl -O https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/insert_navbar.sh
24+
chmod +x insert_navbar.sh
25+
26+
- name: Update Navbar
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
git config user.name github-actions[bot]
31+
git config user.email github-actions[bot]@users.noreply.github.com
32+
33+
# Define the URL of the navbar to be used
34+
NAVBAR_URL="https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/TuringNavbar.html"
35+
36+
# Update all HTML files in the current directory (gh-pages root)
37+
./insert_navbar.sh . $NAVBAR_URL
38+
39+
# Remove the insert_navbar.sh file
40+
rm insert_navbar.sh
41+
42+
# Check if there are any changes
43+
if [[ -n $(git status -s) ]]; then
44+
git add .
45+
git commit -m "Added navbar and removed insert_navbar.sh"
46+
git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" gh-pages
47+
else
48+
echo "No changes to commit"
49+
fi

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
name = "AbstractMCMC"
22
uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
3-
keywords = ["markov chain monte carlo", "probablistic programming"]
3+
keywords = ["markov chain monte carlo", "probabilistic programming"]
44
license = "MIT"
55
desc = "A lightweight interface for common MCMC methods."
6-
version = "4.5.0"
6+
version = "5.4.0"
77

88
[deps]
99
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
1010
ConsoleProgressMonitor = "88cd18e8-d9cc-4ea6-8889-5259c0d15c8b"
1111
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
12+
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1213
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
1314
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1415
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
@@ -19,8 +20,9 @@ TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
1920
Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"
2021

2122
[compat]
22-
BangBang = "0.3.19"
23+
BangBang = "0.3.19, 0.4"
2324
ConsoleProgressMonitor = "0.1"
25+
FillArrays = "1"
2426
LogDensityProblems = "2"
2527
LoggingExtras = "0.4, 0.5, 1"
2628
ProgressLogging = "0.1"

docs/src/api.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,24 @@ Common keyword arguments for regular and parallel sampling are:
7171
- `progress` (default: `AbstractMCMC.PROGRESS[]` which is `true` initially): toggles progress logging
7272
- `chain_type` (default: `Any`): determines the type of the returned chain
7373
- `callback` (default: `nothing`): if `callback !== nothing`, then
74-
`callback(rng, model, sampler, sample, state, iteration)` is called after every sampling step,
75-
where `sample` is the most recent sample of the Markov chain and `state` and `iteration` are the current state and iteration of the sampler
76-
- `discard_initial` (default: `0`): number of initial samples that are discarded
74+
`callback(rng, model, sampler, sample, iteration)` is called after every sampling step,
75+
where `sample` is the most recent sample of the Markov chain and `iteration` is the current iteration
76+
- `num_warmup` (default: `0`): number of "warm-up" steps to take before the first "regular" step,
77+
i.e. number of times to call [`AbstractMCMC.step_warmup`](@ref) before the first call to
78+
[`AbstractMCMC.step`](@ref).
79+
- `discard_initial` (default: `num_warmup`): number of initial samples that are discarded. Note that
80+
if `discard_initial < num_warmup`, warm-up samples will also be included in the resulting samples.
7781
- `thinning` (default: `1`): factor by which to thin samples.
82+
- `initial_state` (default: `nothing`): if `initial_state !== nothing`, the first call to [`AbstractMCMC.step`](@ref)
83+
is passed `initial_state` as the `state` argument.
7884

7985
!!! info
8086
The common keyword arguments `progress`, `chain_type`, and `callback` are not supported by the iterator [`AbstractMCMC.steps`](@ref) and the transducer [`AbstractMCMC.Sample`](@ref).
8187

8288
There is no "official" way for providing initial parameter values yet.
83-
However, multiple packages such as [EllipticalSliceSampling.jl](https://github.com/TuringLang/EllipticalSliceSampling.jl) and [AdvancedMH.jl](https://github.com/TuringLang/AdvancedMH.jl) support an `init_params` keyword argument for setting the initial values when sampling a single chain.
84-
To ensure that sampling multiple chains "just works" when sampling of a single chain is implemented, [we decided to support `init_params` in the default implementations of the ensemble methods](https://github.com/TuringLang/AbstractMCMC.jl/pull/94):
85-
- `init_params` (default: `nothing`): if `init_params isa AbstractArray`, then the `i`th element of `init_params` is used as initial parameters of the `i`th chain. If one wants to use the same initial parameters `x` for every chain, one can specify e.g. `init_params = FillArrays.Fill(x, N)`.
89+
However, multiple packages such as [EllipticalSliceSampling.jl](https://github.com/TuringLang/EllipticalSliceSampling.jl) and [AdvancedMH.jl](https://github.com/TuringLang/AdvancedMH.jl) support an `initial_params` keyword argument for setting the initial values when sampling a single chain.
90+
To ensure that sampling multiple chains "just works" when sampling of a single chain is implemented, [we decided to support `initial_params` in the default implementations of the ensemble methods](https://github.com/TuringLang/AbstractMCMC.jl/pull/94):
91+
- `initial_params` (default: `nothing`): if `initial_params isa AbstractArray`, then the `i`th element of `initial_params` is used as initial parameters of the `i`th chain. If one wants to use the same initial parameters `x` for every chain, one can specify e.g. `initial_params = FillArrays.Fill(x, N)`.
8692

8793
Progress logging can be enabled and disabled globally with `AbstractMCMC.setprogress!(progress)`.
8894

docs/src/design.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ the sampling step of the inference method.
6363
AbstractMCMC.step
6464
```
6565

66+
If one also has some special handling of the warmup-stage of sampling, then this can be specified by overloading
67+
68+
```@docs
69+
AbstractMCMC.step_warmup
70+
```
71+
72+
which will be used for the first `num_warmup` iterations, as specified as a keyword argument to [`AbstractMCMC.sample`](@ref).
73+
Note that this is optional; by default it simply calls [`AbstractMCMC.step`](@ref) from above.
74+
6675
## Collecting samples
6776

6877
!!! note

src/AbstractMCMC.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using ProgressLogging: ProgressLogging
88
using StatsBase: StatsBase
99
using TerminalLoggers: TerminalLoggers
1010
using Transducers: Transducers
11+
using FillArrays: FillArrays
1112

1213
using Distributed: Distributed
1314
using Logging: Logging
@@ -107,4 +108,18 @@ include("stepper.jl")
107108
include("transducer.jl")
108109
include("logdensityproblems.jl")
109110

111+
if isdefined(Base.Experimental, :register_error_hint)
112+
function __init__()
113+
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, _
114+
if Base.parentmodule(exc.f) == LogDensityProblems &&
115+
any(a -> a <: LogDensityModel, argtypes)
116+
print(
117+
io,
118+
"\n`AbstractMCMC.LogDensityModel` is a wrapper and does not itself implement the LogDensityProblems.jl interface. To use LogDensityProblems.jl methods, access the inner type with (e.g.) `logdensity(model.logdensity, params)` instead of `logdensity(model, params)`.",
119+
)
120+
end
121+
end
122+
end
123+
end
124+
110125
end # module AbstractMCMC

src/interface.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ current `state` of the sampler.
7373
"""
7474
function step end
7575

76+
"""
77+
step_warmup(rng, model, sampler[, state; kwargs...])
78+
79+
Return a 2-tuple of the next sample and the next state of the MCMC `sampler` for `model`.
80+
81+
When sampling using [`sample`](@ref), this takes the place of [`AbstractMCMC.step`](@ref) in the first
82+
`num_warmup` number of iterations, as specified by the `num_warmup` keyword to [`sample`](@ref).
83+
This is useful if the sampler has an initial "warmup"-stage that is different from the
84+
standard iteration.
85+
86+
By default, this simply calls [`AbstractMCMC.step`](@ref).
87+
"""
88+
step_warmup(rng, model, sampler; kwargs...) = step(rng, model, sampler; kwargs...)
89+
function step_warmup(rng, model, sampler, state; kwargs...)
90+
return step(rng, model, sampler, state; kwargs...)
91+
end
92+
7693
"""
7794
samples(sample, model, sampler[, N; kwargs...])
7895

0 commit comments

Comments
 (0)