Skip to content

Add show_stack(::AbstractContext) #909

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.36.1"
version = "0.36.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
14 changes: 14 additions & 0 deletions src/contexts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -817,3 +817,17 @@
context, prefix_cond_and_fixed_variables(childcontext(context), prefix)
)
end

_pretty(ctx::AbstractContext) = split(string(ctx), "Context")[1]

Check warning on line 821 in src/contexts.jl

View check run for this annotation

Codecov / codecov/patch

src/contexts.jl#L821

Added line #L821 was not covered by tests
"""
show_stack(ctx::AbstractContext)

Return a minimalistic string representation of the context stack `ctx`. Useful
for debugging complicated context problems, e.g. with submodels.

For example, `SamplingContext(ConditionContext(..., DefaultContext())` will
print as `Sampling->Condition->Default`.
"""
show_stack(ctx::AbstractContext) = show_stack(NodeTrait(ctx), ctx)
show_stack(::IsLeaf, ctx) = _pretty(ctx)
show_stack(::IsParent, ctx) = _pretty(ctx) * "->" * show_stack(childcontext(ctx))

Check warning on line 833 in src/contexts.jl

View check run for this annotation

Codecov / codecov/patch

src/contexts.jl#L831-L833

Added lines #L831 - L833 were not covered by tests
Loading