Skip to content

Commit

Permalink
Add name to CompountStep
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoV94 committed May 30, 2022
1 parent 9e55cac commit 4430d78
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pymc/step_methods/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def __init__(self, methods):
for method in self.methods:
if method.generates_stats:
self.stats_dtypes.extend(method.stats_dtypes)
self.name = (
f"Compound[{', '.join(getattr(m, 'name', 'UNNAMED_STEP') for m in self.methods)}]"
)

def step(self, point):
if self.generates_stats:
Expand Down
10 changes: 10 additions & 0 deletions pymc/tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ def test_blocked(self):
assert not isinstance(sampler_instance, CompoundStep)
assert isinstance(sampler_instance, sampler)

def test_name(self):
with Model() as m:
c1 = HalfNormal("c1")
c2 = HalfNormal("c2")

step1 = NUTS([c1])
step2 = Slice([c2])
step = CompoundStep([step1, step2])
assert step.name == "Compound[nuts, slice]"


class TestAssignStepMethods:
def test_bernoulli(self):
Expand Down

0 comments on commit 4430d78

Please sign in to comment.