Skip to content

Commit

Permalink
cleanup python (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
adriandavila authored Dec 31, 2023
1 parent b3ee3cc commit edb7c30
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ExperimentPath(BaseModel):
"""
Experiment and associated files as an object on local filesystem
Path to experiment config in local filesystem
"""

experiment_path: Path
Expand All @@ -20,7 +20,7 @@ def model_post_init(self, __context: Any) -> None:
@classmethod
def construct_experiments(cls, experiment: Path) -> List[Self]:
"""
Construct an list of ExperimentPath instances
Construct an list of ExperimentPath
"""

if experiment.is_file():
Expand All @@ -42,7 +42,7 @@ def from_dir(cls, experiment_dir: Path) -> List[Self]:

def collect_experiments(experiments: Iterable[Path]) -> List[ExperimentPath]:
"""
Given a list of experiment names, find the experiments and collect them into an interable
Given a list of experiment names, find the experiments and collect them
"""
return list(
itertools.chain.from_iterable(
Expand Down
2 changes: 1 addition & 1 deletion ortoa-tee/extras/ortoa/benchmark/infrastucture/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from dataclasses import dataclass
from pathlib import Path
from typing import Any, ClassVar, List, Tuple
from typing import Any, ClassVar, List

import redis
import yaml
Expand Down
13 changes: 2 additions & 11 deletions ortoa-tee/extras/ortoa/benchmark/infrastucture/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from argparse import ArgumentParser
from datetime import datetime
from pathlib import Path
from typing import List, Optional
from typing import List

from ortoa.benchmark.infrastucture.experiment_collection import (
ExperimentPath,
Expand Down Expand Up @@ -66,17 +66,8 @@ def benchmark(
experiment_base: Path,
experiment_names: List[Path],
) -> Stats:
"""Main entrypoint to the benchmarking flow
"""Main entrypoint to the benchmarking flow"""

Args:
experiment_base (Path): _description_
experiment_names (List[Path]): _description_
max_processes (Optional[int], optional): _description_. Defaults to None.
log_errors_in_main_thread (bool, optional): _description_. Defaults to False.
Returns:
Stats: _description_
"""
# Get a path to every experiment file and verify the paths
experiment_paths: List[ExperimentPath] = collect_experiments(experiment_names)

Expand Down
19 changes: 6 additions & 13 deletions ortoa-tee/extras/ortoa/benchmark/infrastucture/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
Any,
Generic,
List,
Optional,
Protocol,
Sequence,
TypeVar,
runtime_checkable,
)

from alive_progress import alive_bar, alive_it
from alive_progress import alive_bar
from pydantic import BaseModel


@runtime_checkable
class JobProtocol(Protocol):
"""
Protocol class (https://peps.python.org/pep-0544/) providing template for jobs runnable by the JobOrchestration class.
To satisfy this protocol, a class must have all the same members and methods (but can have more). A satisfying class
does not have to inherit from the protocol. Other examples of protocols include typing.Sequence
Protocol class providing template for jobs. To satisfy this protocol, a class must have all the same
members and methods, but does not have to inherit from the protocol.
"""

directory: Path
Expand All @@ -42,21 +40,16 @@ def __call__(self) -> None:


class Result(BaseModel, Generic[JobT]):
"""
Result[Job] is a Job and an exception
"""

class Config:
arbitrary_types_allowed = True

job: JobT
result_path: Path
exception: Optional[BaseException]


class JobOrchestration(BaseModel, Generic[JobT]):
"""
Given a sequence of jobs, schedule the jobs in a process pool, managing job cancellation and progress reporting
Given a sequence of jobs, schedule the jobs and report progress
"""

class Config:
Expand Down Expand Up @@ -86,10 +79,10 @@ def run_sequential(self) -> List[Result[JobT]]:

# save the results
results.append(
Result(job=job, result_path=job.client_flags.output, exception=None)
Result(job=job, result_path=job.client_flags.output)
)

bar() # increment the progress bar status
bar() # update the progress bar

bar.text("Benchmark complete!")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _parse_result(cls, job: ClientJob, results_file: Path) -> pd.DataFrame:

@classmethod
def from_results(cls, results: List[Result]) -> Self:
"""Given an iterable of results, generate statistics on those results"""
"""Generate statistics from the results"""
per_job_result = [
cls._parse_result(job=result.job, results_file=result.result_path)
for result in results
Expand Down
1 change: 0 additions & 1 deletion ortoa-tee/extras/ortoa/benchmark/interface/experiment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import itertools
from pathlib import Path
from typing import Any, Generic, List, Literal, Optional, TypeVar, Union

Expand Down

0 comments on commit edb7c30

Please sign in to comment.