Skip to content

Commit 6c0afda

Browse files
authored
Merge pull request #33 from TensorBFS/remove-artifact
Move Artifacts.toml from main project to test project
2 parents 070ce23 + 0335eb9 commit 6c0afda

File tree

17 files changed

+144
-210
lines changed

17 files changed

+144
-210
lines changed

Artifacts.toml

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

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ authors = ["Jin-Guo Liu", "Martin Roa Villescas"]
44
version = "0.1.0"
55

66
[deps]
7-
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
87
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
98
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
109
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -16,7 +15,6 @@ TropicalGEMM = "a4ad3063-64a7-4bad-8738-34ed09bc0236"
1615
TropicalNumbers = "b3a74e9c-7526-4576-a4eb-79c0d4c32334"
1716

1817
[compat]
19-
Artifacts = "1"
2018
CUDA = "4"
2119
DocStringExtensions = "0.8.6, 0.9"
2220
OMEinsum = "0.7"

benchmark/bench_map.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ using Artifacts
66

77
const SUITE = BenchmarkGroup()
88

9-
problem = read_uai_problem("Promedus_14")
9+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
10+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1011

1112
optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40)
1213
tn = TensorNetworkModel(problem; optimizer)

benchmark/bench_mar.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ using Artifacts
88

99
const SUITE = BenchmarkGroup()
1010

11-
problem = read_uai_problem("Promedus_14")
11+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
12+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1213

1314
optimizer = TreeSA(ntrials = 1, niters = 5, βs = 0.1:0.1:100)
1415
tn1 = TensorNetworkModel(problem; optimizer)

benchmark/bench_mmap.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ using Artifacts
66

77
const SUITE = BenchmarkGroup()
88

9-
problem = read_uai_problem("Promedus_14")
9+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
10+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1011
optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40)
1112

1213
# Does not marginalize any var

example/asia/asia.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using TensorInference
22

33
# Load the model that detailed in the README and `asia.uai`.
4-
instance = uai_problem_from_file(joinpath(@__DIR__, "asia.uai"))
4+
instance = read_instance(joinpath(@__DIR__, "asia.uai"))
55
tnet = TensorNetworkModel(instance)
66

77
# Get the probabilities (PR)
@@ -36,4 +36,4 @@ mmap = MMAPModel(instance; marginalized=[1,2,3,5,6,8])
3636
most_probable_config(mmap)
3737
# The total probability of having lung cancer is roughly half.
3838
log_probability(mmap, [1, 0])
39-
log_probability(mmap, [0, 0])
39+
log_probability(mmap, [0, 0])

src/Core.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ end
4141
$TYPEDSIGNATURES
4242
4343
Set the evidence of an UAI instance.
44-
45-
### Examples
46-
```jldoctest; setup=:(using TensorInference)
47-
julia> problem = read_uai_problem("Promedus_14"); problem.obsvars, problem.obsvals
48-
([42, 48, 27, 30, 29, 15, 124, 5, 148], [1, 1, 1, 1, 1, 1, 1, 1, 1])
49-
50-
julia> set_evidence!(problem, 2=>0, 4=>1); problem.obsvars, problem.obsvals
51-
([2, 4], [0, 1])
52-
```
5344
"""
5445
function set_evidence!(uai::UAIInstance, pairs::Pair{Int}...)
5546
empty!(uai.obsvars)

src/TensorInference.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module TensorInference
22

33
using OMEinsum, LinearAlgebra
44
using DocStringExtensions, TropicalNumbers
5-
using Artifacts
65
# The Tropical GEMM support
76
using TropicalGEMM
87
using StatsBase
@@ -12,7 +11,7 @@ export RescaledArray
1211
export contraction_complexity, TreeSA, GreedyMethod, KaHyParBipartite, SABipartite, MergeGreedy, MergeVectors
1312

1413
# read and load uai files
15-
export read_uai_file, read_td_file, read_uai_evid_file, read_uai_mar_file, read_uai_problem, uai_problem_from_file
14+
export read_model_file, read_td_file, read_evidence_file, read_solution_file, read_instance
1615
export set_evidence!
1716

1817
# marginals

src/utils.jl

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""
22
$(TYPEDSIGNATURES)
33
4-
Parse the problem instance found in `uai_filepath` defined in the UAI model
4+
Parse the problem instance found in `model_filepath` defined in the UAI model
55
format.
66
77
The UAI file formats are defined in:
88
https://personal.utdallas.edu/~vibhav.gogate/uai16-evaluation/uaiformat.html
99
"""
10-
function read_uai_file(uai_filepath; factor_eltype = Float64)
10+
function read_model_file(model_filepath; factor_eltype = Float64)
1111
# Read the uai file into an array of lines
12-
str = open(uai_filepath) do file
12+
str = open(model_filepath) do file
1313
read(file, String)
1414
end
15-
return read_uai_string(str; factor_eltype)
15+
return read_model_string(str; factor_eltype)
1616
end
1717

18-
function read_uai_string(str; factor_eltype = Float64)
18+
function read_model_string(str; factor_eltype = Float64)
1919
rawlines = split(str, "\n")
2020
# Filter out empty lines
2121
lines = filter(!isempty, rawlines)
@@ -65,19 +65,19 @@ end
6565
"""
6666
$(TYPEDSIGNATURES)
6767
68-
Return the observed variables and values in `uai_evid_filepath`. If the passed
68+
Return the observed variables and values in `evidence_filepath`. If the passed
6969
file path is an empty string, return empty vectors.
7070
7171
The UAI file formats are defined in:
7272
https://personal.utdallas.edu/~vibhav.gogate/uai16-evaluation/uaiformat.html
7373
"""
74-
function read_uai_evid_file(uai_evid_filepath::AbstractString)
75-
if isempty(uai_evid_filepath)
74+
function read_evidence_file(evidence_filepath::AbstractString)
75+
if isempty(evidence_filepath)
7676
# No evidence
7777
return Int64[], Int64[]
7878
else
7979
# Read the last line of the uai evid file
80-
line = open(uai_evid_filepath) do file
80+
line = open(evidence_filepath) do file
8181
readlines(file)
8282
end |> last
8383

@@ -104,10 +104,10 @@ as in the model
104104
The UAI file formats are defined in:
105105
https://personal.utdallas.edu/~vibhav.gogate/uai16-evaluation/uaiformat.html
106106
"""
107-
function read_uai_mar_file(uai_mar_filepath::AbstractString; factor_eltype = Float64)
107+
function read_solution_file(solution_filepath::AbstractString; factor_eltype = Float64)
108108

109109
# Read the uai mar file into an array of lines
110-
rawlines = open(uai_mar_filepath) do file
110+
rawlines = open(solution_filepath) do file
111111
readlines(file)
112112
end
113113

@@ -175,31 +175,24 @@ end
175175
"""
176176
$(TYPEDSIGNATURES)
177177
178-
Read a UAI problem from an artifact.
178+
Read a UAI problem instance from a file.
179179
"""
180-
function read_uai_problem(problem::AbstractString; eltype=Float64)::UAIInstance
181-
uai_filepath = joinpath(artifact"MAR_prob", problem * ".uai")
182-
uai_evid_filepath = joinpath(artifact"MAR_prob", problem * ".uai.evid")
183-
uai_mar_filepath = joinpath(artifact"MAR_sol", problem * ".uai.MAR")
184-
return uai_problem_from_file(uai_filepath; uai_evid_filepath, uai_mar_filepath, eltype)
185-
end
186-
187-
"""
188-
$(TYPEDSIGNATURES)
189-
190-
Read a UAI problem from a file.
191-
"""
192-
function uai_problem_from_file(uai_filepath::String; uai_evid_filepath="", uai_mar_filepath="", eltype=Float64)::UAIInstance
193-
nvars, cards, ncliques, factors = read_uai_file(uai_filepath; factor_eltype = eltype)
194-
obsvars, obsvals = read_uai_evid_file(uai_evid_filepath)
195-
reference_marginals = isempty(uai_mar_filepath) ? Vector{eltype}[] : read_uai_mar_file(uai_mar_filepath)
180+
function read_instance(
181+
model_filepath::AbstractString;
182+
evidence_filepath::AbstractString = "",
183+
solution_filepath::AbstractString = "",
184+
eltype = Float64
185+
)::UAIInstance
186+
nvars, cards, ncliques, factors = read_model_file(model_filepath; factor_eltype = eltype)
187+
obsvars, obsvals = read_evidence_file(evidence_filepath)
188+
reference_marginals = isempty(solution_filepath) ? Vector{eltype}[] : read_solution_file(solution_filepath)
196189
return UAIInstance(nvars, ncliques, cards, factors, obsvars, obsvals, reference_marginals)
197190
end
198191

199-
function uai_problem_from_string(uai::String; eltype=Float64)::UAIInstance
200-
nvars, cards, ncliques, factors = read_uai_string(uai; factor_eltype = eltype)
192+
function read_instance_from_string(uai::AbstractString; eltype = Float64)::UAIInstance
193+
nvars, cards, ncliques, factors = read_model_string(uai; factor_eltype = eltype)
201194
return UAIInstance(nvars, ncliques, cards, factors, Int[], Int[], Vector{eltype}[])
202195
end
203196

204197
# patch to get content by broadcasting into array, while keep array size unchanged.
205-
broadcasted_content(x) = asarray(content.(x), x)
198+
broadcasted_content(x) = asarray(content.(x), x)

test/Artifacts.toml

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,6 @@
1-
[MAR_prob]
2-
git-tree-sha1 = "4dd2447ab2b8eeb8fbfc35d0c7416b5f01ff9711"
1+
[uai2014]
2+
git-tree-sha1 = "5d2c17ee6ad8e89f046b370e865780dea89e4268"
33

4-
[[MAR_prob.download]]
5-
sha256 = "857f8b6706dad46698c6e90a1804e1b40633d87f6eb3d82b5f29929bb6f5155a"
6-
url = "https://personal.utdallas.edu/~vibhav.gogate/uai14-competition/files/MAR_prob.tar.gz"
7-
8-
[MAR_sol]
9-
git-tree-sha1 = "8a86826145efa6b7d7d9c837acd80e33d1368f37"
10-
11-
[[MAR_sol.download]]
12-
sha256 = "d8616ebfc1ab538c2957919f8bb47bd9c1fb86392dd025585cde041bc4e0e934"
13-
url = "https://personal.utdallas.edu/~vibhav.gogate/uai14-competition/files/MAR_sol.tar.gz"
14-
15-
[MMAP_UAI2014]
16-
git-tree-sha1 = "869778bbf5214cbff2169ecc2f3e67e2cb1b6a7a"
17-
18-
[[MMAP_UAI2014.download]]
19-
sha256 = "0080c4851e23c17a42262cdaf4cb1a7aa4b80674435756d0d1ade76d80b9f33f"
20-
url = "https://personal.utdallas.edu/~vibhav.gogate/uai14-competition/files/MMAP_UAI2014.tar.gz"
21-
22-
[PR_prob]
23-
git-tree-sha1 = "a9baff14cc5f64a5d95920928581e2b4eb82acd3"
24-
25-
[[PR_prob.download]]
26-
sha256 = "20b38d43a0718ab555988f041069380a30bbb68881e60d07ebf004054eb9f14f"
27-
url = "https://personal.utdallas.edu/~vibhav.gogate/uai14-competition/files/PR_prob.tar.gz"
28-
29-
[PR_sol]
30-
git-tree-sha1 = "e6643155c4ee433d20ddb7e58441b33b35ecacb8"
31-
32-
[[PR_sol.download]]
33-
sha256 = "86b37c0e7c83f6ff162c88d48250e0bf2b7dd73d44441074ae93a81986238436"
34-
url = "https://personal.utdallas.edu/~vibhav.gogate/uai14-competition/files/PR_sol.tar.gz"
4+
[[uai2014.download]]
5+
sha256 = "22dff6d2b27f5e78b315e4c756c24a0fb9e476c8e814a2546d7f61822426b08a"
6+
url = "https://github.com/mroavi/uai-2014-inference-competition/raw/main/uai2014.tar.gz"

0 commit comments

Comments
 (0)