Skip to content

Commit 0335eb9

Browse files
committed
Rename test files and organize testsets
1 parent eed316b commit 0335eb9

File tree

7 files changed

+68
-83
lines changed

7 files changed

+68
-83
lines changed

test/cuda.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ using TensorInference, CUDA
44
CUDA.allowscalar(false)
55

66
@testset "gradient-based tensor network solvers" begin
7-
################# Load problem ####################
87
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
98
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
109

@@ -22,7 +21,6 @@ CUDA.allowscalar(false)
2221
end
2322

2423
@testset "map" begin
25-
################# Load problem ####################
2624
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
2725
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
2826

@@ -38,7 +36,6 @@ end
3836
end
3937

4038
@testset "mmap" begin
41-
################# Load problem ####################
4239
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
4340
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
4441

File renamed without changes.

test/mmap.jl

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ using TensorInference
77
@test TensorInference.connected_clusters(ixs, [2, 3, 6]) == [[2, 3] => [1, 2], [6] => [3]]
88
end
99

10-
@testset "mmap" begin
11-
################# Load problem ####################
10+
@testset "gradient-based tensor network solvers" begin
1211
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
1312
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
1413

@@ -30,3 +29,57 @@ end
3029
logp, config = most_probable_config(mmap3)
3130
@test log_probability(mmap3, config) logp
3231
end
32+
33+
@testset "sampling" begin
34+
instance = TensorInference.read_instance_from_string("""MARKOV
35+
8
36+
2 2 2 2 2 2 2 2
37+
8
38+
1 0
39+
2 1 0
40+
1 2
41+
2 3 2
42+
2 4 2
43+
3 5 3 1
44+
2 6 5
45+
3 7 5 4
46+
47+
2
48+
0.01
49+
0.99
50+
51+
4
52+
0.05 0.01
53+
0.95 0.99
54+
55+
2
56+
0.5
57+
0.5
58+
59+
4
60+
0.1 0.01
61+
0.9 0.99
62+
63+
4
64+
0.6 0.3
65+
0.4 0.7
66+
67+
8
68+
1 1 1 0
69+
0 0 0 1
70+
71+
4
72+
0.98 0.05
73+
0.02 0.95
74+
75+
8
76+
0.9 0.7 0.8 0.1
77+
0.1 0.3 0.2 0.9
78+
""")
79+
n = 10000
80+
tnet = TensorNetworkModel(instance)
81+
samples = sample(tnet, n)
82+
mars = getindex.(marginals(tnet), 2)
83+
mars_sample = [count(s->s[k]==(1), samples) for k=1:8] ./ n
84+
@test isapprox(mars, mars_sample, atol=0.05)
85+
end

test/maxprob.jl renamed to test/mpe.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ using Test
22
using OMEinsum
33
using TensorInference
44

5-
@testset "map" begin
6-
################# Load problem ####################
5+
@testset "gradient-based tensor network solvers" begin
76
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
87
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
98

test/runtests.jl

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
using Test, TensorInference, Documenter, Pkg
1+
using Test, TensorInference, Documenter, Pkg, Artifacts
22

3-
include("utils.jl")
3+
import Pkg;
4+
Pkg.ensure_artifact_installed("uai2014", "Artifacts.toml");
45

5-
artifacts_toml = "Artifacts.toml"
6-
artifacts = Pkg.Artifacts.select_downloadable_artifacts(artifacts_toml)
7-
for name in keys(artifacts)
8-
Pkg.Artifacts.ensure_artifact_installed(name, artifacts[name], artifacts_toml)
9-
end
6+
include("utils.jl")
107

11-
@testset "inference" begin
12-
include("inference.jl")
8+
@testset "MAR" begin
9+
include("mar.jl")
1310
end
1411

15-
@testset "MAP" begin
16-
include("maxprob.jl")
12+
@testset "MPE" begin
13+
include("mpe.jl")
1714
end
1815

1916
@testset "MMAP" begin
2017
include("mmap.jl")
2118
end
2219

23-
@testset "MMAP" begin
24-
include("sampling.jl")
25-
end
26-
2720
using CUDA
2821
if CUDA.functional()
2922
include("cuda.jl")

test/sampling.jl

Lines changed: 0 additions & 55 deletions
This file was deleted.

test/utils.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Artifacts
2-
31
"""
42
Helper function to obtain the filepaths for an instance's model, evidence, and
53
solution files within the uai2014 artifact, corresponding to the provided
@@ -10,8 +8,8 @@ task.
108
- `task::String`: The task type. Supported tasks are "MAR", "MPE", "MMAP", and "PR".
119
"""
1210
function get_instance_filepaths(problem_name::AbstractString, task::AbstractString)
13-
model_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai")
14-
evidence_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai.evid")
15-
solution_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai." * task)
16-
return model_filepath, evidence_filepath, solution_filepath
11+
model_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai")
12+
evidence_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai.evid")
13+
solution_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai." * task)
14+
return model_filepath, evidence_filepath, solution_filepath
1715
end

0 commit comments

Comments
 (0)