Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 12 additions & 2 deletions pymc/sampling/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def __call__(self, trace: IBaseTrace, draw: Draw):


def instantiate_steppers(
model, steps: List[Step], selected_steps, step_kwargs=None
model,
steps: List[Step],
selected_steps: Dict[str, List[Any]],
step_kwargs: Optional[Dict[str, Dict]] = None,
) -> Union[Step, List[Step]]:
"""Instantiate steppers assigned to the model variables.

Expand Down Expand Up @@ -129,7 +132,14 @@ def instantiate_steppers(

unused_args = set(step_kwargs).difference(used_keys)
if unused_args:
raise ValueError("Unused step method arguments: %s" % unused_args)
s = "s" if len(unused_args) > 1 else ""
example_arg = sorted(unused_args)[0]
example_step = list(selected_steps.keys())[0]
raise ValueError(
f"Invalid key{s} found in step_kwargs: {unused_args}. "
"Keys must be step names and values valid kwargs for that stepper. "
f'Did you mean {{"{example_step}": {{"{example_arg}": ...}}}}?'
)

if len(steps) == 1:
return steps[0]
Expand Down
6 changes: 2 additions & 4 deletions tests/sampling/test_mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,11 @@ def test_sample_init(self):

def test_sample_args(self):
with self.model:
with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match=r"'foo'"):
pm.sample(50, tune=0, chains=1, step=pm.Metropolis(), foo=1)
assert "'foo'" in str(excinfo.value)

with pytest.raises(ValueError) as excinfo:
with pytest.raises(ValueError, match=r"'foo'") as excinfo:
pm.sample(50, tune=0, chains=1, step=pm.Metropolis(), foo={})
assert "foo" in str(excinfo.value)

def test_parallel_start(self):
with self.model:
Expand Down