File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -337,6 +337,7 @@ def sample(
337
337
of completion, the sampling speed in samples per second (SPS), and the estimated remaining
338
338
time until completion ("expected time of arrival"; ETA).
339
339
model : Model (optional if in ``with`` context)
340
+ Model to sample from. The model needs to have free random variables.
340
341
random_seed : int or list of ints
341
342
Random seed(s) used by the sampling steps. A list is accepted if
342
343
``cores`` is greater than one.
@@ -435,6 +436,11 @@ def sample(
435
436
p 0.609 0.047 0.528 0.699
436
437
"""
437
438
model = modelcontext (model )
439
+ if not model .free_RVs :
440
+ raise SamplingError (
441
+ "Cannot sample from the model, since the model does not contain any free variables."
442
+ )
443
+
438
444
start = deepcopy (start )
439
445
model_initial_point = model .initial_point
440
446
if start is None :
@@ -493,9 +499,6 @@ def sample(
493
499
494
500
draws += tune
495
501
496
- if not model .free_RVs :
497
- raise ValueError ("The model does not contain any free variables." )
498
-
499
502
if step is None and init is not None and all_continuous (model .value_vars ):
500
503
try :
501
504
# By default, try to use NUTS
Original file line number Diff line number Diff line change @@ -323,7 +323,7 @@ def test_sample_find_MAP_does_not_modify_start():
323
323
def test_empty_model ():
324
324
with pm .Model ():
325
325
pm .Normal ("a" , observed = 1 )
326
- with pytest .raises (ValueError ) as error :
326
+ with pytest .raises (SamplingError ) as error :
327
327
pm .sample ()
328
328
error .match ("any free variables" )
329
329
You can’t perform that action at this time.
0 commit comments