Skip to content

Commit

Permalink
Add benchmarks for projected correlation (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
camposandro authored Jul 25, 2024
1 parent b18cc97 commit fff9d91
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion benchmarks/asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"HEAD"
],
"install_command": [
"python -m pip install {wheel_file}"
"python -m pip install -r requirements.txt {wheel_file}"
],
"build_command": [
"python -m build --wheel -o {build_cache_dir} {build_dir}"
Expand Down
57 changes: 47 additions & 10 deletions benchmarks/benchmarks.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,53 @@
"""Two sample benchmarks to compute runtime and memory usage.
from pathlib import Path

For more information on writing benchmarks:
https://asv.readthedocs.io/en/stable/writing_benchmarks.html."""
import lsdb
from corrgi.correlation.projected_correlation import ProjectedCorrelation
from corrgi.estimators.davis_peebles_estimator import DavisPeeblesEstimator
from corrgi.estimators.natural_estimator import NaturalEstimator
from gundam import gundam

from corrgi import example_benchmarks
DATA_DIR_NAME = Path(__file__).parent.parent / "tests" / "data" / "hipscat"
GALS_WEIGHT_DIR = str(DATA_DIR_NAME / "pcf_gals_weight")
GALS1_WEIGHT_DIR = str(DATA_DIR_NAME / "pcf_gals1_weight")
RANS_WEIGHT_DIR = str(DATA_DIR_NAME / "pcf_rans_weight")


def time_computation():
"""Time computations are prefixed with 'time'."""
example_benchmarks.runtime_computation()
class ProjectedSuite:
"""Benchmarks for projected correlation"""

timeout = 600 # in seconds

def mem_list():
"""Memory computations are prefixed with 'mem' or 'peakmem'."""
return example_benchmarks.memory_computation()
def setup_cache(self):
"""Initialize suite"""
return (
self.create_params(),
lsdb.read_hipscat(GALS_WEIGHT_DIR),
lsdb.read_hipscat(GALS1_WEIGHT_DIR),
lsdb.read_hipscat(RANS_WEIGHT_DIR),
)

@staticmethod
def create_params():
"""Create the projected params"""
params = gundam.packpars(kind="pcf")
params.nsepp = 28 # Number of bins of projected separation rp
params.seppmin = 0.02 # Minimum rp in Mpc/h
params.dsepp = 0.12 # Bin size of rp (in log space)
params.nsepv = 1 # Number of bins of LOS separation pi
params.dsepv = 40.0 # Bin size of pi (in linear space)
params.omegam = 0.25 # Omega matter
params.omegal = 0.75 # Omega lambda
params.h0 = 100 # Hubble constant [km/s/Mpc]
return params

def time_pcf_natural_estimator(self, cache):
"""Times the Natural estimator for a projected auto-correlation"""
pcf_params, gals_catalog, _, rans_catalog = cache
estimator = NaturalEstimator(ProjectedCorrelation(params=pcf_params, use_weights=True))
estimator.compute_autocorrelation_counts(gals_catalog, rans_catalog)

def time_pccf_davis_peebles_estimator(self, cache):
"""Times the Davis-Peebles estimator for a projected cross-correlation"""
pcf_params, gals_catalog, gals1_catalog, rans_catalog = cache
estimator = DavisPeeblesEstimator(ProjectedCorrelation(params=pcf_params, use_weights=True))
estimator.compute_crosscorrelation_counts(gals_catalog, gals1_catalog, rans_catalog)

0 comments on commit fff9d91

Please sign in to comment.