Skip to content

Commit 2344aed

Browse files
committed
[query] Various Benchmark Suite Improvements
1 parent 5828ffd commit 2344aed

14 files changed

+446
-319
lines changed

hail/python/benchmark/conftest.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def pytest_addoption(parser):
1313
parser.addoption("--log", type=str, help='Log file path', default=None)
1414
parser.addoption("--output", type=str, help="Output file path.", default=None)
15-
parser.addoption("--data-dir", type=str, help="Data directory.", default=None)
15+
parser.addoption("--data-dir", type=str, help="Data directory.", default=os.getenv('HAIL_BENCHMARK_DIR'))
1616
parser.addoption('--iterations', type=int, help='override number of iterations for all benchmarks', default=None)
1717
parser.addoption('--cores', type=int, help='Number of cores to use.', default=1)
1818
parser.addoption(
@@ -23,38 +23,19 @@ def pytest_addoption(parser):
2323
const='cpu',
2424
default=None,
2525
)
26+
parser.addoption(
27+
'--max-duration',
28+
type=int,
29+
help='Maximum permitted duration for any benchmark trial in seconds, not to be confused with pytest-timeout',
30+
default=200,
31+
)
2632
parser.addoption('--max-failures', type=int, help='Stop benchmarking item after this many failures', default=3)
27-
parser.addoption('--profiler-path', type=str, help='path to aysnc profiler', default=None)
28-
parser.addoption('--profiler-fmt', choices=['html', 'flame', 'jfr'], help='Choose profiler output.', default='html')
29-
30-
31-
def run_config_from_pytest_config(pytest_config):
32-
return type(
33-
'RunConfig',
34-
(object,),
35-
{
36-
**{
37-
flag: pytest_config.getoption(flag) or default
38-
for flag, default in [
39-
('log', None),
40-
('output', None),
41-
('cores', 1),
42-
('data_dir', os.getenv('HAIL_BENCHMARK_DIR')),
43-
('iterations', None),
44-
('max_failures', None),
45-
('profile', None),
46-
('profiler_path', os.getenv('ASYNC_PROFILER_HOME')),
47-
('profiler_fmt', None),
48-
]
49-
},
50-
'verbose': pytest_config.getoption('verbose') > 0,
51-
'quiet': pytest_config.getoption('verbose') < 0,
52-
'timeout': int(pytest_config.getoption('timeout') or 100),
53-
},
33+
parser.addoption(
34+
'--profiler-path', type=str, help='path to aysnc profiler', default=os.getenv('ASYNC_PROFILER_HOME')
5435
)
36+
parser.addoption('--profiler-fmt', choices=['html', 'flame', 'jfr'], help='Choose profiler output.', default='html')
5537

5638

5739
@pytest.hookimpl
5840
def pytest_configure(config):
59-
config.run_config = run_config_from_pytest_config(config)
60-
init_logging(file=config.run_config.log)
41+
init_logging(file=config.getoption('log'))

hail/python/benchmark/hail/benchmark_benchmark_analysis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import tempfile
22
from pathlib import Path
33

4-
from benchmark.tools import benchmark
4+
import pytest
5+
56
from benchmark.tools.impex import dump_tsv, import_timings
67
from benchmark.tools.statistics import analyze_benchmarks
78

89

9-
@benchmark()
10+
@pytest.mark.benchmark()
1011
def benchmark_analyze_benchmarks(local_tmpdir, onethreetwo, onethreethree):
1112
inputs = (onethreetwo, onethreethree)
1213
inputs = ((v, Path(tempfile.mktemp(dir=local_tmpdir))) for v in inputs)

hail/python/benchmark/hail/benchmark_combiner.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import pytest
44

55
import hail as hl
6-
from benchmark.tools import benchmark, chunk
6+
from benchmark.hail.utils import XFail
7+
from benchmark.tools import chunk
78
from hail.vds.combiner import combine_variant_datasets, new_combiner, transform_gvcf
89

910
COMBINE_GVCF_MAX = 100
@@ -14,7 +15,8 @@ def import_vcf(path):
1415
return hl.import_vcf(str(path), reference_genome='GRCh38', force=True)
1516

1617

17-
@benchmark()
18+
@pytest.mark.benchmark()
19+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
1820
@with_flags(no_ir_logging='1')
1921
def benchmark_compile_2k_merge(empty_gvcf, tmp_path):
2022
vcf = import_vcf(empty_gvcf)
@@ -23,29 +25,30 @@ def benchmark_compile_2k_merge(empty_gvcf, tmp_path):
2325
hl.vds.write_variant_datasets(combined, str(tmp_path / 'combiner-multi-write'), overwrite=True)
2426

2527

26-
@benchmark()
28+
@pytest.mark.benchmark()
29+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
2730
def benchmark_python_only_10k_transform(empty_gvcf):
2831
for vcf in [import_vcf(empty_gvcf)] * 10_000:
2932
transform_gvcf(vcf, [])
3033

3134

32-
@benchmark()
35+
@pytest.mark.benchmark()
3336
def benchmark_python_only_10k_combine(empty_gvcf):
3437
vcf = import_vcf(empty_gvcf)
3538
mt = transform_gvcf(vcf, [])
3639
for mts in chunk(COMBINE_GVCF_MAX, [mt] * 10_000):
3740
combine_variant_datasets(mts)
3841

3942

40-
@benchmark()
43+
@pytest.mark.benchmark()
4144
def benchmark_import_and_transform_gvcf(single_gvcf):
4245
mt = import_vcf(single_gvcf)
4346
vds = transform_gvcf(mt, [])
4447
vds.reference_data._force_count_rows()
4548
vds.variant_data._force_count_rows()
4649

4750

48-
@benchmark()
51+
@pytest.mark.benchmark()
4952
def benchmark_import_gvcf_force_count(single_gvcf):
5053
mt = import_vcf(single_gvcf)
5154
mt._force_count_rows()
@@ -60,14 +63,15 @@ def tmp_and_output_paths(tmp_path):
6063
return (tmp, output)
6164

6265

63-
@benchmark()
66+
@pytest.mark.benchmark()
67+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
6468
def benchmark_vds_combiner_chr22(chr22_gvcfs, tmp_and_output_paths):
6569
parts = hl.eval([hl.parse_locus_interval('chr22:start-end', reference_genome='GRCh38')])
66-
70+
tmp, output = tmp_and_output_paths
6771
combiner = new_combiner(
68-
output_path=str(tmp_and_output_paths[0]),
72+
output_path=str(output),
6973
intervals=parts,
70-
temp_path=str(tmp_and_output_paths[1]),
74+
temp_path=str(tmp),
7175
gvcf_paths=[str(path) for path in chr22_gvcfs],
7276
reference_genome='GRCh38',
7377
branch_factor=16,

hail/python/benchmark/hail/benchmark_linalg.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
1+
import pytest
2+
13
import hail as hl
2-
from benchmark.tools import benchmark
4+
from benchmark.hail.utils import XFail
35

46

5-
@benchmark()
7+
@pytest.mark.benchmark()
8+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
69
def benchmark_block_matrix_nested_multiply(tmp_path):
710
bm = hl.linalg.BlockMatrix.random(8 * 1024, 8 * 1024)
811
bm = bm.checkpoint(str(tmp_path / 'checkpoint.mt'))
912
bm = (bm @ bm) @ bm @ bm @ (bm @ bm)
1013
bm.write(str(tmp_path / 'result.mt'), overwrite=True)
1114

1215

13-
@benchmark()
16+
@pytest.mark.benchmark()
1417
def benchmark_make_ndarray():
1518
ht = hl.utils.range_table(200_000)
1619
ht = ht.annotate(x=hl.nd.array(hl.range(ht.idx)))
1720
ht._force_count()
1821

1922

20-
@benchmark()
23+
@pytest.mark.benchmark()
2124
def benchmark_ndarray_addition():
2225
arr = hl.nd.ones((1024, 1024))
2326
hl.eval(arr + arr)
2427

2528

26-
@benchmark()
29+
@pytest.mark.benchmark()
2730
def benchmark_ndarray_matmul_int64():
2831
arr = hl.nd.arange(1024 * 1024).map(hl.int64).reshape((1024, 1024))
2932
hl.eval(arr @ arr)
3033

3134

32-
@benchmark()
35+
@pytest.mark.benchmark()
3336
def benchmark_ndarray_matmul_float64():
3437
arr = hl.nd.arange(1024 * 1024).map(hl.float64).reshape((1024, 1024))
3538
hl.eval(arr @ arr)
3639

3740

38-
@benchmark()
41+
@pytest.mark.benchmark()
42+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
3943
def benchmark_blockmatrix_write_from_entry_expr_range_mt(tmp_path):
4044
mt = hl.utils.range_matrix_table(40_000, 40_000, n_partitions=4)
4145
path = str(tmp_path / 'result.bm')
4246
hl.linalg.BlockMatrix.write_from_entry_expr(mt.row_idx + mt.col_idx, path)
4347

4448

45-
@benchmark()
49+
@pytest.mark.benchmark()
50+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
4651
def benchmark_blockmatrix_write_from_entry_expr_range_mt_standardize(tmp_path):
4752
mt = hl.utils.range_matrix_table(40_000, 40_000, n_partitions=4)
4853
path = str(tmp_path / 'result.bm')
@@ -51,20 +56,22 @@ def benchmark_blockmatrix_write_from_entry_expr_range_mt_standardize(tmp_path):
5156
)
5257

5358

54-
@benchmark()
59+
@pytest.mark.benchmark()
5560
def benchmark_sum_table_of_ndarrays():
5661
ht = hl.utils.range_table(400).annotate(nd=hl.nd.ones((4096, 4096)))
5762
ht.aggregate(hl.agg.ndarray_sum(ht.nd))
5863

5964

60-
@benchmark()
65+
@pytest.mark.benchmark()
66+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
6167
def benchmark_block_matrix_to_matrix_table_row_major():
6268
mt = hl.utils.range_matrix_table(20_000, 20_000, n_partitions=4)
6369
bm = hl.linalg.BlockMatrix.from_entry_expr(mt.row_idx + mt.col_idx)
6470
bm.to_matrix_table_row_major()._force_count_rows()
6571

6672

67-
@benchmark()
73+
@pytest.mark.benchmark()
74+
@pytest.mark.xfail(raises=TimeoutError, reason=XFail.Timeout)
6875
def benchmark_king(tmp_path):
6976
mt = hl.balding_nichols_model(6, n_variants=10000, n_samples=4096)
7077
path = str(tmp_path / 'result.mt')

0 commit comments

Comments
 (0)