Skip to content

Commit

Permalink
Merge branch 'master' into torfjelde/step-warmup
Browse files Browse the repository at this point in the history
  • Loading branch information
torfjelde committed Oct 4, 2024
2 parents 6e8f88e + 8431b31 commit 44c55bb
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 7 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/DocsNav.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Add Navbar

on:
page_build: # Triggers the workflow on push events to gh-pages branch
workflow_dispatch: # Allows manual triggering
schedule:
- cron: '0 0 * * 0' # Runs every week on Sunday at midnight (UTC)

jobs:
add-navbar:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
fetch-depth: 0

- name: Download insert_navbar.sh
run: |
curl -O https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/insert_navbar.sh
chmod +x insert_navbar.sh
- name: Update Navbar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
# Define the URL of the navbar to be used
NAVBAR_URL="https://raw.githubusercontent.com/TuringLang/turinglang.github.io/main/assets/scripts/TuringNavbar.html"
# Update all HTML files in the current directory (gh-pages root)
./insert_navbar.sh . $NAVBAR_URL
# Remove the insert_navbar.sh file
rm insert_navbar.sh
# Check if there are any changes
if [[ -n $(git status -s) ]]; then
git add .
git commit -m "Added navbar and removed insert_navbar.sh"
git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" gh-pages
else
echo "No changes to commit"
fi
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name = "AbstractMCMC"
uuid = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
keywords = ["markov chain monte carlo", "probablistic programming"]
keywords = ["markov chain monte carlo", "probabilistic programming"]
license = "MIT"
desc = "A lightweight interface for common MCMC methods."
version = "5.0.0"
version = "5.3.0"

[deps]
BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
Expand All @@ -20,7 +20,7 @@ TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"

[compat]
BangBang = "0.3.19"
BangBang = "0.3.19, 0.4"
ConsoleProgressMonitor = "0.1"
FillArrays = "1"
LogDensityProblems = "2"
Expand Down
14 changes: 14 additions & 0 deletions src/AbstractMCMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,18 @@ include("stepper.jl")
include("transducer.jl")
include("logdensityproblems.jl")

if isdefined(Base.Experimental, :register_error_hint)
function __init__()
Base.Experimental.register_error_hint(MethodError) do io, exc, argtypes, _
if Base.parentmodule(exc.f) == LogDensityProblems &&
any(a -> a <: LogDensityModel, argtypes)
print(
io,
"\n`AbstractMCMC.LogDensityModel` is a wrapper and does not itself implement the LogDensityProblems.jl interface. To use LogDensityProblems.jl methods, access the inner type with (e.g.) `logdensity(model.logdensity, params)` instead of `logdensity(model, params)`.",
)
end
end
end
end

end # module AbstractMCMC
11 changes: 7 additions & 4 deletions src/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
const PROGRESS = Ref(true)

"""
setprogress!(progress::Bool)
setprogress!(progress::Bool; silent::Bool=false)
Enable progress logging globally if `progress` is `true`, and disable it otherwise.
Enable progress logging globally if `progress` is `true`, and disable it otherwise.
Optionally disable informational message if `silent` is `true`.
"""
function setprogress!(progress::Bool)
@info "progress logging is $(progress ? "enabled" : "disabled") globally"
function setprogress!(progress::Bool; silent::Bool=false)
if !silent
@info "progress logging is $(progress ? "enabled" : "disabled") globally"
end
PROGRESS[] = progress
return progress
end
Expand Down
9 changes: 9 additions & 0 deletions test/logdensityproblems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
@test model.logdensity ===

@test_throws ArgumentError AbstractMCMC.LogDensityModel(mylogdensity)

try
LogDensityProblems.logdensity(model, ones(10))
catch exc
@test exc isa MethodError
if isdefined(Base.Experimental, :register_error_hint)
@test occursin("is a wrapper", sprint(showerror, exc))
end
end
end

@testset "fallback for log densities" begin
Expand Down

0 comments on commit 44c55bb

Please sign in to comment.