Repository navigation
Separate BUGSExamples into standalone package (WIP) - #453
shravanngoswamii wants to merge 18 commits into
Conversation
3f4416f to
f76d4b0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #453 +/- ##
==========================================
+ Coverage 87.99% 88.26% +0.27%
==========================================
Files 29 29
Lines 3732 3742 +10
==========================================
+ Hits 3284 3303 +19
+ Misses 448 439 -9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
JuliaBUGS.jl documentation for PR #453 is available at: |
DocumenterVitepress's writer calls `Documenter.deploy_folder(...)` while `makedocs()` runs in order to compute the `bases` list it writes to `build/bases.txt`. `deploy_folder` requires `GITHUB_TOKEN` to recognise a CI build; without it the writer falls back to `all_ok=false, subfolder=""`, bases.txt ends up empty, and the deploy step then logs "Found no bases suitable for deployment" and exits without deploying. Plumbing the token through the build step fixes PR-preview deploys end-to-end for downstream packages that use `use-vitepress: 'true'` (observed on TuringLang/JuliaBUGS.jl#453). Co-Authored-By: Claude <noreply@anthropic.com>
When the rendered site is a Vitepress build, the TuringNavbar previously stayed pinned to its own hardcoded palette (`--primary-bg: white`, Source Sans Pro, heavy box-shadow) regardless of Vitepress's light/dark toggle. Visually the result was two stacked headers with totally different colour and typography on the same page (jarring on TuringLang/JuliaBUGS.jl#453). `html:has(.VPNavBar)` rebinds the navbar's CSS variables to Vitepress's own design tokens (`--vp-c-bg`, `--vp-c-text-1`, `--vp-c-brand-1`, `--vp-font-family-base`, ...) so the navbar follows the theme. Also trade the navbar's heavy shadow for a 1px divider so the boundary with the Vitepress nav below reads as one continuous chrome. Documenter HTML output is unaffected — `:has(.VPNavBar)` simply doesn't match anything there. Co-Authored-By: Claude <noreply@anthropic.com>
* add DocumenterVitepress support to DocsDocumenter action * DocsDocumenter: expose GITHUB_TOKEN to the build step DocumenterVitepress's writer calls `Documenter.deploy_folder(...)` while `makedocs()` runs in order to compute the `bases` list it writes to `build/bases.txt`. `deploy_folder` requires `GITHUB_TOKEN` to recognise a CI build; without it the writer falls back to `all_ok=false, subfolder=""`, bases.txt ends up empty, and the deploy step then logs "Found no bases suitable for deployment" and exits without deploying. Plumbing the token through the build step fixes PR-preview deploys end-to-end for downstream packages that use `use-vitepress: 'true'` (observed on TuringLang/JuliaBUGS.jl#453). Co-Authored-By: Claude <noreply@anthropic.com> * DocsNav: make TuringNavbar coexist with DocumenterVitepress The static HTML navbar is inserted right after <body>, but Vitepress's own .VPNav / .VPNavBar / .VPLocalNav are `position: fixed; top: 0` — they overlap the TuringLang navbar end-to-end. The existing CSS in TuringNavbar.html only handles Documenter HTML's `.docs-sidebar` / `#documenter`, which don't exist in a Vitepress build. Add a "DocumenterVitepress Tweaks" block that nudges every Vitepress top-pinned element down by `--navbar-height`. The selectors only match Vitepress output, so Documenter HTML rendering is unaffected. Co-Authored-By: Claude <noreply@anthropic.com> * DocsNav: inherit Vitepress design tokens for the TuringLang navbar When the rendered site is a Vitepress build, the TuringNavbar previously stayed pinned to its own hardcoded palette (`--primary-bg: white`, Source Sans Pro, heavy box-shadow) regardless of Vitepress's light/dark toggle. Visually the result was two stacked headers with totally different colour and typography on the same page (jarring on TuringLang/JuliaBUGS.jl#453). `html:has(.VPNavBar)` rebinds the navbar's CSS variables to Vitepress's own design tokens (`--vp-c-bg`, `--vp-c-text-1`, `--vp-c-brand-1`, `--vp-font-family-base`, ...) so the navbar follows the theme. Also trade the navbar's heavy shadow for a 1px divider so the boundary with the Vitepress nav below reads as one continuous chrome. Documenter HTML output is unaffected — `:has(.VPNavBar)` simply doesn't match anything there. Co-Authored-By: Claude <noreply@anthropic.com> * DocsNav: fix Vitepress chrome stacking — gap + content overlap Two bugs in the previous Vitepress overrides: 1. Both `.VPNav` (outer position:fixed) and `.VPNavBar` (inner position:relative inside `.VPNav`) were getting `top: var(--navbar-height)`. Relative-positioned children's `top` shifts them WITHIN their parent, so this double-offset the bar by `2 × --navbar-height` and produced a visible empty band between the TuringLang navbar and the Vitepress nav. Fix: shift only the outer `.VPNav`. 2. `.VPSidebar` and `.VPContent` were getting `padding-top: var(--navbar-height) !important`. That REPLACED Vitepress's own padding-top for its nav, so the content's top moved up by `var(--vp-nav-height) - var(--navbar-height)` — the Vitepress nav ended up floating in the middle of the page and content rendered both above and below it. Fix: - For `.VPSidebar` and `.VPLocalNav` (independently position:fixed at `top: var(--vp-nav-height)`) set `top: calc(var(--vp-nav-height) + var(--navbar-height))` so they clear both navs. - For `.VPContent` use `margin-top: var(--navbar-height)`. Margin is additive to Vitepress's existing padding-top, so the content correctly sits below both navs without removing the Vitepress nav padding. Co-Authored-By: Claude <noreply@anthropic.com> * DocsNav: use Vitepress's --vp-layout-top-height hook for stacking Replace the manual shift overrides for `.VPNav` / `.VPSidebar` / `.VPLocalNav` / `.VPContent` with a single rule that binds Vitepress's own `--vp-layout-top-height` variable to the TuringLang navbar height. Vitepress's default theme is authored exactly for this case: every layout-sensitive component already adds `--vp-layout-top-height` to its own offset (verified against vitepress@1.6.4 — `VPNav.vue` uses `top: var(--vp-layout-top-height, 0px)`, `VPContent.vue` uses `margin: var(--vp-layout-top-height, 0px) ...`, `VPSidebar.vue` uses `top: var(--vp-layout-top-height, 0px)`, `VPLocalNav.vue` uses `padding-top: var(--vp-layout-top-height, 0px)`, and `VPDoc.vue`'s sticky aside includes the variable in its `padding-top` calc). Using the hook fixes: - The empty band that the previous `.VPNav` + `.VPNavBar` double-shift produced. - The content / TOC clipping behind the Vitepress nav from `padding-top:var(--navbar-height) !important` replacing Vitepress's own padding. - The sidebar dropping far below the Vitepress nav because manual `calc(--vp-nav-height + --navbar-height)` over-counted Vitepress's internal padding. Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
|
@shravanngoswamii anything I can help with? |
Actually, I am moving DoodleBUGS core codebase to mcmcjs, so things here will require later efforts. So I am holding this until porting to mcmcjs completes. Once DoodleBUGS core is in mcmcjs, than only DoodleBUGS web app will live here and everything else will be managed by mcmcjs cli |
Volume 3 was never included in the BUGSExamples module. Fourteen of its eighteen examples compile as written; the other four need language features JuliaBUGS does not have yet (partially observed multivariate nodes in Camel, dloglik in Fire, interp.lin in Jama and St Veit). Three latent bugs surfaced while enabling it. Each example file assigns bare names into one shared module scope, so a file that omits one silently inherits the previous file's value: - Volume_3/05_Hepatitis_ME.jl passed reference_results, which leaked in from 05_Hepatitis.jl, instead of its own reference_results_me. - Volume_2/04_Biopsies.jl spells its initial values intis, so the Example got 03_Multivariate_Orange_trees.jl's inits instead. - Volume_4/11_Methadone.jl called joinpath(readdir(), ...), which has no method, named a file that does not exist, and never built an Example. Also enables Stagnant and Asia, which compile fine and were commented out without a recorded reason. Inhalers stays disabled: its Example call had the wrong arity, and fixing that reveals the real blocker, a cyclic graph from using the logical node group[i] as an index. Registered examples go from 34 to 50.
The 19 Volume 1 example pages were wrapped in hide(), so they built but never appeared in the sidebar and nobody could find them. They are now a top-level Examples section split by volume. Volume 2 and 3 pages are generated by docs/gen_examples.jl. They hold no copy of the model, data, or initial values: each page pulls those from JuliaBUGS.BUGSExamples at build time, so there is one source of truth and the pages cannot drift from the registry. The generator probes each example first and, where JuliaBUGS cannot compile it yet, renders the compile step as an unexecuted block under a warning naming the actual limitation instead of failing the build. It never overwrites a page whose PROSE marker has been filled in, so hand-written prose can be layered in per page. Twelve Volume 1 pages now carry a live graph, the twelve models whose graphs ship inside doodleppl. docs/src/assets/doodleppl.js injects the widget bundle only on pages that embed one, pins it to 0.8.1 with an SRI hash, and mirrors Documenter's light/dark theme onto the widget through a MutationObserver on the html class, which is how Documenter signals a theme change. If the CDN is unreachable, as in an offline build, the embed collapses to a short note pointing at the model definition above it. Docs build clean: 79 pages, 52 of them examples.
a6dd25d to
b5310e0
Compare
Also simplifies the Methadone data construction. The original built a NamedTuple through two nested comprehensions that the formatter could only wrap into a very long line; a generator splat reads better and stays stable under the formatter.
Every generated page now opens with a real description of the data and the model instead of the placeholder, so the PROSE marker is gone from all 30 and the generator will no longer overwrite them. Four formulas were wrong before this and are fixed. They share a cause: the OpenBUGS pages render Greek in a symbol font, so text copied from them turns mu into m, alpha into a, and tau into T. The in-tree Volume_2/01_Dugongs.md still shows the damage. Every formula on these pages was checked symbol by symbol against the @bugs block it describes. Some substantive corrections came out of that check. The Stagnant page claimed the log density has jump discontinuities at the covariate values; it does not, the branch multiplier is zero exactly where the branch switches, so the density is continuous and merely kinked. The real difficulty is the correlation between alpha and the changepoint. Alligators notes that the published table counts 221 animals while the shipped array sums to 219. Eye Tracking notes that the stored reference results come from the fixed-A/B run while the model samples both. Passages that tracked the OpenBUGS wording too closely were rewritten. That documentation is GPL-3 and this package is MIT, so the pages paraphrase and cite rather than reproduce. The new bugsexamples test group compiles every registered example and asserts that no two share reference_results, inits, or inits_alternative by identity. That is the regression test for the shared-module-scope bug: a file that forgets to define one of those silently inherits the previous file's value, which is how Hepatitis ME published Hepatitis's numbers and how Biopsies used the orange-trees initial values. There are no collisions across all 50. 399 assertions pass. Docs build clean: 79 pages, 12 with a live graph.
The docs build failed on endo: it compiles from some random starting values and throws DomainError from others, and the generator had probed it once, seen it succeed, and emitted an executable block. The single probe was hiding a second, worse problem. The hand-written Volume 1 pages call epil(data, inits), passing the example's own initial values, which is exactly why epil, kidney and leukfr never flake. The generated pages passed no inits at all. Testing both ways: epil, kidney, leukfr, endo and alligators all fail bare and succeed with inits, so the alligators page was about to ship a 'JuliaBUGS cannot compile this model yet' warning that is simply untrue. biopsies goes the other way. Its initial values leave missing in the upper triangle of error, which Multinomial rejects, so it needs the bare call even though it has inits. The generator now tries each call eight times and takes the first that never fails, and the probe and the page make the identical call so the probe proves something. Every page compiles for real: 25 with inits, 5 bare, no warnings. Docs build clean: 79 pages, 12 with a live graph.
The generator carried a graph-embedding path that could never fire: all twelve keys in BUNDLED_GRAPHS are Volume 1 keys and the generator only emits Volume 2 and 3, so no generated page has ever contained a doodle-ppl element. The twelve real embeds are hand-written in the Volume 1 pages. Also gone: page_title, whose two branches returned the same value, and the volume_1 and volume_4 entries in three dicts that are only ever indexed by the two volumes it generates. The Sampling section is deleted from all thirty pages. It was byte-identical on every one of them, was never executed, and contradicted the section directly above it: twenty-five pages compile with inits and say inits are not optional, and the Sampling block then recompiled without them. On the five Fun Shapes pages it recommended NUTS with Mooncake on models whose own prose says there is no gradient anywhere. The pages now link to Getting Started instead. Three real bugs came out of the same pass. The reference-results guard tested only for nothing, so an empty NamedTuple passed it and six pages rendered the line about published posterior summaries above nothing at all; the five Fun Shapes rendered an empty Data section too, on pages whose prose says they have no data. The eye_tracking page told readers to look at a reference_results_variable field, which is a bare binding in the source file and not one of the seven fields of Example, so the call throws. Volume_3/notes.md said Eye Tracking and Hips2 through Hips4 were blocked by discrete variables and graph loops. All four compile and are registered by this PR, so it now records what is actually true per file. The Pigs and Simulated data rows in notes.md claimed modelling limitations for source files that are one byte long. Test cleanup: four assertions were tautologies guaranteed by the struct's field types, and the compile testset duplicated test/model/bugsmodel.jl, which already compiles all of Volume 1 with inits. Its skip list called kidney, leukfr and epil known-broken on main when that test compiles them successfully every run. It now covers only the volumes this PR adds, and picks the compile call per example the way the pages do. Folded into the compilation_model group rather than paying two more CI jobs for a seventy-line file. Dropped the Methadone changes: Volume_4 is included nowhere, so all sixty-two lines were unreachable, and this PR's own index page explains Volume 4 is out of scope. Also dropped the unused doodleppl-caption CSS and the index Model column, which repeated the link text beside it on all thirty rows. gen_examples.jl goes from 356 to 265 lines. Docs build clean: 79 pages, 12 with a live graph. 310 assertions pass.
e3791c2 to
c859b31
Compare
docs/gen_bundles.jl writes each registered example as a model file, a data file, and a shell script that fits it with the mcmcjs CLI and exports one self-contained run bundle. The bundles can be hosted anywhere and opened in the report app through a bundle URL, which is what lets an example page link to real posterior results instead of only the published summary table. Two details had to be got right and are worth recording. The model file carries the original BUGS program verbatim and parses it with the string form of @bugs; deparsing model_def instead produces a quote block, which @bugs rejects. And the data has to be written row by row, because the Julia driver rebuilds matrices with stack(elems; dims = 1) while JSON.print writes a matrix column-wise, so the 30 by 5 outcome matrix in Rats arrives transposed and the fit dies on the first out-of-range index. The sampler settings are the ones the OpenBUGS pages report for these examples, a 1000 update burn in followed by a further 10000 updates, over the two chains implied by the two sets of initial values every example ships. Thinning by 10 keeps 1000 of those 10000 draws so a bundle stays inside the size the report app will fetch; the sampling effort is unchanged. Verified on two examples. Rats reproduces the published table, alpha0 106.6 against 106.6 and sigma 6.079 against 6.093, from a 2.7 MB bundle, and Pumps fits in 55 s to 775 KB. JuliaBUGS samples with NUTS where OpenBUGS used Gibbs, so posterior means agree but Monte Carlo error will not, and that belongs on any page that shows both. The script only writes files, so it adds no dependency on mcmcjs, and fitting stays a separate deliberate step because the full set takes hours.
The workflow that fits these needs to do a volume at a time, since the full set is hours of sampling, so the selector now takes volume_1, volume_2, volume_3, all, or a single example key. The generated run.sh no longer uses set -e. A model that fails is reported and skipped, and the script exits with the number of failures, because losing an hour of finished fits to one bad model is worse than an incomplete set.
|
A preview of this pull request has been deployed. |
Benchmark ResultsJulia 1.11.9 on AMD EPYC 9V74 80-Core Processor (Linux) Ratio = JuliaBUGS/Stan (lower is better for JuliaBUGS)
Note: Stan benchmarks use hand-optimized Stan models, not direct BUGS translations. Comparison is illustrative only. |
Closes #436 (partially — work-in-progress; see
REMAINING_WORK.mdin the workspace for the full tracking doc).Summary
Splits the BUGSExamples module out of the JuliaBUGS package into a standalone subpackage at
BUGSExamples/, with its own Project.toml, tests, CI, and Literate.jl + DocumenterVitepress docs site (with DoodleBUGS graph embeds where available).BUGSExamples/package — UUIDcb193daa-…-89ec8f36026b, only depends onJSON. No JuliaBUGS dependency — model code is stored as plain strings.BUGSExamplestruct (name,original_syntax_program,model_def,model_function,stan_code,numpyro_code,data,inits,inits_alternative,reference_results).data_loader.jlthat convertsdata.json→ typedNamedTuple(handles nested vectors → matrices).src/<example>/model.jlbecomes a page.docs/src/.vitepress/config.mtsand theme-synced viapublic/sync_theme.js..github/workflows/BUGSExamplesTests.yml(Julia 1.10/1.11/pre) andBUGSExamplesDocs.yml(DocumenterVitepress deploy undergh-pages/BUGSExamples/).Example.model_def::Expr(old) →BUGSExample.model_def::String(new). Consumers should switch to@bugs(ex.original_syntax_program)instead of usingmodel_defdirectly.What's in this PR
rats,pumpsWhat's NOT in this PR (follow-ups)
The full plan lives in
REMAINING_WORK.mdin the workspace. Highlights:test/runtests.jlis a placeholder).JuliaBUGS/src/BUGSExamples/and migrate 6 JuliaBUGS test files that reach intoJuliaBUGS.BUGSExamples.*— this is where the breakingmodel_def: Expr → Stringchange lands.DoodleBUGS/pr-previews/451/lib/…).TuringLang/BUGSExamples.jl.Test plan
BUGSExamplespackage builds:julia --project=BUGSExamples -e 'using BUGSExamples; BUGSExamples.list()'BUGSExamplesTests.ymlgreen on Julia 1.10 / 1.11 / preBUGSExamplesDocs.ymlbuilds the Vitepress site and the DoodleBUGS widget renders for the rats and pumps pages🤖 Generated with Claude Code