Skip to content

Commit

Permalink
Use Blue style (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion authored Mar 5, 2022
1 parent acfadfa commit 4994a79
Show file tree
Hide file tree
Showing 18 changed files with 297 additions and 257 deletions.
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style="blue"
31 changes: 31 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Format

on:
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: 1
- name: Format code
run: |
using Pkg
Pkg.add(; name="JuliaFormatter", uuid="98e50ef6-434e-11e9-1051-2b60c6c9e899")
using JuliaFormatter
format("."; verbose=true)
shell: julia --color=yes {0}
- uses: reviewdog/action-suggester@v1
if: github.event_name == 'pull_request'
with:
tool_name: JuliaFormatter
fail_on_error: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Abstract types and interfaces for Markov chain Monte Carlo methods.
[![IntegrationTest](https://github.com/TuringLang/AbstractMCMC.jl/workflows/IntegrationTest/badge.svg?branch=master)](https://github.com/TuringLang/AbstractMCMC.jl/actions?query=workflow%3AIntegrationTest+branch%3Amaster)
[![Codecov](https://codecov.io/gh/TuringLang/AbstractMCMC.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/TuringLang/AbstractMCMC.jl)
[![Coveralls](https://coveralls.io/repos/github/TuringLang/AbstractMCMC.jl/badge.svg?branch=master)](https://coveralls.io/github/TuringLang/AbstractMCMC.jl?branch=master)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
17 changes: 3 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,15 @@ using AbstractMCMC
using Documenter
using Random

DocMeta.setdocmeta!(
AbstractMCMC,
:DocTestSetup,
:(using AbstractMCMC);
recursive=true,
)
DocMeta.setdocmeta!(AbstractMCMC, :DocTestSetup, :(using AbstractMCMC); recursive=true)

makedocs(;
sitename="AbstractMCMC",
format=Documenter.HTML(),
modules=[AbstractMCMC],
pages=[
"Home" => "index.md",
"api.md",
"design.md",
],
pages=["Home" => "index.md", "api.md", "design.md"],
strict=true,
checkdocs=:exports,
)

deploydocs(;
repo="github.com/TuringLang/AbstractMCMC.jl.git", push_preview=true
)
deploydocs(; repo="github.com/TuringLang/AbstractMCMC.jl.git", push_preview=true)
23 changes: 11 additions & 12 deletions src/AbstractMCMC.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module AbstractMCMC

import BangBang
import ConsoleProgressMonitor
import LoggingExtras
import ProgressLogging
import StatsBase
import TerminalLoggers
import Transducers

import Distributed
import Logging
import Random
using BangBang: BangBang
using ConsoleProgressMonitor: ConsoleProgressMonitor
using LoggingExtras: LoggingExtras
using ProgressLogging: ProgressLogging
using StatsBase: StatsBase
using TerminalLoggers: TerminalLoggers
using Transducers: Transducers

using Distributed: Distributed
using Logging: Logging
using Random: Random

# Reexport sample
using StatsBase: sample
Expand Down Expand Up @@ -71,7 +71,6 @@ processes.
"""
struct MCMCDistributed <: AbstractMCMCEnsemble end


"""
MCMCSerial
Expand Down
2 changes: 1 addition & 1 deletion src/deprecations.jl
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Deprecate the old name AbstractMCMCParallel in favor of AbstractMCMCEnsemble
Base.@deprecate_binding AbstractMCMCParallel AbstractMCMCEnsemble false
Base.@deprecate_binding AbstractMCMCParallel AbstractMCMCEnsemble false
51 changes: 9 additions & 42 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,14 @@ be specified with the `chain_type` argument.
By default, this method returns `samples`.
"""
function bundle_samples(
samples,
::AbstractModel,
::AbstractSampler,
::Any,
::Type;
kwargs...
samples, ::AbstractModel, ::AbstractSampler, ::Any, ::Type; kwargs...
)
return samples
end

function bundle_samples(
samples::Vector,
::AbstractModel,
::AbstractSampler,
::Any,
::Type{Vector{T}};
kwargs...
) where T
samples::Vector, ::AbstractModel, ::AbstractSampler, ::Any, ::Type{Vector{T}}; kwargs...
) where {T}
return map(samples) do sample
convert(T, sample)
end
Expand All @@ -74,24 +64,13 @@ sample is `sample`.
The method can be called with and without a predefined number `N` of samples.
"""
function samples(
sample,
::AbstractModel,
::AbstractSampler,
N::Integer;
kwargs...
)
function samples(sample, ::AbstractModel, ::AbstractSampler, N::Integer; kwargs...)
ts = Vector{typeof(sample)}(undef, 0)
sizehint!(ts, N)
return ts
end

function samples(
sample,
::AbstractModel,
::AbstractSampler;
kwargs...
)
function samples(sample, ::AbstractModel, ::AbstractSampler; kwargs...)
return Vector{typeof(sample)}(undef, 0)
end

Expand All @@ -113,35 +92,23 @@ function save!!(
::AbstractModel,
::AbstractSampler,
N::Integer;
kwargs...
kwargs...,
)
s = BangBang.push!!(samples, sample)
s !== samples && sizehint!(s, N)
return s
end

function save!!(
samples,
sample,
iteration::Integer,
::AbstractModel,
::AbstractSampler;
kwargs...
samples, sample, iteration::Integer, ::AbstractModel, ::AbstractSampler; kwargs...
)
return BangBang.push!!(samples, sample)
end

# Deprecations
Base.@deprecate transitions(
transition,
model::AbstractModel,
sampler::AbstractSampler,
N::Integer;
kwargs...
transition, model::AbstractModel, sampler::AbstractSampler, N::Integer; kwargs...
) samples(transition, model, sampler, N; kwargs...) false
Base.@deprecate transitions(
transition,
model::AbstractModel,
sampler::AbstractSampler;
kwargs...
transition, model::AbstractModel, sampler::AbstractSampler; kwargs...
) samples(transition, model, sampler; kwargs...) false
27 changes: 15 additions & 12 deletions src/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
# and add a custom progress logger if the current logger does not seem to be able to handle
# progress logs
macro ifwithprogresslogger(progress, exprs...)
return quote
if $progress
if $hasprogresslevel($Logging.current_logger())
$ProgressLogging.@withprogress $(exprs...)
else
$with_progresslogger($Base.@__MODULE__, $Logging.current_logger()) do
return esc(
quote
if $progress
if $hasprogresslevel($Logging.current_logger())
$ProgressLogging.@withprogress $(exprs...)
else
$with_progresslogger($Base.@__MODULE__, $Logging.current_logger()) do
$ProgressLogging.@withprogress $(exprs...)
end
end
else
$(exprs[end])
end
else
$(exprs[end])
end
end |> esc
end,
)
end

# improved checks?
Expand All @@ -31,13 +33,14 @@ function with_progresslogger(f, _module, logger)
log._module !== _module || log.level != ProgressLogging.ProgressLevel
end

Logging.with_logger(f, LoggingExtras.TeeLogger(logger1, logger2))
return Logging.with_logger(f, LoggingExtras.TeeLogger(logger1, logger2))
end

function progresslogger()
# detect if code is running under IJulia since TerminalLogger does not work with IJulia
# https://github.com/JuliaLang/IJulia.jl#detecting-that-code-is-running-under-ijulia
if (Sys.iswindows() && VERSION < v"1.5.3") || (isdefined(Main, :IJulia) && Main.IJulia.inited)
if (Sys.iswindows() && VERSION < v"1.5.3") ||
(isdefined(Main, :IJulia) && Main.IJulia.inited)
return ConsoleProgressMonitor.ProgressLogger()
else
return TerminalLoggers.TerminalLogger()
Expand Down
Loading

0 comments on commit 4994a79

Please sign in to comment.