Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into sqaaas-code
Browse files Browse the repository at this point in the history
  • Loading branch information
orviz committed Nov 20, 2023
2 parents f244b60 + 1299b0c commit 5fa296b
Show file tree
Hide file tree
Showing 26 changed files with 2,650 additions and 13 deletions.
131 changes: 131 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
**/TODO
**/mamba*
pl-training.yml
.vscode

# Project folders/files
# use-cases
workflows
tests
CHANGELOG

# Docs
docs

# Data
**/MNIST
**/*-predictions/
**/*-data/
**/*.tar.gz
**/exp_data

# Logs
**/logs
**/lightning_logs
**/mlruns
**/.logs
**/mllogs
**/nohup*
**/*.out
**/*.err
**/checkpoints/
**/*_logs
**/tmp*
**/.tmp*

# Markdown
**/*.md

# Custom envs
**/.venv*

# Git
.git
.gitignore
.github

# CI
.codeclimate.yml
.travis.yml
.taskcluster.yml

# Docker
docker-compose.yml
.docker
.dockerignore
Dockerfile

# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
**/eggs/
lib/
lib64/
parts/
sdist/
var/
**/*.egg-info/
**/.installed.cfg
**/*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Virtual environment
.env/
.venv/
venv/

# PyCharm
.idea

# Python mode for VIM
.ropeproject
*/.ropeproject
*/*/.ropeproject
*/*/*/.ropeproject

# Vim swap files
*.swp
*/*.swp
*/*/*.swp
*/*/*/*.swp
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*_logs
exp_data/
TODO
/data
nohup*
Expand All @@ -13,6 +15,10 @@ mllogs
*.err
.logs/
pl-training.yml
*-predictions/
*-data/
*.pth
*.tar.gz

# Custom envs
.venv*
Expand Down
69 changes: 59 additions & 10 deletions src/itwinai/components.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from __future__ import annotations
from .cluster import ClusterEnvironment
from typing import Iterable, Dict, Any, Optional, Tuple
from typing import Iterable, Dict, Any, Optional, Tuple, Union
from abc import ABCMeta, abstractmethod
import time
# import logging
# from logging import Logger as PythonLogger

from .cluster import ClusterEnvironment
from .types import ModelML, DatasetML
from .serialization import ModelLoader


class Executable(metaclass=ABCMeta):
"""Base Executable class.
Expand Down Expand Up @@ -136,6 +139,7 @@ def _printout(self, msg: str):


class Trainer(Executable):
"""Trains a machine learning model."""
@abstractmethod
def train(self, *args, **kwargs):
pass
Expand All @@ -149,6 +153,57 @@ def load_state(self):
pass


class Predictor(Executable):
"""Applies a pre-trained machine learning model to unseen data."""

model: ModelML

def __init__(
self,
model: Union[ModelML, ModelLoader],
name: Optional[str] = None,
**kwargs
) -> None:
super().__init__(name, **kwargs)
self.model = model() if isinstance(model, ModelLoader) else model

def execute(
self,
predict_dataset: DatasetML,
config: Optional[Dict] = None,
) -> Tuple[Optional[Tuple], Optional[Dict]]:
""""Execute some operations.
Args:
predict_dataset (DatasetML): dataset object for inference.
config (Dict, optional): key-value configuration.
Defaults to None.
Returns:
Tuple[Optional[Tuple], Optional[Dict]]: tuple structured as
(results, config).
"""
return self.predict(predict_dataset), config

@abstractmethod
def predict(
self,
predict_dataset: DatasetML,
model: Optional[ModelML] = None
) -> Iterable[Any]:
"""Applies a machine learning model on a dataset of samples.
Args:
predict_dataset (DatasetML): dataset for inference.
model (Optional[ModelML], optional): overrides the internal model,
if given. Defaults to None.
Returns:
Iterable[Any]: predictions with the same cardinality of the
input dataset.
"""


class DataGetter(Executable):
@abstractmethod
def load(self, *args, **kwargs):
Expand All @@ -167,18 +222,12 @@ def preproc(self, *args, **kwargs):
# pass


class Evaluator(Executable):
class Saver(Executable):
@abstractmethod
def evaluate(self, *args, **kwargs):
def save(self, *args, **kwargs):
pass


# class Saver(Executable):
# @abstractmethod
# def save(self, *args, **kwargs):
# pass


class Executor(Executable):
"""Sets-up and executes a sequence of Executable steps."""

Expand Down
2 changes: 1 addition & 1 deletion src/itwinai/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import wandb
import mlflow
import mlflow.keras
# import mlflow.keras

BASE_EXP_NAME: str = 'unk_experiment'

Expand Down
14 changes: 14 additions & 0 deletions src/itwinai/serialization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .types import ModelML
import abc


class ModelLoader(abc.ABC):
"""Loads a machine learning model from somewhere."""

def __init__(self, model_uri: str) -> None:
super().__init__()
self.model_uri = model_uri

@abc.abstractmethod
def __call__(self) -> ModelML:
"""Loads model from model URI."""
Loading

0 comments on commit 5fa296b

Please sign in to comment.