Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ function mcmcsample(
initial_state=nothing,
kwargs...,
)
# Warn if initial_parameters is passed instead of initial_params
if haskey(kwargs, :initial_parameters)
@warn "The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
end

# Check if actually multiple threads are used.
if Threads.nthreads() == 1
@warn "Only a single thread available: MCMC chains are not sampled in parallel"
Expand Down Expand Up @@ -588,6 +593,11 @@ function mcmcsample(
initial_state=nothing,
kwargs...,
)
# Warn if initial_parameters is passed instead of initial_params
if haskey(kwargs, :initial_parameters)
@warn "The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
end

# Check if actually multiple processes are used.
if Distributed.nworkers() == 1
@warn "Only a single process available: MCMC chains are not sampled in parallel"
Expand Down Expand Up @@ -727,6 +737,11 @@ function mcmcsample(
initial_state=nothing,
kwargs...,
)
# Warn if initial_parameters is passed instead of initial_params
if haskey(kwargs, :initial_parameters)
@warn "The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
end

# Check if the number of chains is larger than the number of samples
if nchains > N
@warn "Number of chains ($nchains) is greater than number of samples per chain ($N)"
Expand Down
35 changes: 35 additions & 0 deletions test/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
)
@test chain[1].a == -1.8
@test chain[1].b == 3.2

# test warning for initial_parameters (typo)
# Note: initial_parameters will be ignored, but it should warn the user
@test_logs (:warn, r"initial_parameters.*not recognised.*initial_params") match_mode =
:any sample(
MyModel(),
MySampler(),
MCMCThreads(),
3,
2;
progress=false,
initial_parameters=(b=1.0, a=2.0),
)
end

@testset "IJulia" begin
Expand Down Expand Up @@ -282,6 +295,17 @@
MyModel(), MySampler(), MCMCDistributed(), 5, 10; chain_type=MyChain
)

# Test warning for initial_parameters (typo)
@test_logs (:warn, r"initial_parameters.*not recognised.*initial_params") sample(
MyModel(),
MySampler(),
MCMCDistributed(),
3,
2;
progress=false,
initial_parameters=(b=1.0, a=2.0),
)

# Suppress output.
logs, _ = collect_test_logs(; min_level=Logging.LogLevel(-1)) do
sample(
Expand Down Expand Up @@ -408,6 +432,17 @@
MyModel(), MySampler(), MCMCSerial(), 5, 10; chain_type=MyChain
)

# Test warning for initial_parameters (typo)
@test_logs (:warn, r"initial_parameters.*not recognised.*initial_params") sample(
MyModel(),
MySampler(),
MCMCSerial(),
3,
2;
progress=false,
initial_parameters=(b=1.0, a=2.0),
)

# Suppress output.
logs, _ = collect_test_logs(; min_level=Logging.LogLevel(-1)) do
sample(
Expand Down
Loading