Skip to content

Commit 947909c

Browse files
Show warning message if initial_parameters is passed instead of initial_params
1 parent fc74dd4 commit 947909c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/sample.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ function mcmcsample(
405405
initial_state=nothing,
406406
kwargs...,
407407
)
408+
# Warn if initial_parameters is passed instead of initial_params
409+
if haskey(kwargs, :initial_parameters)
410+
@warn "The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
411+
end
412+
408413
# Check if actually multiple threads are used.
409414
if Threads.nthreads() == 1
410415
@warn "Only a single thread available: MCMC chains are not sampled in parallel"
@@ -588,6 +593,11 @@ function mcmcsample(
588593
initial_state=nothing,
589594
kwargs...,
590595
)
596+
# Warn if initial_parameters is passed instead of initial_params
597+
if haskey(kwargs, :initial_parameters)
598+
@warn "The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
599+
end
600+
591601
# Check if actually multiple processes are used.
592602
if Distributed.nworkers() == 1
593603
@warn "Only a single process available: MCMC chains are not sampled in parallel"
@@ -727,6 +737,11 @@ function mcmcsample(
727737
initial_state=nothing,
728738
kwargs...,
729739
)
740+
# Warn if initial_parameters is passed instead of initial_params
741+
if haskey(kwargs, :initial_parameters)
742+
@warn "The `initial_parameters` keyword argument is not recognised; please use `initial_params` instead."
743+
end
744+
730745
# Check if the number of chains is larger than the number of samples
731746
if nchains > N
732747
@warn "Number of chains ($nchains) is greater than number of samples per chain ($N)"

test/sample.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
)
3232
@test chain[1].a == -1.8
3333
@test chain[1].b == 3.2
34+
35+
# test warning for initial_parameters (typo)
36+
# Note: initial_parameters will be ignored, but it should warn the user
37+
@test_logs (:warn, r"initial_parameters.*not recognised.*initial_params") (:warn,) sample(
38+
MyModel(), MySampler(), MCMCThreads(), 3, 2; progress=false, initial_parameters=(b=1.0, a=2.0)
39+
)
3440
end
3541

3642
@testset "IJulia" begin
@@ -282,6 +288,11 @@
282288
MyModel(), MySampler(), MCMCDistributed(), 5, 10; chain_type=MyChain
283289
)
284290

291+
# Test warning for initial_parameters (typo)
292+
@test_logs (:warn, r"initial_parameters.*not recognised.*initial_params") sample(
293+
MyModel(), MySampler(), MCMCDistributed(), 3, 2; progress=false, initial_parameters=(b=1.0, a=2.0)
294+
)
295+
285296
# Suppress output.
286297
logs, _ = collect_test_logs(; min_level=Logging.LogLevel(-1)) do
287298
sample(
@@ -408,6 +419,11 @@
408419
MyModel(), MySampler(), MCMCSerial(), 5, 10; chain_type=MyChain
409420
)
410421

422+
# Test warning for initial_parameters (typo)
423+
@test_logs (:warn, r"initial_parameters.*not recognised.*initial_params") sample(
424+
MyModel(), MySampler(), MCMCSerial(), 3, 2; progress=false, initial_parameters=(b=1.0, a=2.0)
425+
)
426+
411427
# Suppress output.
412428
logs, _ = collect_test_logs(; min_level=Logging.LogLevel(-1)) do
413429
sample(

0 commit comments

Comments
 (0)