Skip to content

Commit 917057b

Browse files
committed
Add pretty-printing for context stacks
1 parent cf2ca27 commit 917057b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# DynamicPPL Changelog
22

3+
## 0.36.12
4+
5+
Added an unexported method, `DynamicPPL.show_context_stack`, for minimalistic printing of context stacks (which is useful when debugging e.g. submodels).
6+
37
## 0.36.11
48

59
Make `ThreadSafeVarInfo` hold a total of `Threads.nthreads() * 2` logp values, instead of just `Threads.nthreads()`.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.36.11"
3+
version = "0.36.12"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/contexts.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,3 +817,17 @@ function prefix_cond_and_fixed_variables(
817817
context, prefix_cond_and_fixed_variables(childcontext(context), prefix)
818818
)
819819
end
820+
821+
_pretty(ctx::AbstractContext) = split(string(ctx), "Context")[1]
822+
"""
823+
show_stack(ctx::AbstractContext)
824+
825+
Return a minimalistic string representation of the context stack `ctx`. Useful
826+
for debugging complicated context problems, e.g. with submodels.
827+
828+
For example, `SamplingContext(ConditionContext(..., DefaultContext())` will
829+
print as `Sampling->Condition->Default`.
830+
"""
831+
show_stack(ctx::AbstractContext) = show_stack(NodeTrait(ctx), ctx)
832+
show_stack(::IsLeaf, ctx) = _pretty(ctx)
833+
show_stack(::IsParent, ctx) = _pretty(ctx) * "->" * show_stack(childcontext(ctx))

0 commit comments

Comments
 (0)