Skip to content

Commit db1f96c

Browse files
committed
Add pretty-printing for context stacks
1 parent e75fd1e commit db1f96c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Project.toml

+1-1
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.1"
3+
version = "0.36.2"
44

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

src/contexts.jl

+14
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)