Skip to content

Commit cacf6f0

Browse files
committed
Improve naming of filepath arguments and variables
1 parent 7c1843d commit cacf6f0

File tree

9 files changed

+38
-38
lines changed

9 files changed

+38
-38
lines changed

benchmark/bench_map.jl

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

77
const SUITE = BenchmarkGroup()
88

9-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
10-
problem = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
9+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
10+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1111

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

benchmark/bench_mar.jl

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

99
const SUITE = BenchmarkGroup()
1010

11-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
12-
problem = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
11+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
12+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1313

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

benchmark/bench_mmap.jl

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

77
const SUITE = BenchmarkGroup()
88

9-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
10-
problem = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
9+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
10+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1111
optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40)
1212

1313
# Does not marginalize any var

src/utils.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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_model_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
1515
return read_model_string(str; factor_eltype)
@@ -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_evidence_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_solution_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

@@ -178,14 +178,14 @@ $(TYPEDSIGNATURES)
178178
Read a UAI problem instance from a file.
179179
"""
180180
function read_instance(
181-
uai_filepath::AbstractString;
182-
uai_evid_filepath::AbstractString = "",
183-
uai_mar_filepath::AbstractString = "",
181+
model_filepath::AbstractString;
182+
evidence_filepath::AbstractString = "",
183+
solution_filepath::AbstractString = "",
184184
eltype = Float64
185185
)::UAIInstance
186-
nvars, cards, ncliques, factors = read_model_file(uai_filepath; factor_eltype = eltype)
187-
obsvars, obsvals = read_evidence_file(uai_evid_filepath)
188-
reference_marginals = isempty(uai_mar_filepath) ? Vector{eltype}[] : read_solution_file(uai_mar_filepath)
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)
189189
return UAIInstance(nvars, ncliques, cards, factors, obsvars, obsvals, reference_marginals)
190190
end
191191

test/cuda.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ CUDA.allowscalar(false)
55

66
@testset "gradient-based tensor network solvers" begin
77
################# Load problem ####################
8-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
9-
instance = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
8+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
9+
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
1010

1111
# does not optimize over open vertices
1212
tn = TensorNetworkModel(instance; optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40))
@@ -23,8 +23,8 @@ end
2323

2424
@testset "map" begin
2525
################# Load problem ####################
26-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
27-
instance = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
26+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
27+
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
2828

2929
# does not optimize over open vertices
3030
tn = TensorNetworkModel(instance; optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40))
@@ -39,8 +39,8 @@ end
3939

4040
@testset "mmap" begin
4141
################# Load problem ####################
42-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
43-
instance = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
42+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
43+
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
4444

4545
optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40)
4646
tn_ref = TensorNetworkModel(instance; optimizer)

test/inference.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ using TensorInference
1212
end
1313

1414
@testset "cached, rescaled contract" begin
15-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
16-
problem = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
15+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
16+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
1717
ref_sol = problem.reference_marginals
1818
optimizer = TreeSA(ntrials = 1, niters = 5, βs = 0.1:0.1:100)
1919
tn = TensorNetworkModel(problem; optimizer)
@@ -66,8 +66,8 @@ end
6666
for problem in problems
6767
@info "Testing: $problem"
6868
@testset "$(problem)" begin
69-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths(problem, "MAR")
70-
problem = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
69+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths(problem, "MAR")
70+
problem = read_instance(model_filepath; evidence_filepath, solution_filepath)
7171
ref_sol = problem.reference_marginals
7272
obsvars = problem.obsvars
7373

test/maxprob.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ using TensorInference
44

55
@testset "map" begin
66
################# Load problem ####################
7-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
8-
instance = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
7+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
8+
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
99

1010
# does not optimize over open vertices
1111
tn = TensorNetworkModel(instance; optimizer = TreeSA(ntrials = 3, niters = 2, βs = 1:0.1:80))

test/mmap.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ end
99

1010
@testset "mmap" begin
1111
################# Load problem ####################
12-
model_filepath, evid_filepath, sol_filepath = get_instance_filepaths("Promedus_14", "MAR")
13-
instance = read_instance(model_filepath; uai_evid_filepath = evid_filepath, uai_mar_filepath = sol_filepath)
12+
model_filepath, evidence_filepath, solution_filepath = get_instance_filepaths("Promedus_14", "MAR")
13+
instance = read_instance(model_filepath; evidence_filepath, solution_filepath)
1414

1515
optimizer = TreeSA(ntrials = 1, niters = 2, βs = 1:0.1:40)
1616
tn_ref = TensorNetworkModel(instance; optimizer)

test/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ task.
1111
"""
1212
function get_instance_filepaths(problem_name::AbstractString, task::AbstractString)
1313
model_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai")
14-
evid_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai.evid")
15-
sol_filepath = joinpath(artifact"uai2014", task, problem_name * ".uai." * task)
16-
return model_filepath, evid_filepath, sol_filepath
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
1717
end

0 commit comments

Comments
 (0)