Benchmarking in hpfracc โ layout, coupling, and maintenance๏
This note complements CONTRIBUTING.md, ALGORITHMS_ARCHITECTURE.md, ANALYTICS_ARCHITECTURE.md, SPECIAL_ARCHITECTURE.md, UTILS_ARCHITECTURE.md, VALIDATION_ARCHITECTURE.md, and SOLVERS_ARCHITECTURE.md. It maps where benchmarks live, how they differ, naming pitfalls, and lightweight import rules.
1. Three different โbenchmarkโ surfaces๏
Location |
Role |
Typical entry |
|---|---|---|
|
General numerical benchmarks (array sizes, synthetic test functions, timing/memory, optional plots + CSV export). |
|
|
Torch-heavy ML layer benchmarks ( |
Canonical: |
|
Validation-oriented |
Used by validation workflows; not the same API as |
Repo root |
Standalone scripts (e.g. intelligent backend timing). |
Run as scripts; not necessarily imported as a package. |
2. Naming and package surface๏
Numerical (
benchmark_runner.py):BenchmarkConfig,BenchmarkResult,BenchmarkRunnerโ these names are only for the numerical runner.ML (
ml_performance_benchmark.py): useMLBenchmarkConfigandMLBenchmarkResultfor new code. The old namesBenchmarkConfig/BenchmarkResultin this module remain as deprecated subclasses (same constructor shape,DeprecationWarningin__post_init__).hpfracc/benchmarks/__init__.py: imports the numerical runner eagerly; exposesMLPerformanceBenchmark,MLBenchmarkConfig,MLBenchmarkResultvia__getattr__soimport hpfracc.benchmarksdoes not load PyTorch until you touch an ML symbol.validation.method_benchmarks.BenchmarkResultis a third, unrelated dataclass (includesBenchmarkType,success, etc.).
3. Dependencies and import coupling๏
benchmark_runner.py
Core: NumPy, psutil, json, logging (no root
logging.basicConfig; configure logging in applications or scripts).Matplotlib is imported only inside
_plot_performance_results,_plot_accuracy_results, and_plot_memory_resultssoimport hpfracc.benchmarks.benchmark_runnerdoes not load pyplot for CSV-only or non-plotting paths.pandas was already lazy inside the CSV export helper.
ml_performance_benchmark.py
Eager: torch, numpy, psutil, and hpfracc.ml components (heavy).
Matplotlib / seaborn are imported only inside
_generate_visualizations.
validation/benchmarks.py
NumPy, psutil, warnings โ no matplotlib at module level.
4. Outputs and risks๏
Risk |
Mitigation |
|---|---|
Default |
Set |
Name collision across numerical vs ML |
Use |
ML benchmark cost |
Full |
5. Tests๏
tests/test_benchmarks/โ smoke tests: subprocess import guard (matplotlib not loaded forbenchmark_runner),BenchmarkRunnerwith tempoutput_dir, JSON/CSVsave_results, lazy ML exports onhpfracc.benchmarks, and ML canonical vs deprecatedDeprecationWarningbehaviour (skipped if PyTorch is unavailable).
When extending tests:
Prefer temp
output_dir,MPLBACKEND=Agg, and do not patchbuiltins.openglobally alongside matplotlib (see ANALYTICS_ARCHITECTURE.md ยง7 โ same font-manager footgun).
python -m pytest tests/test_benchmarks/ -q