Skip to content

Commit

Permalink
Simplify interaction_fetching benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Nov 3, 2024
1 parent 114a5df commit 0065c8b
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 259 deletions.
56 changes: 13 additions & 43 deletions benchmark/interaction_fetching/cooler_cis_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
#include <filesystem>
#include <string_view>
#include <utility>
#include <vector>

#include "./common.hpp"
Expand All @@ -21,43 +23,22 @@ static const std::filesystem::path test_file{"test/data/integration_tests/4DNFIZ
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
100000, 250000, 500000, 1000000, 2500000};

static const auto w = balancing::Method::KR();

static const std::vector<Params> params_uint{
{"cis; small; normalization=NONE; symmetric", true, 100e3, 100e3, 25e3, 25e3},
{"cis; medium; normalization=NONE; symmetric", true},
{"cis; large; normalization=NONE; symmetric", true, 5e6, 5e6, 500e3, 500e3},
};

static const std::vector<Params> params_fp{
{"cis; small; normalization=weight; symmetric", true, 100e3, 100e3, 25e3, 25e3, 1, w},
{"cis; medium; normalization=weight; symmetric", true, 1.0e6, 1.0e6, 250e3, 250e3, 1, w},
{"cis; large; normalization=weight; symmetric", true, 5e6, 5e6, 500e3, 500e3, 1, w},
};
static constexpr std::string_view range_small{"chr2L:5,000,000-5,100,000"};
static constexpr std::string_view range_medium{"chr2L:6,000,000-7,000,000"};
static constexpr std::string_view range_large{"chr2L:10,000,000-15,000,000"};

TEST_CASE("cooler::File::fetch (cis; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_uint) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0);
const auto& chrom2 = cis ? chrom1 : chroms.at(3);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), label, res))
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), range, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<std::uint32_t>(clr, range1, range2, normalization);
}
return nnz;
meter.measure([&clr, &range]() {
return count_nnz<std::uint32_t>(clr, range, range, balancing::Method::NONE());
});
};
}
Expand All @@ -69,24 +50,13 @@ TEST_CASE("cooler::File::fetch (cis; double)") {
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_fp) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0);
const auto& chrom2 = cis ? chrom1 : chroms.at(3);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), label, res))
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), range, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<double>(clr, range1, range2, normalization);
}
return nnz;
meter.measure([&clr, &range]() {
return count_nnz<double>(clr, range, range, balancing::Method::KR());
});
};
}
Expand Down
57 changes: 16 additions & 41 deletions benchmark/interaction_fetching/cooler_trans_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
#include <filesystem>
#include <string_view>
#include <utility>
#include <vector>

#include "./common.hpp"
Expand All @@ -21,43 +23,27 @@ static const std::filesystem::path test_file{"test/data/integration_tests/4DNFIZ
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
100000, 250000, 500000, 1000000, 2500000};

static const auto w = balancing::Method::KR();
static constexpr std::pair<std::string_view, std::string_view> range_small{
"chr2L:15,000,000-15,100,000", "chrX:10,200,000-10,300,000"};

static const std::vector<Params> params_uint{
{"trans; small; normalization=NONE; symmetric", false, 100e3, 100e3, 25e3, 25e3},
{"trans; medium; normalization=NONE; symmetric", false},
{"trans; large; normalization=NONE; symmetric", false, 5e6, 5e6, 500e3, 500e3},
};
static constexpr std::pair<std::string_view, std::string_view> range_medium{
"chr2L:5,000,000-6,000,000", "chrX:5,000,000-6,000,000"};

static const std::vector<Params> params_fp{
{"trans; small; normalization=weight; symmetric", false, 100e3, 100e3, 25e3, 25e3, 1, w},
{"trans; medium; normalization=weight; symmetric", false, 1.0e6, 1.0e6, 250e3, 250e3, 1, w},
{"trans; large; normalization=weight; symmetric", false, 5e6, 5e6, 500e3, 500e3, 1, w},
};
static constexpr std::pair<std::string_view, std::string_view> range_large{
"chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"};

TEST_CASE("cooler::File::fetch (trans; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_uint) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0);
const auto& chrom2 = cis ? chrom1 : chroms.at(3);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), label, res))
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<std::uint32_t>(clr, range1, range2, normalization);
}
return nnz;
meter.measure([&clr, range1 = query.first, range2 = query.second]() {
return count_nnz<std::uint32_t>(clr, range1, range2, balancing::Method::NONE());
});
};
}
Expand All @@ -69,24 +55,13 @@ TEST_CASE("cooler::File::fetch (trans; double)") {
test_file.string(), resolutions.back()))
.chromosomes();
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_fp) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0);
const auto& chrom2 = cis ? chrom1 : chroms.at(3);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}bp"), label, res))
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const cooler::File clr(
fmt::format(FMT_STRING("{}::/resolutions/{}"), test_file.string(), res));
meter.measure([&clr, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<double>(clr, range1, range2, normalization);
}
return nnz;
meter.measure([&clr, range1 = query.first, range2 = query.second]() {
return count_nnz<double>(clr, range1, range2, balancing::Method::KR());
});
};
}
Expand Down
59 changes: 13 additions & 46 deletions benchmark/interaction_fetching/file_cis_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
#include <filesystem>
#include <string_view>
#include <utility>
#include <vector>

#include "./common.hpp"
#include "hictk/balancing/methods.hpp"
#include "hictk/cooler/cooler.hpp"
#include "hictk/cooler/validation.hpp"
#include "hictk/file.hpp"

using namespace hictk;
Expand All @@ -25,45 +26,23 @@ static const std::filesystem::path test_file3{"test/data/hic/4DNFIZ1ZVXC8.hic9"}
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
100000, 250000, 500000, 1000000, 2500000};

static const auto w = balancing::Method::KR();

static const std::vector<Params> params_uint{
{"cis; small; normalization=NONE; symmetric", true, 100e3, 100e3, 25e3, 25e3},
{"cis; medium; normalization=NONE; symmetric", true},
{"cis; large; normalization=NONE; symmetric", true, 5e6, 5e6, 500e3, 500e3},
};

static const std::vector<Params> params_fp{
{"cis; small; normalization=weight; symmetric", true, 100e3, 100e3, 25e3, 25e3, 1, w},
{"cis; medium; normalization=weight; symmetric", true, 1.0e6, 1.0e6, 250e3, 250e3, 1, w},
{"cis; large; normalization=weight; symmetric", true, 5e6, 5e6, 500e3, 500e3, 1, w},
};
static constexpr std::string_view range_small{"chr2L:5,000,000-5,100,000"};
static constexpr std::string_view range_medium{"chr2L:6,000,000-7,000,000"};
static constexpr std::string_view range_large{"chr2L:10,000,000-15,000,000"};

TEST_CASE("File::fetch (cis; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
const std::uint32_t chrom_id_offset = cooler::utils::is_multires_file(path.string()) ? 0 : 1;
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_uint) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0 + chrom_id_offset);
const auto& chrom2 = cis ? chrom1 : chroms.at(3 + chrom_id_offset);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), label, res))
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), range, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<std::uint32_t>(f, range1, range2, normalization);
}
return nnz;
meter.measure([&f, &range]() {
return count_nnz<std::uint32_t>(f, range, range, balancing::Method::NONE());
});
};
}
Expand All @@ -77,25 +56,13 @@ TEST_CASE("File::fetch (cis; double)") {
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
const std::uint32_t chrom_id_offset = cooler::utils::is_multires_file(path.string()) ? 0 : 1;
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_fp) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0 + chrom_id_offset);
const auto& chrom2 = cis ? chrom1 : chroms.at(3 + chrom_id_offset);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), label, res))
for (const auto& range : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), range, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<double>(f, range1, range2, normalization);
}
return nnz;
meter.measure([&f, &range]() {
return count_nnz<double>(f, range, range, balancing::Method::KR());
});
};
}
Expand Down
1 change: 0 additions & 1 deletion benchmark/interaction_fetching/file_gw_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "./common.hpp"
#include "hictk/balancing/methods.hpp"
#include "hictk/cooler/cooler.hpp"
#include "hictk/cooler/validation.hpp"
#include "hictk/file.hpp"

using namespace hictk;
Expand Down
60 changes: 16 additions & 44 deletions benchmark/interaction_fetching/file_trans_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
#include <filesystem>
#include <string_view>
#include <utility>
#include <vector>

#include "./common.hpp"
#include "hictk/balancing/methods.hpp"
#include "hictk/cooler/cooler.hpp"
#include "hictk/cooler/validation.hpp"
#include "hictk/file.hpp"

using namespace hictk;
Expand All @@ -25,45 +26,28 @@ static const std::filesystem::path test_file3{"test/data/hic/4DNFIZ1ZVXC8.hic9"}
static const std::vector<std::uint32_t> resolutions{1000, 5000, 10000, 25000, 50000,
100000, 250000, 500000, 1000000, 2500000};

static const auto w = balancing::Method::KR();
static constexpr std::pair<std::string_view, std::string_view> range_small{
"chr2L:15,000,000-15,100,000", "chrX:10,200,000-10,300,000"};

static const std::vector<Params> params_uint{
{"trans; small; normalization=NONE; symmetric", false, 100e3, 100e3, 25e3, 25e3},
{"trans; medium; normalization=NONE; symmetric", false},
{"trans; large; normalization=NONE; symmetric", false, 5e6, 5e6, 500e3, 500e3},
};
static constexpr std::pair<std::string_view, std::string_view> range_medium{
"chr2L:5,000,000-6,000,000", "chrX:5,000,000-6,000,000"};

static const std::vector<Params> params_fp{
{"trans; small; normalization=weight; symmetric", false, 100e3, 100e3, 25e3, 25e3, 1, w},
{"trans; medium; normalization=weight; symmetric", false, 1.0e6, 1.0e6, 250e3, 250e3, 1, w},
{"trans; large; normalization=weight; symmetric", false, 5e6, 5e6, 500e3, 500e3, 1, w},
};
static constexpr std::pair<std::string_view, std::string_view> range_large{
"chr2L:15,000,000-20,000,000", "chrX:15,000,000-20,000,000"};

TEST_CASE("File::fetch (trans; uint32)") {
const auto chroms = cooler::File(fmt::format(FMT_STRING("{}::/resolutions/{}"),
test_file1.string(), resolutions.back()))
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
const std::uint32_t chrom_id_offset = cooler::utils::is_multires_file(path.string()) ? 0 : 1;
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_uint) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0 + chrom_id_offset);
const auto& chrom2 = cis ? chrom1 : chroms.at(3 + chrom_id_offset);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), label, res))
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<std::uint32_t>(f, range1, range2, normalization);
}
return nnz;
meter.measure([&f, range1 = query.first, range2 = query.second]() {
return count_nnz<std::uint32_t>(f, range1, range2, balancing::Method::NONE());
});
};
}
Expand All @@ -77,25 +61,13 @@ TEST_CASE("File::fetch (trans; double)") {
.chromosomes();

for (const auto& path : {test_file1, test_file2, test_file3}) {
const std::uint32_t chrom_id_offset = cooler::utils::is_multires_file(path.string()) ? 0 : 1;
for (const auto& res : resolutions) {
for (const auto& [label, cis, avg_height, avg_width, height_std, width_std, num_queries,
normalization_, seed] : params_fp) {
const auto normalization = normalization_;
const auto& chrom1 = chroms.at(0 + chrom_id_offset);
const auto& chrom2 = cis ? chrom1 : chroms.at(3 + chrom_id_offset);
const auto queries = generate_queries(chrom1, chrom2, num_queries, avg_height, avg_width,
height_std, width_std, seed);

BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), path.extension(), label, res))
for (const auto& query : {range_small, range_medium, range_large}) {
BENCHMARK_ADVANCED(fmt::format(FMT_STRING("{}; {}; {}bp"), query.first, query.second, res))
(Catch::Benchmark::Chronometer meter) {
const File f(path.string(), res);
meter.measure([&f, &queries, &normalization]() {
std::int64_t nnz{};
for (const auto& [range1, range2] : queries) {
nnz += count_nnz<double>(f, range1, range2, normalization);
}
return nnz;
meter.measure([&f, range1 = query.first, range2 = query.second]() {
return count_nnz<double>(f, range1, range2, balancing::Method::KR());
});
};
}
Expand Down
Loading

0 comments on commit 0065c8b

Please sign in to comment.