Skip to content

Commit e84ed15

Browse files
Merge pull request #3496 from CliMA/ck/repro_fixes
Reproducibility infrastructure fixes
2 parents 29ec888 + 6d92728 commit e84ed15

File tree

4 files changed

+35
-43
lines changed

4 files changed

+35
-43
lines changed

reproducibility_tests/ref_counter.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
191
1+
192
22

33
# **README**
44
#
@@ -21,6 +21,9 @@
2121

2222
#=
2323
24+
192
25+
- Reproducibility infrastructure fixes.
26+
2427
191
2528
- Reproducibility infrastructure debugging.
2629

reproducibility_tests/reproducibility_tools.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ function error_if_dissimilar_dicts(dicts, dict)
2727
end
2828
end
2929

30-
all_files_in_dir(dir) =
31-
map((root, dirs, files) -> joinpath(root, file), walkdir(dir))
30+
function all_files_in_dir(dir)
31+
all_files = String[]
32+
for (root, dirs, files) in walkdir(dir)
33+
for file in files
34+
push!(all_files, joinpath(root, file))
35+
end
36+
end
37+
return all_files
38+
end
3239

3340
function no_comparison_error(dirs, non_existent_files)
3441
msg = "\n\n"
@@ -252,11 +259,12 @@ function export_reproducibility_results(
252259
joinpath(@__DIR__, "ref_counter.jl"),
253260
),
254261
skip::Bool = !haskey(ENV, "BUILDKITE_COMMIT"),
262+
repro_folder = "reproducibility_bundle",
255263
)
256-
repro_folder = joinpath(computed_dir, "reproducibility_bundle")
257-
data_file_computed = joinpath(repro_folder, computed_filename)
264+
repro_dir = joinpath(computed_dir, repro_folder)
265+
data_file_computed = joinpath(repro_dir, computed_filename)
258266

259-
mkpath(repro_folder)
267+
mkpath(repro_dir)
260268
hdfwriter = InputOutput.HDF5Writer(data_file_computed, comms_ctx)
261269
InputOutput.write!(hdfwriter, field_vec, name)
262270
Base.close(hdfwriter)
@@ -277,7 +285,7 @@ function export_reproducibility_results(
277285
for (computed_mse, dir) in zip(computed_mses, dirs)
278286
commit_hash = basename(dirname(dir))
279287
computed_mse_file =
280-
joinpath(repro_folder, "computed_mse_$commit_hash.json")
288+
joinpath(repro_dir, "computed_mse_$commit_hash.json")
281289

282290
open(computed_mse_file, "w") do io
283291
JSON.print(io, computed_mse)

reproducibility_tests/reproducibility_utils.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ function move_data_to_save_dir(;
401401
ref_counter_PR = read_ref_counter(ref_counter_file_PR),
402402
skip = get(ENV, "BUILDKITE_PIPELINE_SLUG", nothing) != "climaatmos-ci",
403403
n_hash_characters = 7,
404+
repro_folder = "reproducibility_bundle",
404405
)
405406
buildkite_ci || return nothing
406407

@@ -419,15 +420,17 @@ function move_data_to_save_dir(;
419420
mkpath(dest_root)
420421
dest_dir = joinpath(dest_root, commit_sha)
421422
mkpath(dest_dir)
423+
dest_repro = joinpath(dest_dir, repro_folder)
424+
mkpath(dest_repro)
422425
# Always move reproducibility data, so that we
423426
# can compare against multiple references
424427
for src in dirs_src
425-
dst = joinpath(dest_dir, basename(src))
428+
dst = joinpath(dest_repro, basename(src))
426429
mv(src, dst; force = true)
427430
debug_reproducibility() &&
428431
@info "Reproducibility: File $src moved to $dst"
429432
end
430-
ref_counter_file_main = joinpath(dest_dir, "ref_counter.jl")
433+
ref_counter_file_main = joinpath(dest_repro, "ref_counter.jl")
431434
mv(ref_counter_file_PR, ref_counter_file_main; force = true)
432435
else
433436
if debug_reproducibility()

test/unit_reproducibility_infra.jl

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,8 @@ if pkgversion(ClimaCore) ≥ v"0.14.18"
11991199
@test source_checksum(hash1) == source_checksum(computed_dir)
12001200
@test source_checksum(hash2) == source_checksum(computed_dir)
12011201

1202+
repro_folder = "repro_bundle"
1203+
repro_dir = joinpath(save_dir, "hash_new", repro_folder)
12021204
move_data_to_save_dir(;
12031205
dest_root = save_dir,
12041206
buildkite_ci = true,
@@ -1212,25 +1214,12 @@ if pkgversion(ClimaCore) ≥ v"0.14.18"
12121214
"ref_counter.jl",
12131215
),
12141216
ref_counter_PR = 3,
1217+
repro_folder,
12151218
skip = false,
12161219
)
1217-
@test isfile(
1218-
joinpath(
1219-
save_dir,
1220-
"hash_new",
1221-
"job_id_1",
1222-
"ref_prog_state.hdf5",
1223-
),
1224-
)
1225-
@test isfile(
1226-
joinpath(
1227-
save_dir,
1228-
"hash_new",
1229-
"job_id_2",
1230-
"ref_prog_state.hdf5",
1231-
),
1232-
)
1233-
@test isfile(joinpath(save_dir, "hash_new", "ref_counter.jl"))
1220+
@test isfile(joinpath(repro_dir, "job_id_1", "ref_prog_state.hdf5"))
1221+
@test isfile(joinpath(repro_dir, "job_id_2", "ref_prog_state.hdf5"))
1222+
@test isfile(joinpath(repro_dir, "ref_counter.jl"))
12341223
end
12351224
end
12361225

@@ -1283,6 +1272,8 @@ if pkgversion(ClimaCore) ≥ v"0.14.18"
12831272
@test source_checksum(hash1) == source_checksum(computed_dir)
12841273
@test source_checksum(hash2) == source_checksum(computed_dir)
12851274

1275+
repro_folder = "repro_bundle"
1276+
repro_dir = joinpath(save_dir, "hash_new", repro_folder)
12861277
move_data_to_save_dir(;
12871278
dest_root = save_dir,
12881279
buildkite_ci = true,
@@ -1295,26 +1286,13 @@ if pkgversion(ClimaCore) ≥ v"0.14.18"
12951286
ref_counter_file_dir,
12961287
"ref_counter.jl",
12971288
),
1289+
repro_folder,
12981290
ref_counter_PR = 3,
12991291
skip = false,
13001292
)
1301-
@test isfile(
1302-
joinpath(
1303-
save_dir,
1304-
"hash_new",
1305-
"job_id_1",
1306-
"ref_prog_state.hdf5",
1307-
),
1308-
)
1309-
@test isfile(
1310-
joinpath(
1311-
save_dir,
1312-
"hash_new",
1313-
"job_id_2",
1314-
"ref_prog_state.hdf5",
1315-
),
1316-
)
1317-
@test isfile(joinpath(save_dir, "hash_new", "ref_counter.jl"))
1293+
@test isfile(joinpath(repro_dir, "job_id_1", "ref_prog_state.hdf5"))
1294+
@test isfile(joinpath(repro_dir, "job_id_2", "ref_prog_state.hdf5"))
1295+
@test isfile(joinpath(repro_dir, "ref_counter.jl"))
13181296
end
13191297
end
13201298
end

0 commit comments

Comments
 (0)