Skip to content

Commit

Permalink
Merge pull request #98 from ArnoStrouwen/aqua
Browse files Browse the repository at this point in the history
Aqua CI
  • Loading branch information
ChrisRackauckas authored Dec 12, 2023
2 parents 0dc52c2 + 513ae5f commit fc12442
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
group:
- Core
version:
- '1'
- '1.6'
- '1'
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
julia-version: [1,1.6]
julia-version: [1]
os: [ubuntu-latest]
package:
- {user: SciML, repo: Surrogates.jl, group: All}
Expand Down
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Sobol = "ed01d8cd-4d21-5b2a-85b4-cc3bdc58bad4"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[weakdeps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand All @@ -25,11 +24,13 @@ Accessors = "0.1"
ConcreteStructs = "0.2"
Distributions = "0.21, 0.22, 0.23, 0.24, 0.25"
LatticeRules = "0.0.1"
LinearAlgebra = "1"
Primes = "0.5"
Random = "1"
Requires = "1"
Sobol = "1.3"
StatsBase = "0.33, 0.34"
julia = "1.6"
Test = "1"
julia = "1.9"

[extras]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
1 change: 0 additions & 1 deletion src/QuasiMonteCarlo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export SamplingAlgorithm,
VanDerCorputSample,
GoldenSample,
KroneckerSample,
SectionSample,
FaureSample,
randomize,
RandomizationMethod,
Expand Down
34 changes: 17 additions & 17 deletions src/RandomizedQuasiMonteCarlo/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ Create an iterator for doing multiple i.i.d. randomization over QMC sequences wh
- `T` is the `eltype` of the point sets. For some QMC methods (Faure, Sobol) this can be `Rational`
It is now compatible with all scrambling methods and shifting. One can also use it with `Distributions.Sampleable` or `RandomSample`.
"""
function DesignMatrix(N, d, S::DeterministicSamplingAlgorithm, num_mats, T = Float64)
function DesignMatrix(N, d, S::DeterministicSamplingAlgorithm, num_mats::Integer, T::DataType = Float64)
return DesignMatrix(N, d, S, S.R, num_mats, T)
end

function DesignMatrix(N,
d,
S::DeterministicSamplingAlgorithm,
R::OwenScramble,
num_mats,
T = Float64)
num_mats::Integer,
T::DataType = Float64)
X, random_bits, bits, indices = initialize(N, d, S, R, T)
return OwenDesignMat(X, random_bits, bits, indices, R, num_mats)
end
Expand All @@ -102,7 +102,7 @@ function DesignMatrix(N,
d,
S::DeterministicSamplingAlgorithm,
R::ScrambleMethod,
num_mats,
num_mats::Integer,
T = Float64)
X, random_bits, bits = initialize(N, d, S, R, T)
return ScrambleDesignMat(X, random_bits, bits, R, num_mats)
Expand All @@ -113,12 +113,12 @@ function DesignMatrix(N,
S::DeterministicSamplingAlgorithm,
R::Shift,
num_mats,
T = Float64)
T::DataType = Float64)
X = initialize(N, d, S, R, T)
return ShiftDesignMat(X, R, num_mats)
end

function DesignMatrix(N, d, D::RandomSample, num_mats, T = Float64)
function DesignMatrix(N, d, D::RandomSample, num_mats, T::DataType = Float64)
X = initialize(N, d, D, T)
return RandomDesignMat(X, num_mats)
end
Expand All @@ -130,7 +130,7 @@ next!(DM::DistributionDesignMat) = rand!(DM.D, DM.X)
next!(DM::RandomDesignMat) = rand!(DM.X)

## OwenScramble
function initialize(n, d, sampler, R::OwenScramble, T = Float64)
function initialize(n, d, sampler, R::OwenScramble, T::DataType = Float64)
# Generate unrandomized sequence
no_rand_sampler = @set sampler.R = NoRand()
points = permutedims(sample(n, d, no_rand_sampler, T))
Expand All @@ -157,7 +157,7 @@ end

## Other scramble

function initialize(n, d, sampler, R::ScrambleMethod, T = Float64)
function initialize(n, d, sampler, R::ScrambleMethod, T::DataType = Float64)
# Generate unrandomized sequence
no_rand_sampler = @set sampler.R = NoRand()
points = permutedims(sample(n, d, no_rand_sampler, T))
Expand All @@ -181,15 +181,15 @@ function scramble!(random_points::AbstractArray{T},
end

## Shift
function initialize(n, d, sampler, R::Shift, T = Float64)
function initialize(n, d, sampler, R::Shift, T::DataType = Float64)
# Generate unrandomized sequence
no_rand_sampler = @set sampler.R = NoRand()
points = sample(n, d, no_rand_sampler, T)
return points
end

## Distribution
function initialize(n, d, D::RandomSample, T = Float64)
function initialize(n, d, D::RandomSample, T::DataType = Float64)
# Generate unrandomized sequence
X = zeros(T, d, n)
return X
Expand All @@ -215,13 +215,13 @@ Create `num_mats` matrices each containing a QMC point set, where:
- `T` is the `eltype` of the point sets. For some QMC methods (Faure, Sobol) this can be `Rational`
If the bound `lb` and `ub` are specified instead of `d`, the samples will be transformed into the box `[lb, ub]`.
"""
function generate_design_matrices(n, d, sampler::DeterministicSamplingAlgorithm, num_mats,
T = Float64)
function generate_design_matrices(n, d, sampler::DeterministicSamplingAlgorithm, num_mats::Integer,
T::DataType = Float64)
return generate_design_matrices(n, d, sampler, sampler.R, num_mats, T)
end

function generate_design_matrices(n, d, sampler::RandomSamplingAlgorithm, num_mats,
T = Float64)
function generate_design_matrices(n, d, sampler::RandomSamplingAlgorithm, num_mats::Integer,
T::DataType = Float64)
return [sample(n, d, sampler, T) for j in 1:num_mats]
end

Expand Down Expand Up @@ -250,7 +250,7 @@ end
Note that this is an ad hoc way to produce i.i.d sequence as it creates a deterministic point in dimension `d × num_mats` and split it in `num_mats` point set of dimension `d`.
This does not have any QMC garantuees.
"""
function generate_design_matrices(n, d, sampler, R::NoRand, num_mats, T = Float64)
function generate_design_matrices(n, d, sampler, R::NoRand, num_mats::Integer, T::DataType = Float64)
out = sample(n, num_mats * d, sampler, T)
@warn "The `generate_design_matrices(n, d, sampler, R = NoRand(), num_mats)` method does not produces true and independent QMC matrices, see [this doc warning](https://docs.sciml.ai/QuasiMonteCarlo/stable/design_matrix/) for more context.
Prefer using randomization methods such as `R = Shift()`, `R = MatousekScrambling()`, etc., see [documentation](https://docs.sciml.ai/QuasiMonteCarlo/stable/randomization/)"
Expand All @@ -261,7 +261,7 @@ function generate_design_matrices(n,
d,
sampler,
R::RandomizationMethod,
num_mats,
T = Float64)
num_mats::Integer,
T::DataType = Float64)
return collect(DesignMatrix(n, d, sampler, R, num_mats, T))
end
8 changes: 4 additions & 4 deletions src/net_utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ function unif2bits(y::Real, b::I; pad = 32) where {I <: Integer}
end

# Inspired by digits!(a::AbstractVector{T}, n::Integer; base) where T<:Integer in Base at intfuncs.jl:926
function unif2bits!(bits::AbstractVector{<:Integer}, y, b::Integer; kwargs...)
function unif2bits!(bits::AbstractVector{<:Integer}, y::Real, b::Integer; kwargs...)
invbase = inv(b)
for i in eachindex(bits)
r, y = divrem(y, invbase^i)
bits[i] = r
end
end

#? Apparently this is not ideal to explicitly state the Type.
#? Apparently this is not ideal to explicitly state the Type.
#? See https://github.com/SciML/QuasiMonteCarlo.jl/issues/44#issuecomment-1328156825
#? Not sure how to do otherwise in this case though.
#? Not sure how to do otherwise in this case though.
"""
bits2unif(::Type{T}, bits::AbstractVector{<:Integer},
b::Integer)
Expand Down Expand Up @@ -76,7 +76,7 @@ end
#? @btime @evalpoly(3, $bi...)
#? 500.515 ns (1 allocation: 272 bytes)
#? @btime QuasiMonteCarlo.bits2int($bi, 3)
#? 13.113 ns (0 allocations: 0 bytes)
#? 13.113 ns (0 allocations: 0 bytes)
"""
bits2int(bit::AbstractMatrix{<:Integer}, b::Integer)
Expand Down
11 changes: 11 additions & 0 deletions test/qa.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using QuasiMonteCarlo, Aqua
@testset "Aqua" begin
Aqua.find_persistent_tasks_deps(QuasiMonteCarlo)
Aqua.test_ambiguities(QuasiMonteCarlo, recursive = false)
Aqua.test_deps_compat(QuasiMonteCarlo)
Aqua.test_piracies(QuasiMonteCarlo)
Aqua.test_project_extras(QuasiMonteCarlo)
Aqua.test_stale_deps(QuasiMonteCarlo)
Aqua.test_unbound_args(QuasiMonteCarlo)
Aqua.test_undefined_exports(QuasiMonteCarlo)
end
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using QuasiMonteCarlo
using Aqua, Test
# Aqua.test_all(QuasiMonteCarlo)
using Test
include("qa.jl")

using Compat
using Statistics, LinearAlgebra, StatsBase, Random
Expand Down Expand Up @@ -435,13 +435,13 @@ end
@test isa(X, Matrix{eltype(X)}) == true
μ = [mean(f(c) for c in eachcol(X)) for X in iterator] # Check that iterator do work!
if !isa(algorithm, Beta) # The Beta distribution is not Uniform hence we do not expect the μ to be close to 1. We could compute the expected results but it would involve a β function dependency.
@test μones(num_mat) atol=5e-2 # the results for different randomization should all be close to 1. Arbitrarily we allow 5% error.
@test μones(num_mat) atol=5e-2 # the results for different randomization should all be close to 1. Arbitrarily we allow 5% error.
end
end
end

@testset "Types of output and intermediate arrays" begin
# Scrambling methods use intermediate array for the bits scrambling. It is in general uncessary to have this large array stored as Int64.
# Scrambling methods use intermediate array for the bits scrambling. It is in general uncessary to have this large array stored as Int64.
#TODO test other randomization methods (here just scrambling) and QMC sequence (here just Sobol)
#TODO here we test output and constructions of intermediate array, we could test that all operation are type stables
d = 4
Expand Down

0 comments on commit fc12442

Please sign in to comment.