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

Check if log density supports LogDensityProblems #111

Merged
merged 5 commits into from
Dec 29, 2022
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/IntegrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
fail-fast: false
matrix:
package:
- {user: TuringLang, repo: AdvancedHMC.jl}
- {user: TuringLang, repo: AdvancedMH.jl}
- {user: TuringLang, repo: EllipticalSliceSampling.jl}
- {user: TuringLang, repo: MCMCChains.jl}
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
keywords = ["markov chain monte carlo", "probablistic programming"]
license = "MIT"
desc = "A lightweight interface for common MCMC methods."
version = "4.2"
version = "4.2.1"

[deps]
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
ConsoleProgressMonitor = "88cd18e8-d9cc-4ea6-8889-5259c0d15c8b"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
Expand All @@ -20,6 +21,7 @@ Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"
[compat]
BangBang = "0.3.19"
ConsoleProgressMonitor = "0.1"
LogDensityProblems = "2"
LoggingExtras = "0.4, 0.5"
ProgressLogging = "0.1"
StatsBase = "0.32, 0.33"
Expand Down
1 change: 1 addition & 0 deletions src/AbstractMCMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module AbstractMCMC

using BangBang: BangBang
using ConsoleProgressMonitor: ConsoleProgressMonitor
using LogDensityProblems: LogDensityProblems
using LoggingExtras: LoggingExtras
using ProgressLogging: ProgressLogging
using StatsBase: StatsBase
Expand Down
12 changes: 12 additions & 0 deletions src/logdensityproblems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ that the wrapped object implements the LogDensityProblems.jl interface.
"""
struct LogDensityModel{L} <: AbstractModel
logdensity::L
function LogDensityModel{L}(logdensity::L) where {L}
if LogDensityProblems.capabilities(logdensity) === nothing
throw(
ArgumentError(
"The log density function does not support the LogDensityProblems.jl interface",
),
)
end
return new{L}(logdensity)
end
end

LogDensityModel(logdensity::L) where {L} = LogDensityModel{L}(logdensity)