Skip to content

Add show_context_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

Closed
wants to merge 2 commits into from
Closed

Conversation

penelopeysm
Copy link
Member

@penelopeysm penelopeysm commented May 3, 2025

The docstring says it all. Basically this is a method I've been wanting for ages and I finally decided to implement it after realising that GibbsContext contains a complete VarInfo inside it and it's impossible to parse the output of @show context. Obviously I could just run this myself every time I needed it, but I thought it might be useful enough to be added to DynamicPPL itself, hence the PR.

Not even sure if this warrants a patch bump + release, opinions are welcome.

Copy link

codecov bot commented May 3, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 82.81%. Comparing base (cf2ca27) to head (00a4b6b).

Files with missing lines Patch % Lines
src/contexts.jl 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #909      +/-   ##
==========================================
- Coverage   82.92%   82.81%   -0.11%     
==========================================
  Files          36       36              
  Lines        3964     3969       +5     
==========================================
  Hits         3287     3287              
- Misses        677      682       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 14815463313

Details

  • 0 of 4 (0.0%) changed or added relevant lines in 1 file are covered.
  • 17 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.3%) to 84.76%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/contexts.jl 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
src/model.jl 1 85.83%
src/threadsafe.jl 16 55.05%
Totals Coverage Status
Change from base Build 14706709520: -0.3%
Covered Lines: 3326
Relevant Lines: 3924

💛 - Coveralls

@coveralls
Copy link

coveralls commented May 3, 2025

Pull Request Test Coverage Report for Build 14815463313

Details

  • 0 of 4 (0.0%) changed or added relevant lines in 1 file are covered.
  • 17 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.09%) to 85.015%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/contexts.jl 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
src/model.jl 1 85.83%
src/threadsafe.jl 16 55.05%
Totals Coverage Status
Change from base Build 14706709520: -0.09%
Covered Lines: 3336
Relevant Lines: 3924

💛 - Coveralls

Copy link
Member

@mhauru mhauru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the docstring has an example, could that be a doctest?

I wonder if this should be a show(::AbstractContext, ::MIME"text/plain") method. Maybe it omits too much, and the -> thing is too non-standard?

Happy to release this with a patch bump or wait for the next release.

@penelopeysm
Copy link
Member Author

I think making this the default show method is a bit too dangerous, it's sometimes useful to see e.g. the sampler in SamplingContext or the values in Condition/FixedContext.
I'll add tests...

@penelopeysm penelopeysm changed the title Add show_stack(::AbstractContext) Add show_context_stack(::AbstractContext) Jun 3, 2025
Copy link
Contributor

github-actions bot commented Jun 3, 2025

Benchmark Report for Commit 00a4b6b

Computer Information

Julia Version 1.11.5
Commit 760b2e5b739 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × AMD EPYC 7763 64-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver3)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)

Benchmark Results

|                 Model | Dimension |  AD Backend |      VarInfo Type | Linked | Eval Time / Ref Time | AD Time / Eval Time |
|-----------------------|-----------|-------------|-------------------|--------|----------------------|---------------------|
| Simple assume observe |         1 | forwarddiff |             typed |  false |                  9.5 |                 1.5 |
|           Smorgasbord |       201 | forwarddiff |             typed |  false |                733.0 |                37.5 |
|           Smorgasbord |       201 | forwarddiff | simple_namedtuple |   true |                365.2 |                58.4 |
|           Smorgasbord |       201 | forwarddiff |           untyped |   true |               1219.9 |                30.1 |
|           Smorgasbord |       201 | forwarddiff |       simple_dict |   true |               3850.6 |                20.9 |
|           Smorgasbord |       201 | reversediff |             typed |   true |               1458.0 |                29.4 |
|           Smorgasbord |       201 |    mooncake |             typed |   true |                944.9 |                 5.3 |
|    Loop univariate 1k |      1000 |    mooncake |             typed |   true |               5520.5 |                 4.2 |
|       Multivariate 1k |      1000 |    mooncake |             typed |   true |               1024.2 |                 8.8 |
|   Loop univariate 10k |     10000 |    mooncake |             typed |   true |              61295.2 |                 3.8 |
|      Multivariate 10k |     10000 |    mooncake |             typed |   true |               8832.6 |                 9.8 |
|               Dynamic |        10 |    mooncake |             typed |   true |                129.2 |                14.2 |
|              Submodel |         1 |    mooncake |             typed |   true |                 13.7 |                 6.5 |
|                   LDA |        12 | reversediff |             typed |   true |                450.0 |                 5.3 |

@penelopeysm
Copy link
Member Author

I kind of thought about it a bit more, and I'm not sure if this belongs in DPPL proper. I feel like it's a useful function to define for docs, and it was useful for debugging, but it just feels a bit too much like a personal-utility thing to put in here. :/

Feel free to reopen and review again if you disagree, @mhauru as it's in a mergeable state (I added doctests)

@penelopeysm penelopeysm closed this Jun 3, 2025
@penelopeysm penelopeysm deleted the py/pretty branch June 3, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants