Skip to content

Commit

Permalink
Merge pull request #66 from TuringLang/ml/callback
Browse files Browse the repository at this point in the history
  • Loading branch information
mileslucas authored Apr 10, 2021
2 parents d961513 + 0a8ae72 commit 232fb36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
keywords = ["markov chain monte carlo", "probablistic programming"]
license = "MIT"
desc = "A lightweight interface for common MCMC methods."
version = "3.0.0"
version = "3.0.1"

[deps]
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
Expand Down
4 changes: 2 additions & 2 deletions src/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function mcmcsample(
end

# Run callback.
callback === nothing || callback(rng, model, sampler, sample, 1)
callback === nothing || callback(rng, model, sampler, sample, state, 1; kwargs...)

# Save the sample.
samples = AbstractMCMC.samples(sample, model, sampler; kwargs...)
Expand All @@ -217,7 +217,7 @@ function mcmcsample(
sample, state = step(rng, model, sampler, state; kwargs...)

# Run callback.
callback === nothing || callback(rng, model, sampler, sample, i)
callback === nothing || callback(rng, model, sampler, sample, state, i; kwargs...)

# Save the sample.
samples = save!!(samples, sample, i, model, sampler; kwargs...)
Expand Down
9 changes: 7 additions & 2 deletions test/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,16 @@

@testset "Testing callbacks" begin
function count_iterations(rng, model, sampler, sample, state, i; iter_array, kwargs...)
iter_array[i] = i
push!(iter_array, i)
end
N = 100
it_array = zeros(N)
it_array = Float64[]
sample(MyModel(), MySampler(), N; callback=count_iterations, iter_array=it_array)
@test it_array == collect(1:N)

# sampling without predetermined N
it_array = Float64[]
chain = sample(MyModel(), MySampler(); callback=count_iterations, iter_array=it_array)
@test it_array == collect(1:size(chain, 1))
end
end

4 comments on commit 232fb36

@mileslucas
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Error while trying to register: Register Failed
@mileslucas, it looks like you are not a publicly listed member/owner in the parent organization (TuringLang).
If you are a member/owner, you will need to change your membership to public. See GitHub Help

@cpfiffer
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/34003

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.0.1 -m "<description of version>" 232fb3690f68fd59f4dcee5b9a0ac6a5f128e8c6
git push origin v3.0.1

Please sign in to comment.