-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified workflow configuration (#108)
* Add SQAaaS dynamic badge for dev branch (#104) * Add SQAaaS dynamic badge * Upgrade to sqaaas-assessment-action@v2 * Add draft example * UPDATE credits field * ADD docs * REFACTOR components and pipeline code * UPDATE docstring * UPDATE mnist torch uc * ADD config file parser draft * ADD itwinaiCLI and ConfigParser * ADD docs * ADD pipeline parser and serializer plus tests * UPDATE docs * ADD adapter component and tests (incl parser) * ADD splitter component, improve pipeline, tests * UPDATE test * REMOVE todos * ADD component tests * ADD serializer tests * FIX linter * ADD basic workflow tutorial * ADD basic intermediate tutorial * ADD advanced tutorial * UPDATE advanced tutorial * UPDATE use cases * UPDATE save parameters * FIX linter * FIX cyclones use case workflow --------- Co-authored-by: orviz <[email protected]>
- Loading branch information
Showing
62 changed files
with
2,784 additions
and
895 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
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,9 @@ | ||
server: | ||
class_path: mycode.ServerOptions | ||
init_args: | ||
host: localhost | ||
port: 80 | ||
client: | ||
class_path: mycode.ClientOptions | ||
init_args: | ||
url: http://${server.init_args.host}:${server.init_args.port}/ |
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,14 @@ | ||
pipeline: | ||
class_path: itwinai.pipeline.Pipeline | ||
steps: [server, client] | ||
|
||
server: | ||
class_path: mycode.ServerOptions | ||
init_args: | ||
host: localhost | ||
port: 80 | ||
|
||
client: | ||
class_path: mycode.ClientOptions | ||
init_args: | ||
url: http://${server.init_args.host}:${server.init_args.port}/ |
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,29 @@ | ||
""" | ||
>>> python itwinaicli.py --config itwinai-conf.yaml --help | ||
>>> python itwinaicli.py --config itwinai-conf.yaml --server.port 333 | ||
""" | ||
|
||
|
||
from itwinai.parser import ConfigParser2 | ||
from itwinai.parser import ItwinaiCLI | ||
|
||
cli = ItwinaiCLI() | ||
print(cli.pipeline) | ||
print(cli.pipeline.steps) | ||
print(cli.pipeline.steps['server'].port) | ||
|
||
|
||
parser = ConfigParser2( | ||
config='itwinai-conf.yaml', | ||
override_keys={ | ||
'server.init_args.port': 777 | ||
} | ||
) | ||
pipeline = parser.parse_pipeline() | ||
print(pipeline) | ||
print(pipeline.steps) | ||
print(pipeline.steps['server'].port) | ||
|
||
server = parser.parse_step('server') | ||
print(server) | ||
print(server.port) |
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,35 @@ | ||
# from dataclasses import dataclass | ||
from itwinai.components import BaseComponent | ||
|
||
|
||
class ServerOptions(BaseComponent): | ||
host: str | ||
port: int | ||
|
||
def __init__(self, host: str, port: int) -> None: | ||
self.host = host | ||
self.port = port | ||
|
||
def execute(): | ||
... | ||
|
||
|
||
class ClientOptions(BaseComponent): | ||
url: str | ||
|
||
def __init__(self, url: str) -> None: | ||
self.url = url | ||
|
||
def execute(): | ||
... | ||
|
||
|
||
class ServerOptions2(BaseComponent): | ||
host: str | ||
port: int | ||
|
||
def __init__(self, client: ClientOptions) -> None: | ||
self.client = client | ||
|
||
def execute(): | ||
... |
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 @@ | ||
""" | ||
Provide functionalities to manage configuration files, including parsing, | ||
execution, and dynamic override of fields. | ||
""" | ||
|
||
from typing import Any | ||
from jsonargparse import ArgumentParser, ActionConfigFile, Namespace | ||
|
||
from .components import BaseComponent | ||
|
||
|
||
class ItwinaiCLI: | ||
_parser: ArgumentParser | ||
pipeline: BaseComponent | ||
|
||
def __init__( | ||
self, | ||
pipeline_nested_key: str = "pipeline", | ||
args: Any = None, | ||
parser_mode: str = "omegaconf" | ||
) -> None: | ||
self.pipeline_nested_key = pipeline_nested_key | ||
self.args = args | ||
self.parser_mode = parser_mode | ||
self._init_parser() | ||
self._parse_args() | ||
pipeline_inst = self._parser.instantiate_classes(self._config) | ||
self.pipeline = pipeline_inst[self.pipeline_nested_key] | ||
|
||
def _init_parser(self): | ||
self._parser = ArgumentParser(parser_mode=self.parser_mode) | ||
self._parser.add_argument( | ||
"-c", "--config", action=ActionConfigFile, | ||
required=True, | ||
help="Path to a configuration file in json or yaml format." | ||
) | ||
self._parser.add_subclass_arguments( | ||
baseclass=BaseComponent, | ||
nested_key=self.pipeline_nested_key | ||
) | ||
|
||
def _parse_args(self): | ||
if isinstance(self.args, (dict, Namespace)): | ||
self._config = self._parser.parse_object(self.args) | ||
else: | ||
self._config = self._parser.parse_args(self.args) |
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,29 @@ | ||
""" | ||
Example of dynamic override of config files with (sub)class arguments, | ||
and variable interpolation with omegaconf. | ||
Run with: | ||
>>> python parser.py | ||
Or (after clearing the arguments in parse_args(...)): | ||
>>> python parser.py --config example.yaml --server.port 212 | ||
See the help page of each class: | ||
>>> python parser.py --server.help mycode.ServerOptions | ||
""" | ||
|
||
from jsonargparse import ArgumentParser, ActionConfigFile | ||
from mycode import ServerOptions, ClientOptions | ||
|
||
if __name__ == "__main__": | ||
parser = ArgumentParser(parser_mode="omegaconf") | ||
parser.add_subclass_arguments(ServerOptions, "server") | ||
parser.add_subclass_arguments(ClientOptions, "client") | ||
parser.add_argument("--config", action=ActionConfigFile) | ||
|
||
# Example of dynamic CLI override | ||
# cfg = parser.parse_args(["--config=example.yaml", "--server.port=212"]) | ||
cfg = parser.parse_args() | ||
cfg = parser.instantiate_classes(cfg) | ||
print(cfg.client) | ||
print(cfg.client.url) | ||
print(cfg.server.port) |
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,53 @@ | ||
# AI workflow metadata/header. | ||
# They are optional and easily extensible in the future. | ||
version: 0.0.1 | ||
name: Experiment name | ||
description: This is a textual description | ||
credits: | ||
- author1 | ||
- author2 | ||
|
||
# Provide a unified place where this *template* can be configured. | ||
# Variables which can be overridden at runtime as env vars, e.g.: | ||
# - Execution environment details (e.g., path in container vs. in laptop, MLFlow tracking URI) | ||
# - Tunable parameters (e.g., learning rate) | ||
# - Intrinsically dynamic values (e.g., MLFLow run ID is a random value) | ||
# These variables are interpolated with OmegaConf. | ||
vars: | ||
images_dataset_path: some/path/disk | ||
mlflow_tracking_uri: http://localhost:5000 | ||
training_lr: 0.001 | ||
|
||
# Runner-independent workflow steps. | ||
# Each step is designed to be minimal, but easily extensible | ||
# to accommodate future needs by adding new fields. | ||
# The only required field is 'command'. New fields can be added | ||
# to support future workflow executors. | ||
steps: | ||
preprocessing-step: | ||
command: | ||
class_path: itwinai.torch.Preprocessor | ||
init_args: | ||
save_path: ${vars.images_dataset_path} | ||
after: null | ||
env: null | ||
|
||
training-step: | ||
command: | ||
class_path: itwinai.torch.Trainer | ||
init_args: | ||
lr: ${vars.training_lr} | ||
tracking_uri: ${vars.mlflow_tracking_uri} | ||
after: preprocessing-step | ||
env: null | ||
|
||
sth_step: | ||
command: python inference.py -p pipeline.yaml | ||
after: [preprocessing-step, training-step] | ||
env: docker+ghcr.io/intertwin-eu/itwinai:training-0.0.1 | ||
|
||
sth_step2: | ||
command: python train.py -p pipeline.yaml | ||
after: null | ||
env: conda+path/to/my/local/env | ||
|
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
Oops, something went wrong.