File size: 845 Bytes
b48ae75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Versioned sampling contract, shared by native configuration and evaluator."""


def validate_profiling(value):
    if not isinstance(value, dict) or set(value) != {"total_runs", "warmup_runs", "statistic"}:
        raise ValueError("profiling requires exactly total_runs, warmup_runs, statistic")
    total, warmup = value["total_runs"], value["warmup_runs"]
    if type(total) is not int or total < 1:
        raise ValueError("profiling.total_runs must be a positive integer")
    if type(warmup) is not int or not 0 <= warmup < total:
        raise ValueError("profiling.warmup_runs must be an integer in [0, total_runs)")
    if value["statistic"] != "mean":
        raise ValueError("profiling.statistic must be mean")
    return dict(value)


def default_profiling():
    return {"total_runs": 8, "warmup_runs": 3, "statistic": "mean"}