Skip to content

Commit 147cdcb

Browse files
committed
Add context pretty-printing
1 parent f3603ff commit 147cdcb

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
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

+12-3
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,15 @@ function prefix_cond_and_fixed_variables(
819819
end
820820

821821
_pretty(ctx::AbstractContext) = split(string(ctx), "Context")[1]
822-
pretty_context(ctx::AbstractContext) = pretty_context(NodeTrait(ctx), ctx)
823-
pretty_context(::IsLeaf, ctx) = _pretty(ctx)
824-
pretty_context(::IsParent, ctx) = _pretty(ctx) * "->" * pretty_context(childcontext(ctx))
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)