Skip to content

Commit

Permalink
Add basic typing
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Sep 29, 2024
1 parent 739d41f commit c1a29db
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
15 changes: 12 additions & 3 deletions rebench/model/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from typing import TYPE_CHECKING

from . import value_with_optional_details
from .exp_run_details import ExpRunDetails
from .exp_variables import ExpVariables

if TYPE_CHECKING:
from .benchmark_suite import BenchmarkSuite
from .run_id import RunId
from ..interop.adapter import GaugeAdapter
from ..persistence import DataStore


class Benchmark(object):

Expand All @@ -46,8 +54,9 @@ def compile(cls, bench, suite, data_store):
variables, extra_args, run_details, codespeed_name,
data_store)

def __init__(self, name, command, gauge_adapter, suite, variables, extra_args,
run_details, codespeed_name, data_store):
def __init__(self, name: str, command: str, gauge_adapter: "GaugeAdapter",
suite: "BenchmarkSuite", variables: str, extra_args: str,
run_details: "ExpRunDetails", codespeed_name: str, data_store: "DataStore"):
assert run_details is None or isinstance(run_details, ExpRunDetails)
self.name = name

Expand All @@ -70,7 +79,7 @@ def __init__(self, name, command, gauge_adapter, suite, variables, extra_args,
self.variables = variables

# the compiled runs, these might be shared with other benchmarks/suites
self._runs = set()
self._runs: set[RunId] = set()

data_store.register_config(self)

Expand Down
16 changes: 13 additions & 3 deletions rebench/model/run_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,34 @@
import os
import re
import shlex
from typing import TYPE_CHECKING

from .benchmark import Benchmark
from .termination_check import TerminationCheck
from ..output import UIError
from ..statistics import StatisticProperties, SampleCounter

if TYPE_CHECKING:
from ..persistence import AbstractPersistence
from ..reporter import Reporter
from ..statistics import WithSamples


class RunId(object):

def __init__(self, benchmark, cores, input_size, var_value, tag):
def __init__(self, benchmark: Benchmark, cores : str,
input_size: str, var_value: str, tag: str):
self.benchmark = benchmark
self.cores = cores
self.input_size = input_size
self.var_value = var_value
self.tag = tag

self._reporters = set()
self._persistence = set()
self._reporters: set[Reporter] = set()
self._persistence: set[AbstractPersistence] = set()

self.statistics: WithSamples

if self.is_profiling():
self.statistics = SampleCounter()
else:
Expand Down
7 changes: 6 additions & 1 deletion rebench/model/termination_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .run_id import RunId
from ..ui import UI


class TerminationCheck(object):
def __init__(self, run_id, ui):
def __init__(self, run_id: "RunId", ui: "UI"):
self._run_id = run_id
self.ui = ui
self._consecutive_erroneous_executions = 0
Expand Down
6 changes: 3 additions & 3 deletions rebench/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def register_config(self, cfg):
return cfg


class _AbstractPersistence(object):
class AbstractPersistence(object):

def load_data(self, runs, discard_run_data):
"""
Expand All @@ -135,15 +135,15 @@ def close(self):
"""Needs to be implemented by subclass"""


class _ConcretePersistence(_AbstractPersistence):
class _ConcretePersistence(AbstractPersistence):

def __init__(self, data_store, ui):
self._data_store = data_store
self._start_time = None
self.ui = ui


class _CompositePersistence(_AbstractPersistence):
class _CompositePersistence(AbstractPersistence):

def __init__(self, file_pers, rebench_db):
self._file = file_pers
Expand Down
9 changes: 7 additions & 2 deletions rebench/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
import math


class SampleCounter(object):
class WithSamples(object):
def add_sample(self, _sample):
pass


class SampleCounter(WithSamples):

def __init__(self):
self.num_samples = 0
Expand All @@ -30,7 +35,7 @@ def add_sample(self, _sample):
self.num_samples += 1


class StatisticProperties(object):
class StatisticProperties(WithSamples):
"""
The class maintains running statistics for the added data points.
Data points can be added one by one, or as lists of values.
Expand Down

0 comments on commit c1a29db

Please sign in to comment.