Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion regression_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from datetime import datetime
from pathlib import Path
from typing import Any, Dict, List, Optional, Tuple
import numpy as np

import yaml
from userbenchmark.utils import (
Expand Down Expand Up @@ -63,6 +64,12 @@ def get_default_output_path(bm_name: str) -> str:
)
return os.path.join(output_path, fname)

def compute_quantiles(values: List[float]) -> Dict[str, float]:
return {
"q25": float(np.quantile(values, 0.25)),
"q50": float(np.quantile(values, 0.50)),
"q75": float(np.quantile(values, 0.75)),
}

def generate_regression_result(
control: Dict[str, Any], treatment: Dict[str, Any]
Expand All @@ -86,18 +93,23 @@ def _call_userbenchmark_detector(
detector = importlib.import_module(
f"userbenchmark.fb.{bm_name}.regression_detector"
).run

# Process control and treatment to include only shared keys
filtered_control_metrics = {}
control_only_metrics = {}
filtered_treatment_metrics = {}
treatment_only_metrics = {}
for control_name, control_metric in control["metrics"].items():
if control_name in treatment["metrics"]:
if "times" in control_metric and isinstance(control_metric["times"], list):
control_metric.update(compute_quantiles(control_metric["times"]))
filtered_control_metrics[control_name] = control_metric
else:
control_only_metrics[control_name] = control_metric
for treatment_name, treatment_metric in treatment["metrics"].items():
if treatment_name in control["metrics"]:
if "times" in treatment_metric and isinstance(treatment_metric["times"], list):
treatment_metric.update(compute_quantiles(treatment_metric["times"]))
filtered_treatment_metrics[treatment_name] = treatment_metric
else:
treatment_only_metrics[treatment_name] = treatment_metric
Expand Down Expand Up @@ -332,7 +344,7 @@ def get_metrics_by_date(
with open(args.control, "r") as cfptr:
control = json.load(cfptr)
with open(args.treatment, "r") as tfptr:
treatment = json.load(tfptr)
treatment = json.load(cfptr)
output_path = (
args.output if args.output else get_default_output_path(control["name"])
)
Expand Down