Skip to content
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

Rework of how transformations are handled #575

Merged
merged 198 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 165 commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
5af1afa
initial implementation of VarNameVector
torfjelde Oct 31, 2023
8ce53f7
added some hacky getval and getdist get things to work for VarInfo
torfjelde Nov 7, 2023
fc6a051
Apply suggestions from code review
torfjelde Nov 7, 2023
7cd599d
added arbitrary metadata field as discussed
torfjelde Nov 12, 2023
ed0a757
renamed idcs to varname_to_index
torfjelde Nov 12, 2023
4ebd252
renamed vns to varnames for VarNameVector
torfjelde Nov 12, 2023
9f12c9a
added keys impl for Metadata
torfjelde Nov 12, 2023
5a15121
added push! and update! for VarNameVector
torfjelde Nov 13, 2023
edde2c1
added getindex_raw! and setindex_raw! for VarNameVector
torfjelde Nov 13, 2023
ed46002
added `iterate` and `convert` (for `AbstractDict) impls for `VarNameV…
torfjelde Nov 13, 2023
5b00059
make the key and eltype part of the `VarNameVector` type
torfjelde Nov 13, 2023
bef7e0a
added more tests for VarNameVector
torfjelde Nov 13, 2023
006ee8d
formatting
torfjelde Nov 13, 2023
9802811
more testing for VarNameVector
torfjelde Nov 13, 2023
88b1721
minor changes to some comments
torfjelde Nov 13, 2023
ca7b173
added a bunch more tests for VarNameVector + several bugfixes in the …
torfjelde Nov 13, 2023
fb01b94
formatting
torfjelde Nov 13, 2023
9634839
added `similar` implementation for `VarNameVector`
torfjelde Nov 13, 2023
5179f6f
formatting
torfjelde Nov 13, 2023
9f632bb
removed debug statement
torfjelde Nov 13, 2023
3c210f7
made VarInfo slighly more generic wrt. underlying metadata
torfjelde Nov 13, 2023
8bf6589
Merge branch 'master' into torfjelde/varnamevector
torfjelde Nov 14, 2023
8b2720f
fixed incorrect behavior in `keys` for `Metadata`
torfjelde Nov 14, 2023
9fa6446
minor style changes to VarNameVector tests
torfjelde Nov 14, 2023
0900c57
style
torfjelde Nov 14, 2023
1f7e633
added testing of `update!` with smaller sizes and fixed bug related t…
torfjelde Nov 14, 2023
8d05586
formatting
torfjelde Nov 14, 2023
7801fe1
move functionality related to `push!` for `VarNameVector` into `push!`
torfjelde Nov 14, 2023
cdc2373
Update src/varnamevector.jl
torfjelde Nov 16, 2023
d2d776d
Merge branch 'master' into torfjelde/varnamevector
torfjelde Nov 20, 2023
ae4bcb7
several fixes to make sampling with VarNameVector + initiall tests for
torfjelde Dec 30, 2023
97e1bcc
VarInfo + VarNameVector tests for all demo models
torfjelde Dec 30, 2023
be3c1b4
Merge remote-tracking branch 'origin/torfjelde/varnamevector' into to…
torfjelde Dec 30, 2023
ad343f3
Apply suggestions from code review
torfjelde Dec 30, 2023
f707b25
added docs on the design of `VarNameVector`
torfjelde Dec 31, 2023
4e7af1d
Merge branch 'master' into torfjelde/varnamevector
torfjelde Dec 31, 2023
f1faf18
Apply suggestions from code review
torfjelde Dec 31, 2023
87d3d01
added note on `update!`
torfjelde Dec 31, 2023
9c3b265
further elaboration of the design of `VarInfo` and `VarNameVector`
torfjelde Jan 1, 2024
958c66b
more writing improvements
torfjelde Jan 1, 2024
74c6efd
added docstring to `has_inactive_ranges` and `inactive_ranges_sweep!`
torfjelde Jan 1, 2024
d9ea878
moved docs on `VarInfo` design to a separate internals section
torfjelde Jan 1, 2024
5acce98
writing improvements for internal docs
torfjelde Jan 1, 2024
6f95cdd
further motivation of the design choices made in `VarNameVector`
torfjelde Jan 1, 2024
38a4b08
improved writing
torfjelde Jan 1, 2024
60edd10
VarNameVector is now grown as much as needed
torfjelde Jan 1, 2024
3f9d34f
updated `delete!`
torfjelde Jan 2, 2024
fb822b5
Significant changes to implementation of `VarNameVector`:
torfjelde Jan 2, 2024
66bc090
added `copy` when constructing `VectorVarInfo` from `VarInfo`
torfjelde Jan 2, 2024
ccd86f2
added missing `isempty` impl
torfjelde Jan 2, 2024
1d4a000
remove impl of `iterate` and instead implemented `pairs` and `values`…
torfjelde Jan 2, 2024
9a16dd1
added missing `empty!` for `num_inactive`
torfjelde Jan 2, 2024
e49b762
removed redundant `shift_left!` methd
torfjelde Jan 2, 2024
2b445c9
fixed `delete!` for `VarNameVector`
torfjelde Jan 2, 2024
e3c2633
added `is_contiguous` as an alterantive to `!has_inactive`
torfjelde Jan 2, 2024
19a829c
updates to internal docs
torfjelde Jan 2, 2024
a358bc4
renamed `sweep_inactive_ranges!` to `contiguify!`
torfjelde Jan 2, 2024
46be8d5
improvements to internal docs
torfjelde Jan 2, 2024
57d688e
more improvements to internal docs
torfjelde Jan 2, 2024
0968a07
moved additional methods description in internals to earlier in the doc
torfjelde Jan 2, 2024
0d008a4
moved internals docs to a separate directory and split into files
torfjelde Jan 2, 2024
ccd0d64
more improvements to internals doc
torfjelde Jan 2, 2024
7c45e67
formatting
torfjelde Jan 2, 2024
373215b
added tests for `delete!` and fixed reference to old method
torfjelde Jan 2, 2024
0cdafbf
addition to `delete!` test
torfjelde Jan 2, 2024
51c041f
added `values_as` impls for `VarNameVector`
torfjelde Jan 2, 2024
20b3742
added docs for `replace_valus` and `values_as` for `VarNameVector`
torfjelde Jan 2, 2024
ef6c618
fixed doctest
torfjelde Jan 2, 2024
8a1209c
formatting
torfjelde Jan 2, 2024
adeadf0
temporarily disable doctests so we can build docs
torfjelde Jan 2, 2024
7ff179d
added missing compat entry for ForwardDiff in docs
torfjelde Jan 2, 2024
c7ec08a
moved some shared code into methods to make things a bit cleaner
torfjelde Jan 3, 2024
c5a5e58
added impl of `merge` for `VarNameVector`
torfjelde Jan 3, 2024
c376d95
renamed a few variables in `merge` impl for `VarNameVector`
torfjelde Jan 3, 2024
f71baa5
forgot to include some changes in previous commit
torfjelde Jan 3, 2024
af25f3c
added impl of `subset` for `VarNameVector`
torfjelde Jan 3, 2024
c28f076
fixed `pairs` impl for `VarNameVector`
torfjelde Jan 3, 2024
f5d2c63
added missing impl of `subset` for `VectorVarInfo`
torfjelde Jan 3, 2024
3eb6c7f
added missing impl of `merge_metadata` for `VarNameVector`
torfjelde Jan 3, 2024
9ba8144
added a bunch of `from_vec_transform` and `tovec` impls to make
torfjelde Jan 3, 2024
acd6951
make default args use `from_vec_transform` rather than `FromVec`
torfjelde Jan 3, 2024
790f743
fixed `values_as` fro `VarInfo` with `VarNameVector` as `metadata`
torfjelde Jan 3, 2024
c474bb0
fixed impl of `getindex_raw` when using integer index for `VarNameVec…
torfjelde Jan 4, 2024
8251463
added tests for `getindex` with `Int` index for `VarNameVector`
torfjelde Jan 4, 2024
5df7031
fix for `setindex!` and `setindex_raw!` for `VarNameVector`
torfjelde Jan 4, 2024
683b776
introduction of `from_vec_transform` and `tovec` and its usage in `Va…
torfjelde Jan 19, 2024
4dae00d
moved definition of `is_splat_symbol` to the file where it's used
torfjelde Jan 19, 2024
e3b52a4
added `VarInfo` constructor with vector input for `VectorVarInfo`
torfjelde Jan 19, 2024
9626be1
make `extract_priors` take the `rng` as an argument
torfjelde Jan 19, 2024
e731fd6
added `replace_values` for `Metadata`
torfjelde Jan 19, 2024
0785abf
make link and invlink act on the `metadata` field for `VarInfo` +
torfjelde Jan 19, 2024
b3e0955
added temporary defs of `with_logabsdet_jacobian` and `inverse` for
torfjelde Jan 19, 2024
ff963ce
added invlink_with_logpdf overload for `ThreadSafeVarInfo`
torfjelde Jan 19, 2024
03f2b2b
added `is_transformed` field to `VarNameVector`
torfjelde Jan 19, 2024
949b33a
removed unnecessary defintions of `with_logabsdet_jacobian` and
torfjelde Jan 19, 2024
cc5ecc4
fixed issue where we were storing the wrong transformations in `VarNa…
torfjelde Jan 19, 2024
1aae1b4
make sure `extract_priors` doesn't mutate the `varinfo`
torfjelde Jan 19, 2024
8e0853d
updated `similar` for `VarNameVector` and fixed `invlink` for `VarNam…
torfjelde Jan 19, 2024
229b168
added handling of `is_transformed` in `merge` for `VarNameVector`
torfjelde Jan 19, 2024
c581dcf
removed unnecesasry `deepcopy` from outer `link`
torfjelde Jan 19, 2024
b4d3f55
updated `push!` to also `push!` on `is_transformed`
torfjelde Jan 19, 2024
ed1d006
skip tests for mutating linking when using VarNameVector
torfjelde Jan 19, 2024
f132209
use same projection for `Cholesky` in `VarNameVector` as in `VarInfo`
torfjelde Jan 19, 2024
49454de
fixed `settrans!!` for `VarInfo` with `VarNameVector`
torfjelde Jan 19, 2024
01ff2dd
fixed bug in `set_flag!`
torfjelde Jan 19, 2024
20adedf
fixed another typo
torfjelde Jan 19, 2024
8f9566a
fixed return values of `settrans!!`
torfjelde Jan 19, 2024
5532046
updated static transformation tests
torfjelde Jan 20, 2024
3c5d2ac
Update test/simple_varinfo.jl
torfjelde Jan 20, 2024
317d969
Merge branch 'master' into torfjelde/varnamevector
torfjelde Jan 20, 2024
f8441ea
Merge remote-tracking branch 'origin/torfjelde/varnamevector' into to…
torfjelde Jan 25, 2024
ab16323
Merge branch 'master' into torfjelde/varnamevector
torfjelde Jan 25, 2024
a9be219
removed unnecessary impl of `extract_priors`
torfjelde Jan 25, 2024
53c8d33
make `short_varinfo_name` of `TypedVarInfo` a bit more informative
torfjelde Jan 25, 2024
61d85ad
moved impl of `has_varnamevector` for `ThreadSafeVarInfo`
torfjelde Jan 25, 2024
9ace554
added back `extract_priors` impl as we do need it
torfjelde Jan 25, 2024
67c9821
forgot to include tests for `VarNameVector` in `runtests.jl`
torfjelde Jan 25, 2024
32a2d31
fix for `relax_container_types` in `test/varnamevector.jl`
torfjelde Jan 25, 2024
b3bb42d
fixed `need_transforms_relaxation`
torfjelde Jan 26, 2024
25ff2b1
updated some tests to not refer directly to `FromVec`
torfjelde Jan 28, 2024
004f038
introduce `from_internal_transform` and its siblings
torfjelde Jan 28, 2024
38c89bd
remove `with_logabsdet_jacobian_and_reconstruct` in favour of
torfjelde Jan 28, 2024
218dc23
added `internal_to_linked_internal_transform` + fixed a few bugs in
torfjelde Jan 28, 2024
1df4293
added `linked_internal_to_internal_transform` as a complement to `int…
torfjelde Jan 28, 2024
f8df896
fixed bugs in `invlink` for `VarInfo` using `linked_internal_to_inter…
torfjelde Jan 28, 2024
d62f26a
more work on removing calls to `reconstruct`
torfjelde Jan 28, 2024
b4517d6
removed redundant comment
torfjelde Jan 28, 2024
b7d4754
added `from_linked_vec_transform` specialization for `LKJ`
torfjelde Jan 28, 2024
0244dd9
more work on removing references to `reconstruct`
torfjelde Jan 28, 2024
e886d07
added `copy` in `values_from_metadata` to preserve behavior and avoid
torfjelde Jan 28, 2024
2af6605
remove `reconstruct_and_link` and `invlink_and_reconstruct`
torfjelde Jan 28, 2024
a0664d7
replaced references to `link_and_reconstruct` and `invlink_and_recons…
torfjelde Jan 28, 2024
f2d59b2
introduced `recombine` and replaced calls to `reconstruct` with `n` s…
torfjelde Jan 28, 2024
e3bfa76
completely removed `reconstruct`
torfjelde Jan 28, 2024
c0aef81
renamed `maybe_reconstruct_and_link` to `to_maybe_linked_internal` and
torfjelde Jan 28, 2024
f7c0853
added impls of `from_*_internal_transform` for `ThreadSafeVarInfo`
torfjelde Jan 30, 2024
77b835e
removed `reconstruct` from docs and from exports
torfjelde Jan 30, 2024
b83c262
renamed `getval` to `getindex_internal` and made `dist` an optional
torfjelde Jan 31, 2024
c4faf3e
updated docs + added description of how internals of transforms work
torfjelde Jan 31, 2024
c8d9695
added a bunch of illustrations for the transforms docs + dot files us…
torfjelde Jan 31, 2024
95dc8e3
temporarily removed `VarNameVector` completely
torfjelde Jan 31, 2024
8930f9c
formatting
torfjelde Jan 31, 2024
e45b668
Update docs/src/internals/transformations.md
torfjelde Jan 31, 2024
0e71092
Update docs/src/internals/transformations.md
torfjelde Jan 31, 2024
2de9ac9
removed refs to VectorVarInfo
torfjelde Jan 31, 2024
9b71428
added impls of `from_internal_transform` for `ThreadSafeVarInfo`
torfjelde Feb 1, 2024
786e9bf
reverted accidental removal of old `VarInfo` constructor
torfjelde Feb 1, 2024
f1fe42c
fixed incorrect `recombine` call
torfjelde Feb 1, 2024
2273954
removed undefined refs to `VarNameVector` stuff in `setup_varinfos`
torfjelde Feb 1, 2024
ab7c189
bump minior version because Turing breaks
torfjelde Feb 1, 2024
3a86601
fix: was using `from_linked_internal_transform` in
torfjelde Feb 1, 2024
28c7d85
removed `getindex_raw`
torfjelde Feb 1, 2024
59514d6
removed redundant docstrings
torfjelde Feb 1, 2024
cdc882b
fixed tests
torfjelde Feb 1, 2024
57ba7c0
fixed comparisons in tests
torfjelde Feb 1, 2024
902e59c
try relative references for images in transformation docs
torfjelde Feb 1, 2024
d7aba55
another attempt at fixing asset-references
torfjelde Feb 3, 2024
b0dd2f8
Merge branch 'master' into torfjelde/transformations
torfjelde Feb 3, 2024
1f51203
fixed getindex diagrams in docs
torfjelde Feb 3, 2024
0eb79b1
minor changes to comments
torfjelde Feb 3, 2024
071bebf
remove Combinatorics as a test dep, as it's not needed for this PR
torfjelde Feb 3, 2024
bbdc060
reverted unnecessary change
torfjelde Feb 3, 2024
e2f4d18
disable type-stability tests for models on older Julia versions
torfjelde Feb 3, 2024
3d823ac
removed seemingly completely unused impl of `setval!`
torfjelde Feb 3, 2024
8750255
Merge branch 'master' into torfjelde/transformations
torfjelde Apr 16, 2024
ed6ee88
Merge branch 'master' into torfjelde/transformations
torfjelde Jun 18, 2024
607bdb3
Update test/model.jl
torfjelde Jun 18, 2024
55c8098
Apply suggestions from code review
torfjelde Jun 21, 2024
cc910d5
Merge remote-tracking branch 'origin/torfjelde/transformations' into …
torfjelde Jun 27, 2024
ec9f985
Merge branch 'master' into torfjelde/transformations
torfjelde Jul 14, 2024
a079606
Merge remote-tracking branch 'origin/torfjelde/transformations' into …
torfjelde Jul 19, 2024
ad959ec
Type-stability tests are now correctly using `rand_prior_true` instead
torfjelde Jul 21, 2024
9f84070
`getindex_internal` now calls `getindex` instead of `view`, as the
torfjelde Jul 21, 2024
7d39934
Removed seemingly unnecessary definition of `getindex_internal`
torfjelde Jul 21, 2024
b554504
Fixed references to `newmetadata` which has been replaced by `replace…
torfjelde Jul 28, 2024
ddb1dfe
Made implementation of `recombine` more explicit
torfjelde Jul 28, 2024
3b08f1d
Added docstrings for `untyped_varinfo` and `typed_varinfo`
torfjelde Jul 28, 2024
96ccebe
Added TODO comment about implementing `view` for `VarInfo`
torfjelde Jul 28, 2024
beaeeaa
Fixed potential infinite recursion as suggested by @mhauru
torfjelde Jul 28, 2024
ab2c98b
added docstring to `from_vec_trnasform_for_size
torfjelde Jul 28, 2024
f1f7968
Replaced references to `vectorize(dist, x)` with `tovec(x)`
torfjelde Jul 28, 2024
6e57822
Fixed docstring
torfjelde Jul 28, 2024
841215f
Update src/extract_priors.jl
torfjelde Jul 28, 2024
78b2083
Bump minor version since this is a breaking change
torfjelde Jul 28, 2024
b6ecf7b
Merge remote-tracking branch 'origin/torfjelde/transformations' into …
torfjelde Jul 28, 2024
7100ce1
Merge branch 'master' into torfjelde/transformations
torfjelde Jul 28, 2024
bab63e1
Apply suggestions from code review
sunxd3 Jul 30, 2024
6997019
Update src/varinfo.jl
sunxd3 Jul 30, 2024
9dc7f02
Apply suggestions from code review
torfjelde Jul 30, 2024
c0f9923
Apply suggestions from code review
torfjelde Jul 30, 2024
9056928
Update src/extract_priors.jl
torfjelde Aug 6, 2024
e43dd1b
Added fix for product distributions of targets with changing support …
torfjelde Aug 6, 2024
a7673fd
Addeed tests for product of distributions with dynamic support
torfjelde Aug 6, 2024
e8d4c96
Apply suggestions from code review
torfjelde Aug 6, 2024
d7c224e
Empty commit to trigger CI
mhauru Aug 14, 2024
951ffd5
Merge remote-tracking branch 'origin/master' into torfjelde/transform…
mhauru Aug 14, 2024
a0a8761
Update test/model.jl
torfjelde Aug 14, 2024
a8812e9
Increase HTML page size threshold for docs
mhauru Aug 21, 2024
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: 2 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Expand All @@ -14,6 +15,7 @@ DataStructures = "0.18"
Distributions = "0.25"
Documenter = "1"
FillArrays = "0.13, 1"
ForwardDiff = "0.10"
LogDensityProblems = "2"
MCMCChains = "5, 6"
StableRNGs = "1"
2 changes: 2 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ makedocs(;
"Home" => "index.md",
"API" => "api.md",
"Tutorials" => ["tutorials/prob-interface.md"],
"Internals" => ["internals/transformations.md"],
],
checkdocs=:exports,
doctest=false,
)

deploydocs(; repo="github.com/TuringLang/DynamicPPL.jl.git", push_preview=true)
108 changes: 54 additions & 54 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,62 @@ Please see the documentation of [AbstractPPL.jl](https://github.com/TuringLang/A

### Data Structures of Variables

DynamicPPL provides different data structures for samples from the model and their log density.
All of them are subtypes of [`AbstractVarInfo`](@ref).
DynamicPPL provides different data structures used in for storing samples and accumulation of the log-probabilities, all of which are subtypes of [`AbstractVarInfo`](@ref).

```@docs
AbstractVarInfo
```

But exactly how a [`AbstractVarInfo`](@ref) stores this information can vary.

#### `VarInfo`

```@docs
VarInfo
TypedVarInfo
```

One main characteristic of [`VarInfo`](@ref) is that samples are stored in a linearized form.

```@docs
link!
invlink!
```

```@docs
set_flag!
unset_flag!
is_flagged
```

For Gibbs sampling the following functions were added.

```@docs
setgid!
updategid!
```

The following functions were used for sequential Monte Carlo methods.

```@docs
get_num_produce
set_num_produce!
increment_num_produce!
reset_num_produce!
setorder!
set_retained_vns_del_by_spl!
```

```@docs
Base.empty!
```

#### `SimpleVarInfo`

```@docs
SimpleVarInfo
```

### Common API

#### Accumulation of log-probabilities
Expand All @@ -241,7 +290,7 @@ resetlogp!!
```@docs
keys
getindex
DynamicPPL.getindex_raw
DynamicPPL.getindex_internal
push!!
empty!!
isempty
Expand Down Expand Up @@ -269,8 +318,9 @@ DynamicPPL.invlink
DynamicPPL.link!!
DynamicPPL.invlink!!
DynamicPPL.default_transformation
DynamicPPL.link_transform
DynamicPPL.invlink_transform
DynamicPPL.maybe_invlink_before_eval!!
DynamicPPL.reconstruct
```

#### Utils
Expand All @@ -283,56 +333,6 @@ DynamicPPL.varname_leaves
DynamicPPL.varname_and_value_leaves
```

#### `SimpleVarInfo`

```@docs
SimpleVarInfo
```

#### `VarInfo`

Another data structure is [`VarInfo`](@ref).

```@docs
VarInfo
TypedVarInfo
```

One main characteristic of [`VarInfo`](@ref) is that samples are stored in a linearized form.

```@docs
link!
invlink!
```

```@docs
set_flag!
unset_flag!
is_flagged
```

For Gibbs sampling the following functions were added.

```@docs
setgid!
updategid!
```

The following functions were used for sequential Monte Carlo methods.

```@docs
get_num_produce
set_num_produce!
increment_num_produce!
reset_num_produce!
setorder!
set_retained_vns_del_by_spl!
```

```@docs
Base.empty!
```

### Evaluation Contexts

Internally, both sampling and evaluation of log densities are performed with [`AbstractPPL.evaluate!!`](@ref).
Expand Down
17 changes: 17 additions & 0 deletions docs/src/assets/images/transformations-assume-without-istrans.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
digraph {
Copy link
Member

Choose a reason for hiding this comment

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

Random thought: Could we use DocumenterMermaid and write the graphs as mermaid code blocks in the docs (BTW mermaid is supported also by Github: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be happy with this 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

So I'm having a look at this, and the main issue is that we can't do proper syntax highlighting 😕 This is a bit annoying, but also agree that the PNGs needed for the DOT diagrams are also annoying.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, so after some hacking, I think I have a solution that gets us syntax highlighting and stuff in Mermaid.js diagrams, with the caveat that we can't get proper colouring.

Mermaid.js uses some pretty strong CSS rules, e.g. unique ID for every diagram. This in turn means that it's difficult to override generally (you have to do it case-by-case for each diagram), and even then, you can't completely make use of the highlight.js functionality to get highlighing in nodes because of the ID-based styling of Mermaid.js.

Buuut this should be sufficient to replace usage of dot diagrams

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

@yebai yebai Jul 29, 2024

Choose a reason for hiding this comment

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

@shravanngoswamii can you help replace all figures in the PR with DocumenterMermaid? Feel free to open a new PR against this PR.

Copy link
Member

Choose a reason for hiding this comment

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

@torfjelde It might be better to transfer these high-level docs into a Quarto docs page and then provide a link here.

Copy link
Member

Choose a reason for hiding this comment

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

@shravanngoswamii can you help replace all figures in the PR with DocumenterMermaid? Feel free to open a new PR against this PR.

Ok, Sure!

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

It might be better to transfer these high-level docs into a Quarto docs page and then provide a link here.

Possibly! But I think that's somewhat out of scope for this PR? This is following the existing approach in DPPL of documenting things here, so if we want to move these things, we should do so once and proper I think

# `assume` block
subgraph cluster_assume {
label = "assume";
fontname = "Courier";

assume [shape=box, label=< assume(varinfo, <FONT COLOR="#3B6EA8">@varname</FONT>(x), Normal())>, fontname="Courier"];
without_linking_assume [shape=box, label="f = from_internal_transform(varinfo, varname, dist)", fontname="Courier"];
with_logabsdetjac [shape=box, label="x, logjac = with_logabsdet_jacobian(f, assume_internal(varinfo, varname, dist))", fontname="Courier"];
return_assume [shape=box, label=< <FONT COLOR="#3B6EA8">return</FONT> x, logpdf(dist, x) - logjac, varinfo >, style=dashed, fontname="Courier"];

assume -> without_linking_assume;
without_linking_assume -> with_logabsdetjac;
with_logabsdetjac -> return_assume;
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions docs/src/assets/images/transformations-assume.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
digraph {
# `assume` block
subgraph cluster_assume {
label = "assume";
fontname = "Courier";

assume [shape=box, label=< assume(varinfo, <FONT COLOR="#3B6EA8">@varname</FONT>(x), Normal())>, fontname="Courier"];
iflinked_assume [label=< <FONT COLOR="#3B6EA8">if</FONT> istrans(varinfo, varname) >, fontname="Courier"];
without_linking_assume [shape=box, label="f = from_internal_transform(varinfo, varname, dist)", fontname="Courier"];
with_linking_assume [shape=box, label="f = from_linked_internal_transform(varinfo, varname, dist)", fontname="Courier"];
with_logabsdetjac [shape=box, label="x, logjac = with_logabsdet_jacobian(f, assume_internal(varinfo, varname, dist))", fontname="Courier"];
return_assume [shape=box, label=< <FONT COLOR="#3B6EA8">return</FONT> x, logpdf(dist, x) - logjac, varinfo >, style=dashed, fontname="Courier"];

assume -> iflinked_assume;
iflinked_assume -> without_linking_assume [label=< <FONT COLOR="#97365B">false</FONT>>, fontname="Courier"];
iflinked_assume -> with_linking_assume [label=< <FONT COLOR="#97365B">true</FONT>>, fontname="Courier"];
without_linking_assume -> with_logabsdetjac;
with_linking_assume -> with_logabsdetjac;
with_logabsdetjac -> return_assume;
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/src/assets/images/transformations-getindex-with-dist.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
digraph {
# `getindex` block
subgraph cluster_getindex {
label = "getindex";
fontname = "Courier";

getindex [shape=box, label=< x = getindex(varinfo, <FONT COLOR="#3B6EA8">@varname</FONT>(x), Normal()) >, fontname="Courier"];
iflinked_getindex [label=< <FONT COLOR="#3B6EA8">if</FONT> istrans(varinfo, varname) >, fontname="Courier"];
without_linking_getindex [shape=box, label="f = from_internal_transform(varinfo, varname, dist)", fontname="Courier"];
with_linking_getindex [shape=box, label="f = from_linked_internal_transform(varinfo, varname, dist)", fontname="Courier"];
return_getindex [shape=box, label=< <FONT COLOR="#3B6EA8">return</FONT> f(getindex_internal(varinfo, varname)) >, style=dashed, fontname="Courier"];

getindex -> iflinked_getindex;
iflinked_getindex -> without_linking_getindex [label=< <FONT COLOR="#97365B">false</FONT>>, fontname="Courier"];
iflinked_getindex -> with_linking_getindex [label=< <FONT COLOR="#97365B">true</FONT>>, fontname="Courier"];
without_linking_getindex -> return_getindex;
with_linking_getindex -> return_getindex;
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/src/assets/images/transformations-getindex-without-dist.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
digraph {
# `getindex` block
subgraph cluster_getindex {
label = "getindex";
fontname = "Courier";

getindex [shape=box, label=< x = getindex(varinfo, <FONT COLOR="#3B6EA8">@varname</FONT>(x)) >, fontname="Courier"];
iflinked_getindex [label=< <FONT COLOR="#3B6EA8">if</FONT> istrans(varinfo, varname) >, fontname="Courier"];
without_linking_getindex [shape=box, label="f = from_internal_transform(varinfo, varname)", fontname="Courier"];
with_linking_getindex [shape=box, label="f = from_linked_internal_transform(varinfo, varname)", fontname="Courier"];
return_getindex [shape=box, label=< <FONT COLOR="#3B6EA8">return</FONT> f(getindex_internal(varinfo, varname)) >, style=dashed, fontname="Courier"];

getindex -> iflinked_getindex;
iflinked_getindex -> without_linking_getindex [label=< <FONT COLOR="#97365B">false</FONT>>, fontname="Courier"];
iflinked_getindex -> with_linking_getindex [label=< <FONT COLOR="#97365B">true</FONT>>, fontname="Courier"];
without_linking_getindex -> return_getindex;
with_linking_getindex -> return_getindex;
}
}

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions docs/src/assets/images/transformations.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
digraph {
# Nodes.
tilde_node [shape=box, label="x ~ Normal()", fontname="Courier"];
base_node [shape=box, label=< vn = <FONT COLOR="#3B6EA8">@varname</FONT>(x)<BR/>dist = Normal()<BR/>x, vi = ... >, fontname="Courier"];
assume [shape=box, label="assume(vn, dist, vi)", fontname="Courier"];

iflinked [label=< <FONT COLOR="#3B6EA8">if</FONT> istrans(vi, vn) >, fontname="Courier"];

without_linking [shape=box, label="f = from_internal_transform(vi, vn, dist)", styled=dashed, fontname="Courier"];
with_linking [shape=box, label="f = from_linked_internal_transform(vi, vn, dist)", styled=dashed, fontname="Courier"];

with_logabsdetjac [shape=box, label="x, logjac = with_logabsdet_jacobian(f, getindex_internal(vi, vn, dist))", styled=dashed, fontname="Courier"];
return [shape=box, label=< <FONT COLOR="#3B6EA8">return</FONT> x, logpdf(dist, x) - logjac, vi >, styled=dashed, fontname="Courier"];

# Edges.
tilde_node -> base_node [style=dashed, label=< <FONT COLOR="#3B6EA8">@model</FONT>>, fontname="Courier"]
base_node -> assume [style=dashed, label=" tilde-pipeline", fontname="Courier"];

assume -> iflinked;

iflinked -> without_linking [label=< <FONT COLOR="#97365B">false</FONT>>, fontname="Courier"];
iflinked -> with_linking [label=< <FONT COLOR="#97365B">true</FONT>>, fontname="Courier"];

without_linking -> with_logabsdetjac;
with_linking -> with_logabsdetjac;

with_logabsdetjac -> return;
}
Binary file added docs/src/assets/images/transformations.dot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading