diff --git a/.github/workflows/DocsNav.yml b/.github/workflows/DocsNav.yml new file mode 100644 index 00000000..14614d1f --- /dev/null +++ b/.github/workflows/DocsNav.yml @@ -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 diff --git a/Project.toml b/Project.toml index a0ba0825..60215cec 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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" diff --git a/src/AbstractMCMC.jl b/src/AbstractMCMC.jl index dc464d42..d7374dd2 100644 --- a/src/AbstractMCMC.jl +++ b/src/AbstractMCMC.jl @@ -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 diff --git a/src/sample.jl b/src/sample.jl index 8e99ae7e..e59f0e32 100644 --- a/src/sample.jl +++ b/src/sample.jl @@ -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 diff --git a/test/logdensityproblems.jl b/test/logdensityproblems.jl index 181d2645..4a3a22d5 100644 --- a/test/logdensityproblems.jl +++ b/test/logdensityproblems.jl @@ -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