Skip to content

Issue A2: Performance Optimization — Accelerate accorr Metric #10

@Ramdam17

Description

@Ramdam17

Description:

Optimize the accorr (adjusted circular correlation) metric computation, which is currently a performance bottleneck.

Context:
The accorr metric in analyses.py is slow for large datasets. Users have reported long computation times that limit practical use. We need to explore optimization strategies.

Current implementation location: hypyp/analyses.py

Optimization strategies to explore:

  1. Pre-computing

    • Identify repeated computations that can be cached
    • Pre-compute frequency band signals once, reuse across metrics
  2. Parallelization

    • Use joblib for parallel computation across epochs/channels
    • Consider numba JIT compilation for inner loops
    • Explore numpy vectorization improvements
  3. Algorithm optimization

    • Profile current code to find bottlenecks
    • Review circular statistics libraries (e.g., pycircstat, astropy.stats)
    • Consider approximations for large datasets

Tasks:

  • Profile current accorr implementation (use cProfile or line_profiler)
  • Identify top 3 bottlenecks
  • Implement at least one optimization strategy
  • Benchmark: before vs. after (varying data sizes)
  • Ensure numerical accuracy is preserved (compare outputs)
  • Add tests for optimized code

Acceptance Criteria:

  • Profiling report identifying bottlenecks
  • At least 2x speedup on benchmark dataset
  • Benchmark script included in PR
  • Unit tests pass (numerical accuracy preserved)
  • Documentation of optimization approach

Benchmark template:

import time
import numpy as np
from hypyp import analyses

# Generate test data of varying sizes
sizes = [(10, 32, 1000), (50, 64, 2000), (100, 64, 5000)]

for n_epochs, n_channels, n_samples in sizes:
    data = generate_test_data(n_epochs, n_channels, n_samples)
    
    start = time.time()
    result = analyses.compute_sync(data, metric='accorr')
    elapsed = time.time() - start
    
    print(f"Size {n_epochs}x{n_channels}x{n_samples}: {elapsed:.2f}s")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions