Skip to content
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 AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DynamicPPL builds on AbstractPPL.jl for shared PPL interfaces such as `VarName`,
- `VarName` (AbstractPPL): address for model variables, including nested fields/indices.
- `VarNamedTuple` (`src/varnamedtuple.jl`): named-tuple-like parameter storage keyed by `VarName`.
- `LogDensityFunction` (`src/logdensityfunction.jl`): bridge from named parameters to flat `AbstractVector{<:Real}` for samplers, optimisers, and AD via LogDensityProblems.jl.
- `ext/`: `DynamicPPLForwardDiffExt`, `DynamicPPLMooncakeExt`, `DynamicPPLReverseDiffExt`, `DynamicPPLEnzymeCoreExt`, `DynamicPPLComponentArraysExt`, `DynamicPPLMCMCChainsExt`, and `DynamicPPLMarginalLogDensitiesExt`.
- `ext/`: `DynamicPPLForwardDiffExt`, `DynamicPPLMooncakeExt`, `DynamicPPLReverseDiffExt`, `DynamicPPLEnzymeCoreExt`, `DynamicPPLComponentArraysExt`, and `DynamicPPLMCMCChainsExt`.
- `DynamicPPL.TestUtils`: analytical test models (`logprior_true`, `loglikelihood_true`, etc.), `run_ad`, `ADResult`.

## DynamicPPL Invariants
Expand Down
3 changes: 0 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
MarginalLogDensities = "f0c3360a-fb8d-11e9-1194-5521fd7ee392"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"

Expand All @@ -44,7 +43,6 @@ DynamicPPLComponentArraysExt = ["ComponentArrays"]
DynamicPPLEnzymeCoreExt = ["EnzymeCore"]
DynamicPPLForwardDiffExt = ["ForwardDiff"]
DynamicPPLMCMCChainsExt = ["MCMCChains"]
DynamicPPLMarginalLogDensitiesExt = ["MarginalLogDensities"]
DynamicPPLMooncakeExt = ["Mooncake", "DifferentiationInterface"]
DynamicPPLReverseDiffExt = ["ReverseDiff"]

Expand All @@ -71,7 +69,6 @@ LinearAlgebra = "1.6"
LogDensityProblems = "2"
MCMCChains = "6, 7"
MacroTools = "0.5.6"
MarginalLogDensities = "0.4.3"
Mooncake = "0.4.147, 0.5"
OrderedCollections = "1"
PartitionedDistributions = "0.0.1"
Expand Down
8 changes: 1 addition & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ using AbstractPPL
using Distributions
using DocumenterMermaid
using MCMCChains
using MarginalLogDensities
using AbstractMCMC: AbstractMCMC
using Random

Expand All @@ -20,7 +19,6 @@ DocMeta.setdocmeta!(
DynamicPPL, :DocTestSetup, :(using DynamicPPL, MCMCChains); recursive=true
)
# Need this to document a method which uses a type inside the extension
DPPLMLDExt = Base.get_extension(DynamicPPL, :DynamicPPLMarginalLogDensitiesExt)

links = InterLinks("AbstractPPL" => "https://turinglang.org/AbstractPPL.jl/stable/")

Expand All @@ -31,11 +29,7 @@ makedocs(;
format=Documenter.HTML(;
size_threshold=2^10 * 400, mathengine=Documenter.HTMLWriter.MathJax3()
),
modules=[
DynamicPPL,
Base.get_extension(DynamicPPL, :DynamicPPLMCMCChainsExt),
Base.get_extension(DynamicPPL, :DynamicPPLMarginalLogDensitiesExt),
],
modules=[DynamicPPL, Base.get_extension(DynamicPPL, :DynamicPPLMCMCChainsExt)],
pages=[
"Home" => "index.md",
"Contributor onboarding" => "onboarding.md",
Expand Down
12 changes: 0 additions & 12 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,6 @@ When using `predict` with `MCMCChains.Chains`, you can control which variables a
- `include_all=false` (default): Include only newly predicted variables
- `include_all=true`: Include both parameters from the original chain and predicted variables

## Marginalisation

DynamicPPL provides the `marginalize` function to marginalise out variables from a model.
This requires `MarginalLogDensities.jl` to be loaded in your environment.

```@docs
marginalize
```

A `MarginalLogDensity` object acts as a function which maps non-marginalised parameter values to a marginal log-probability.
To retrieve a VarInfo object from it, you can use [`InitFromVector`](@ref).

## Models within models

One can include models and call another model inside the model function with `left ~ to_submodel(model)`.
Expand Down
1 change: 0 additions & 1 deletion docs/src/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ InitFromParams(::ParamsWithStats, ::Union{Nothing,AbstractInitStrategy})
InitFromUniform
InitFromVector
InitFromVector(::AbstractVector{<:Real}, ::LogDensityFunction)
InitFromVector(::MarginalLogDensities.MarginalLogDensity{<:DPPLMLDExt.LogDensityFunctionWrapper}, ::Union{AbstractVector,Nothing})
```

However, sometimes you will need to implement your own initialisation strategy.
Expand Down
215 changes: 0 additions & 215 deletions ext/DynamicPPLMarginalLogDensitiesExt.jl

This file was deleted.

24 changes: 1 addition & 23 deletions src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ export AbstractVarInfo,
@addlogprob!,
check_model,
set_logprob_type!,
marginalize,
# Deprecated.
generated_quantities,
typed_identity
Expand Down Expand Up @@ -282,29 +281,8 @@ using .DebugUtils
include("test_utils.jl")

include("deprecated.jl")

# Extended in MarginalLogDensitiesExt
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One needs to keep the generic method as an API so MarginalLogDensities can overload it.

function marginalize end

# Extended in MarginalLogDensities.jl
function marginalize end
if isdefined(Base.Experimental, :register_error_hint)
function __init__()
# Same for MarginalLogDensities.jl
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, _
requires_mld =
exc.f === DynamicPPL.marginalize &&
length(argtypes) == 2 &&
argtypes[1] <: Model &&
argtypes[2] <: AbstractVector{<:Union{Symbol,<:VarName}}
if requires_mld
printstyled(
io,
"\n\n `$(exc.f)` requires MarginalLogDensities.jl to be loaded.\n Please run `using MarginalLogDensities` before calling `$(exc.f)`.\n";
color=:cyan,
bold=true,
)
end
end
end
end

# Standard tag: Improves stacktraces
# Ref: https://www.stochasticlifestyle.com/improved-forwarddiff-jl-stacktraces-with-package-tags/
Expand Down
2 changes: 0 additions & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ InvertedIndices = "41ab1584-1d38-5bbf-9106-f11c6c58b48f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
MarginalLogDensities = "f0c3360a-fb8d-11e9-1194-5521fd7ee392"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Expand Down Expand Up @@ -50,7 +49,6 @@ ForwardDiff = "0.10.12, 1"
InvertedIndices = "1"
LogDensityProblems = "2"
MCMCChains = "7.2.1"
MarginalLogDensities = "0.4"
Mooncake = "0.4, 0.5"
OffsetArrays = "1"
OrderedCollections = "1"
Expand Down
14 changes: 8 additions & 6 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,14 @@ end
x .~ [Normal(), Normal()]
return x
end
expected_error = ArgumentError("""
As of v0.35, DynamicPPL does not allow arrays of distributions in `.~`. \
Please use `product_distribution` instead, or write a loop if necessary. \
See https://github.com/TuringLang/DynamicPPL.jl/releases/tag/v0.35.0 for more \
details.\
""")
expected_error = ArgumentError(
"""
As of v0.35, DynamicPPL does not allow arrays of distributions in `.~`. \
Please use `product_distribution` instead, or write a loop if necessary. \
See https://github.com/TuringLang/DynamicPPL.jl/releases/tag/v0.35.0 for more \
details.\
"""
)
@test_throws expected_error (vector_dot_tilde()(); true)
end

Expand Down
Loading
Loading