Skip to content

Commit

Permalink
Avoid racing condition in geometry read/write of Kalman filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo committed Nov 20, 2023
1 parent 580b243 commit c1f067a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 37 deletions.
6 changes: 4 additions & 2 deletions tests/common/tests/kalman_fitting_telescope_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class KalmanFittingTelescopeTests : public KalmanFittingTests {
}

protected:
static void SetUpTestCase() {
virtual void SetUp() override {

vecmem::host_memory_resource host_mr;

detray::tel_det_config<> tel_cfg{rectangle};
Expand All @@ -77,7 +78,8 @@ class KalmanFittingTelescopeTests : public KalmanFittingTests {
// Write detector file
auto writer_cfg = detray::io::detector_writer_config{}
.format(detray::io::format::json)
.replace_files(true);
.replace_files(true)
.path(std::get<0>(GetParam()));
detray::io::write_detector(det, name_map, writer_cfg);
}
};
Expand Down
5 changes: 3 additions & 2 deletions tests/common/tests/kalman_fitting_wire_chamber_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class KalmanFittingWireChamberTests : public KalmanFittingTests {
}

protected:
static void SetUpTestCase() {
virtual void SetUp() override {
vecmem::host_memory_resource host_mr;

detray::wire_chamber_config wire_chamber_cfg;
Expand All @@ -76,7 +76,8 @@ class KalmanFittingWireChamberTests : public KalmanFittingTests {
// Write detector file
auto writer_cfg = detray::io::detector_writer_config{}
.format(detray::io::format::json)
.replace_files(true);
.replace_files(true)
.path(std::get<0>(GetParam()));
detray::io::write_detector(det, name_map, writer_cfg);
}
};
Expand Down
8 changes: 4 additions & 4 deletions tests/cpu/test_ckf_sparse_tracks_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {
detray::io::write_detector(det, name_map, writer_cfg);

// Read back detector file
const std::string path = name + "/";
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file("telescope_detector_geometry.json")
.add_file("telescope_detector_homogeneous_material.json")
.add_file("telescope_detector_surface_grids.json");
reader_cfg.add_file(path + "telescope_detector_geometry.json")
.add_file(path + "telescope_detector_homogeneous_material.json")
.add_file(path + "telescope_detector_surface_grids.json");

const auto [host_det, names] =
detray::io::read_detector<host_detector_type>(host_mr, reader_cfg);
Expand Down Expand Up @@ -115,7 +116,6 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {
typename writer_type::config smearer_writer_cfg{meas_smearer};

// Run simulator
const std::string path = name + "/";
const std::string full_path = io::data_directory() + path;
std::filesystem::create_directories(full_path);
auto sim = traccc::simulator<host_detector_type, b_field_t, generator_type,
Expand Down
8 changes: 4 additions & 4 deletions tests/cpu/test_kalman_fitter_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
vecmem::host_memory_resource host_mr;

// Read back detector file
const std::string path = name + "/";
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file("telescope_detector_geometry.json")
.add_file("telescope_detector_homogeneous_material.json")
.add_file("telescope_detector_surface_grids.json");
reader_cfg.add_file(path + "telescope_detector_geometry.json")
.add_file(path + "telescope_detector_homogeneous_material.json")
.add_file(path + "telescope_detector_surface_grids.json");

const auto [host_det, names] =
detray::io::read_detector<host_detector_type>(host_mr, reader_cfg);
Expand Down Expand Up @@ -97,7 +98,6 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
typename writer_type::config smearer_writer_cfg{meas_smearer};

// Run simulator
const std::string path = name + "/";
const std::string full_path = io::data_directory() + path;
std::filesystem::create_directories(full_path);
auto sim = traccc::simulator<host_detector_type, b_field_t, generator_type,
Expand Down
6 changes: 3 additions & 3 deletions tests/cpu/test_kalman_fitter_wire_chamber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ TEST_P(KalmanFittingWireChamberTests, Run) {
vecmem::host_memory_resource host_mr;

// Read back detector file
const std::string path = name + "/";
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file("wire_chamber_geometry.json")
.add_file("wire_chamber_homogeneous_material.json")
reader_cfg.add_file(path + "wire_chamber_geometry.json")
.add_file(path + "wire_chamber_homogeneous_material.json")
//.add_file("wire_chamber_surface_grids.json")
.do_check(true);

Expand Down Expand Up @@ -96,7 +97,6 @@ TEST_P(KalmanFittingWireChamberTests, Run) {
typename writer_type::config smearer_writer_cfg{meas_smearer};

// Run simulator
const std::string path = name + "/";
const std::string full_path = io::data_directory() + path;
std::filesystem::create_directories(full_path);
auto sim = traccc::simulator<host_detector_type, b_field_t, generator_type,
Expand Down
16 changes: 8 additions & 8 deletions tests/cuda/test_ckf_sparse_tracks_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {
detray::io::write_detector(det, name_map, writer_cfg);

// Read back detector file
const std::string path = name + "/";
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file("telescope_detector_geometry.json")
.add_file("telescope_detector_homogeneous_material.json")
.add_file("telescope_detector_surface_grids.json");
reader_cfg.add_file(path + "telescope_detector_geometry.json")
.add_file(path + "telescope_detector_homogeneous_material.json")
.add_file(path + "telescope_detector_surface_grids.json");

auto [host_det, names] =
detray::io::read_detector<host_detector_type>(mng_mr, reader_cfg);
Expand Down Expand Up @@ -127,7 +128,6 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {
typename writer_type::config smearer_writer_cfg{meas_smearer};

// Run simulator
const std::string path = name + "/";
const std::string full_path = io::data_directory() + path;
std::filesystem::create_directories(full_path);
auto sim = traccc::simulator<host_detector_type, b_field_t, generator_type,
Expand Down Expand Up @@ -287,31 +287,31 @@ TEST_P(CkfSparseTrackTelescopeTests, Run) {
INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation0, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple(
"single_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_single_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 1, 5000)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation1, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple(
"double_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_double_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 2, 2500)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation2, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple(
"quadra_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_quadra_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 4, 1250)));

INSTANTIATE_TEST_SUITE_P(
CkfSparseTrackTelescopeValidation3, CkfSparseTrackTelescopeTests,
::testing::Values(std::make_tuple(
"decade_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_decade_tracks", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 200.f, 200.f},
std::array<scalar, 2u>{1.f, 1.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 10, 500)));
14 changes: 7 additions & 7 deletions tests/cuda/test_kalman_fitter_telescope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
vecmem::cuda::managed_memory_resource mng_mr;

// Read back detector file
const std::string path = name + "/";
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file("telescope_detector_geometry.json")
.add_file("telescope_detector_homogeneous_material.json")
.add_file("telescope_detector_surface_grids.json");
reader_cfg.add_file(path + "telescope_detector_geometry.json")
.add_file(path + "telescope_detector_homogeneous_material.json")
.add_file(path + "telescope_detector_surface_grids.json");

auto [host_det, names] =
detray::io::read_detector<host_detector_type>(mng_mr, reader_cfg);
Expand Down Expand Up @@ -114,7 +115,6 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
typename writer_type::config smearer_writer_cfg{meas_smearer};

// Run simulator
const std::string path = name + "/";
const std::string full_path = io::data_directory() + path;
std::filesystem::create_directories(full_path);
auto sim = traccc::simulator<host_detector_type, b_field_t, generator_type,
Expand Down Expand Up @@ -223,23 +223,23 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation0, KalmanFittingTelescopeTests,
::testing::Values(std::make_tuple(
"1_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_1_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f}, std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f}, std::array<scalar, 2u>{0.f, 0.f}, 100,
100)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation1, KalmanFittingTelescopeTests,
::testing::Values(std::make_tuple(
"10_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_10_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{10.f, 10.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 100, 100)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation2, KalmanFittingTelescopeTests,
::testing::Values(std::make_tuple(
"100_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"cuda_100_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 100, 100)));
14 changes: 7 additions & 7 deletions tests/sycl/test_kalman_fitter_telescope.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
vecmem::sycl::shared_memory_resource shared_mr;

// Read back detector file
const std::string path = name + "/";
detray::io::detector_reader_config reader_cfg{};
reader_cfg.add_file("telescope_detector_geometry.json")
.add_file("telescope_detector_homogeneous_material.json")
.add_file("telescope_detector_surface_grids.json");
reader_cfg.add_file(path + "telescope_detector_geometry.json")
.add_file(path + "telescope_detector_homogeneous_material.json")
.add_file(path + "telescope_detector_surface_grids.json");

auto [host_det, names] =
detray::io::read_detector<host_detector_type>(shared_mr, reader_cfg);
Expand Down Expand Up @@ -134,7 +135,6 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
typename writer_type::config smearer_writer_cfg{meas_smearer};

// Run simulator
const std::string path = name + "/";
const std::string full_path = io::data_directory() + path;
std::filesystem::create_directories(full_path);
auto sim = traccc::simulator<host_detector_type, b_field_t, generator_type,
Expand Down Expand Up @@ -230,23 +230,23 @@ TEST_P(KalmanFittingTelescopeTests, Run) {
INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation0, KalmanFittingTelescopeTests,
::testing::Values(std::make_tuple(
"1_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"sycl_1_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f}, std::array<scalar, 2u>{1.f, 1.f},
std::array<scalar, 2u>{0.f, 0.f}, std::array<scalar, 2u>{0.f, 0.f}, 100,
100)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation1, KalmanFittingTelescopeTests,
::testing::Values(std::make_tuple(
"10_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"sycl_10_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{10.f, 10.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 100, 100)));

INSTANTIATE_TEST_SUITE_P(
KalmanFitTelescopeValidation2, KalmanFittingTelescopeTests,
::testing::Values(std::make_tuple(
"100_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
"sycl_100_GeV_0_phi", std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 3u>{0.f, 0.f, 0.f},
std::array<scalar, 2u>{100.f, 100.f}, std::array<scalar, 2u>{0.f, 0.f},
std::array<scalar, 2u>{0.f, 0.f}, 100, 100)));

0 comments on commit c1f067a

Please sign in to comment.