-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Remove unreachable lines of sampling code #4261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5e6f189
to
f2967dd
Compare
Codecov Report
@@ Coverage Diff @@
## master #4261 +/- ##
==========================================
- Coverage 88.15% 88.14% -0.02%
==========================================
Files 87 87
Lines 14243 14242 -1
==========================================
- Hits 12556 12553 -3
- Misses 1687 1689 +2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring should be improved and type annotations could be added:
steps : step function or vector of step functions
One or more step functions that have been assigned to some subset of
the model's parameters. Defaults to None (no assigned variables).
In contrast to what the docstring says, the code assumes that steps
is a list and it can be empty.
This code should trigger line 138:
with pymc3.Model() as model:
n = pymc3.Normal("n")
u = pymc3.Normal("u")
steppers = pymc3.sampling.instantiate_steppers(
_model=model,
steps=[
pymc3.Slice([u])
],
selected_steps={
pymc3.Metropolis : [n],
pymc3.NUTS : [],
}
)
print(steppers)
Granted, it is not typically used that way, but instead of removing that len(vars)
check, I would suggest to indent lines 134-138 and invert the condition.
pymc3/sampling.py
Outdated
the model's parameters. Defaults to None (no assigned variables). | ||
the model's parameters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
has no .append
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHould be like this:
steps : list
A list of zero or more step function instances that have been assigned to some subset of
the model's parameters.
Thanks for your review and help here, I've updated - for now I've just updated the docstring and inverted the condition, as I haven't figured out how to type some of the objects here yet (e.g. variables) |
pymc3/sampling.py
Outdated
selected_steps : dictionary of step methods and variables | ||
The step methods and the variables that have were assigned to them. | ||
The step methods and the (possibly zero) variables that have were assigned to them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here, it should say
selected_steps : dict
A dictionary that maps a step method class to a list of model variables.
pymc3/sampling.py
Outdated
selected_steps : dictionary of step methods and variables | ||
The step methods and the variables that have were assigned to them. | ||
The step methods and the (possibly zero) variables that have were assigned to them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here, it should say
selected_steps : dict
A dictionary that maps a step method class to a list of model variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure - I've added zero or more
here because it's the fact that there could be zero here which was causing the continue
line to be uncovered
Thanks @MarcoGorelli and @michaelosthege. |
I may be wrong here, but I think these lines are unreachable. I was trying to write a sensible test which covers them, but I think that might not be possible.
The function
instantiate_steppers
is only ever called fromassign_step_methods
.In
assign_step_methods
, there isWe have two cases:
If
model
has no unnassigned free random variables, thenselected_steps
will be empty and so the loopfor step_class, vars in selected_steps.items():
ininstantiate_steppers
will never be reached.if
model
has unnasigned free random variables, thenselected_steps[selected]
will be a list withvar
in it, and soif len(vars) == 0
will never be True.In both cases, the
continue
inwon't be reached.
cc @michaelosthege - does this look right to you, or am I missing something?