-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class representations for dataset and engine
- Loading branch information
1 parent
89f2e7c
commit ebb9ccd
Showing
10 changed files
with
165 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pathlib import Path | ||
|
||
# Base directory point to the main directory of the project, so all the data | ||
# loaded from files can refer to it as a root directory | ||
BASE_DIRECTORY = Path(__file__).parent.parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
from typing import Text | ||
|
||
from benchmark import BASE_DIRECTORY | ||
|
||
|
||
class Dataset: | ||
|
||
@classmethod | ||
def from_name(cls, name: Text) -> "Dataset": | ||
# TODO: load dataset info from given path | ||
return Dataset(name) | ||
|
||
def __init__(self, name: Text): | ||
self.name = name | ||
|
||
def path(self) -> Path: | ||
return BASE_DIRECTORY / "dataset" / self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import json | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import Text, Optional, Dict, Union | ||
|
||
from benchmark import BASE_DIRECTORY | ||
|
||
|
||
@dataclass | ||
class ContainerConf: | ||
engine: Text | ||
image: Optional[Text] = None | ||
dockerfile: Optional[Text] = None | ||
environment: Optional[Dict[Text, Union[Text, int, bool]]] = None | ||
main: Optional[Text] = None | ||
hostname: Optional[Text] = None | ||
|
||
def dockerfile_path(self, root_dir: Path) -> Path: | ||
""" | ||
Calculates the absolute path to the directory containing the dockerfile, | ||
using given root directory as a base. | ||
:param root_dir: | ||
:return: | ||
""" | ||
return BASE_DIRECTORY / "engine" / self.engine | ||
|
||
|
||
class Engine: | ||
""" | ||
An abstraction over vector database engine. | ||
""" | ||
|
||
@classmethod | ||
def from_name(cls, name: Text) -> "Engine": | ||
container_configs = {} | ||
with open(BASE_DIRECTORY / "engine" / name / "config.json", "r") as fp: | ||
config = json.load(fp) | ||
for container_name, conf in config.items(): | ||
container_configs[container_name] = ContainerConf(engine=name, **conf) | ||
return Engine(container_configs) | ||
|
||
def __init__(self, container_configs: Dict[Text, ContainerConf]): | ||
self.container_configs = container_configs | ||
|
||
def get_config(self, container_name: Text) -> ContainerConf: | ||
return self.container_configs.get(container_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from pathlib import Path | ||
from typing import Text, Union | ||
|
||
PathLike = Union[Text, Path] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.