Skip to content

Commit 284189f

Browse files
authored
Make HMMBase optional in the test suite (#111)
* Put HMMBase in extension of HMMTest * Split test suite * Using * Fix * Fixes * Increase test case sizes * Fixes * Fix * Split better * More fixes * Rm show * Fix * Subtle change * Fixes
1 parent 0e92d51 commit 284189f

File tree

17 files changed

+141
-88
lines changed

17 files changed

+141
-88
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push:
44
branches:
55
- main
6-
tags: ['*']
6+
tags: ["*"]
77
pull_request:
88
concurrency:
99
# Skip intermediate builds: always.
@@ -12,16 +12,19 @@ concurrency:
1212
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
1313
jobs:
1414
test:
15-
name: Julia ${{ matrix.version }} - ${{ github.event_name }}
15+
name: Julia ${{ matrix.version }} - ${{ matrix.test_suite }}
1616
runs-on: ubuntu-latest
1717
strategy:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.9'
22-
- '1'
23-
os:
24-
- ubuntu-latest
21+
- "1.9"
22+
- "1"
23+
test_suite:
24+
- "Standard"
25+
- "HMMBase"
26+
env:
27+
JULIA_HMM_TEST_SUITE: ${{ matrix.test_suite }}
2528
steps:
2629
- uses: actions/checkout@v4
2730
- uses: julia-actions/setup-julia@v2
@@ -36,4 +39,4 @@ jobs:
3639
with:
3740
files: lcov.info
3841
token: ${{ secrets.CODECOV_TOKEN }}
39-
fail_ci_if_error: true
42+
fail_ci_if_error: true

examples/autodiff.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using Enzyme: Enzyme
1111
using ForwardDiff: ForwardDiff
1212
using HiddenMarkovModels
1313
import HiddenMarkovModels as HMMs
14+
using HMMTest #src
1415
using LinearAlgebra
1516
using Random: Random, AbstractRNG
1617
using StableRNGs

examples/basics.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ This is important to keep in mind when testing new models.
189189
In many applications, we have access to various observation sequences of different lengths.
190190
=#
191191

192-
nb_seqs = 300
192+
nb_seqs = 1000
193193
long_obs_seqs = [last(rand(rng, hmm, rand(rng, 100:200))) for k in 1:nb_seqs];
194194
typeof(long_obs_seqs)
195195

@@ -258,6 +258,5 @@ hcat(initialization(hmm_est_concat), initialization(hmm))
258258
# ## Tests #src
259259

260260
control_seq = fill(nothing, last(seq_ends)); #src
261-
test_identical_hmmbase(rng, hmm, 100; hmm_guess) #src
262261
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess) #src
263262
test_type_stability(rng, hmm, control_seq; seq_ends, hmm_guess) #src

examples/controlled.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Simulation requires a vector of controls, each being a vector itself with the ri
6666
Let us build several sequences of variable lengths.
6767
=#
6868

69-
control_seqs = [[randn(rng, d) for t in 1:rand(100:200)] for k in 1:100];
69+
control_seqs = [[randn(rng, d) for t in 1:rand(100:200)] for k in 1:1000];
7070
obs_seqs = [rand(rng, hmm, control_seq).obs_seq for control_seq in control_seqs];
7171

7272
obs_seq = reduce(vcat, obs_seqs)
@@ -151,5 +151,5 @@ hcat(hmm_est.dist_coeffs[2], hmm.dist_coeffs[2])
151151

152152
@test hmm_est.dist_coeffs[1] hmm.dist_coeffs[1] atol = 0.05 #src
153153
@test hmm_est.dist_coeffs[2] hmm.dist_coeffs[2] atol = 0.05 #src
154-
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess, atol=0.08, init=false) #src
154+
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess, init=false) #src
155155
test_type_stability(rng, hmm, control_seq; seq_ends, hmm_guess) #src

examples/temporal.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ map(mean, hcat(obs_distributions(hmm_est, 2), obs_distributions(hmm, 2)))
183183

184184
# ## Tests #src
185185

186-
@test mean(obs_seq[1:2:end]) < 0 < mean(obs_seq[2:2:end]) #src
187-
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess, atol=0.09, init=false) #src
186+
@test mean(obs_seqs[1][1:2:end]) < 0 < mean(obs_seqs[1][2:2:end]) #src
187+
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess, init=false) #src
188188
test_type_stability(rng, hmm, control_seq; seq_ends, hmm_guess) #src

examples/types.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,9 @@ Another useful array type is [StaticArrays.jl](https://github.com/JuliaArrays/St
156156

157157
@test nnz(log_transition_matrix(hmm)) == nnz(transition_matrix(hmm)) #src
158158

159-
seq_ends = cumsum(rand(rng, 100:200, 100)); #src
159+
seq_ends = cumsum(rand(rng, 100:200, 1000)); #src
160160
control_seq = fill(nothing, last(seq_ends)); #src
161-
test_identical_hmmbase(rng, hmm, 100; hmm_guess) #src
162-
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess, init=false, atol=0.08) #src
161+
test_coherent_algorithms(rng, hmm, control_seq; seq_ends, hmm_guess, init=false) #src
163162
test_type_stability(rng, hmm, control_seq; seq_ends, hmm_guess) #src
164163
# https://github.com/JuliaSparse/SparseArrays.jl/issues/469 #src
165164
@test_skip test_allocations(rng, hmm, control_seq; seq_ends, hmm_guess) #src

libs/HMMTest/Project.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ version = "0.1.0"
55

66
[deps]
77
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
8-
HMMBase = "b2b3ca75-8444-5ffa-85e6-af70e2b64fe7"
98
HiddenMarkovModels = "84ca31d5-effc-45e0-bfda-5a68cd981f47"
109
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
1110
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1211
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1312
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
13+
14+
[weakdeps]
15+
HMMBase = "b2b3ca75-8444-5ffa-85e6-af70e2b64fe7"
16+
17+
[extensions]
18+
HMMTestHMMBaseExt = "HMMBase"
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
module HMMTestHMMBaseExt
12

2-
function test_identical_hmmbase(
3+
using HiddenMarkovModels
4+
import HiddenMarkovModels as HMMs
5+
using HMMBase: HMMBase
6+
using HMMTest
7+
using Random: AbstractRNG
8+
using Statistics: mean
9+
using Test: @test, @testset, @test_broken
10+
11+
function HMMTest.test_identical_hmmbase(
312
rng::AbstractRNG,
413
hmm::AbstractHMM,
514
T::Integer;
@@ -54,3 +63,5 @@ function test_identical_hmmbase(
5463
end
5564
end
5665
end
66+
67+
end

libs/HMMTest/src/HMMTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ using BenchmarkTools: @ballocated
44
using HiddenMarkovModels
55
using HiddenMarkovModels: AbstractVectorOrNTuple
66
import HiddenMarkovModels as HMMs
7-
using HMMBase: HMMBase
87
using JET: @test_opt, @test_call
98
using Random: AbstractRNG
109
using Statistics: mean
1110
using Test: @test, @testset, @test_broken
1211

12+
function test_identical_hmmbase end # in extension
13+
1314
export transpose_hmm
1415
export test_equal_hmms, test_coherent_algorithms
1516
export test_identical_hmmbase
@@ -19,7 +20,6 @@ export test_type_stability
1920
include("utils.jl")
2021
include("coherence.jl")
2122
include("allocations.jl")
22-
include("hmmbase.jl")
2323
include("jet.jl")
2424

2525
end

src/HiddenMarkovModels.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using ChainRulesCore: ChainRulesCore, NoTangent, RuleConfig, rrule_via_ad
1616
using DensityInterface: DensityInterface, DensityKind, HasDensity, NoDensity, logdensityof
1717
using DocStringExtensions
1818
using FillArrays: Fill
19-
using LinearAlgebra: Transpose, dot, ldiv!, lmul!, mul!, parent
19+
using LinearAlgebra: Transpose, axpy!, dot, ldiv!, lmul!, mul!, parent
2020
using Random: Random, AbstractRNG, default_rng
2121
using SparseArrays: AbstractSparseArray, SparseMatrixCSC, nonzeros, nnz, nzrange, rowvals
2222
using StatsAPI: StatsAPI, fit, fit!

0 commit comments

Comments
 (0)