-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from fgcz/main
Release app_runner 0.0.9
- Loading branch information
Showing
25 changed files
with
885 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ bfabric/scripts/query_result.txt | |
build/ | ||
dist/ | ||
site/ | ||
feats/ | ||
_build/ |
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 @@ | ||
# App Definition Design | ||
|
||
## Goals | ||
|
||
- Centralized configuration for all app versions so that if necessary adaptions to the system integration can be done in one place easily. | ||
|
||
## Remarks | ||
|
||
- The app ID is not part of the app specification, since the same app specification can be used for multiple B-Fabric apps. | ||
|
||
## Open question | ||
|
||
## Future possibilities | ||
|
||
- Version ranges: Maybe we could use semver, but it would need to be a standardized flavor thereof. | ||
- Allow to provide a folder (or set of YAML files) with multiple app definitions, to be pooled together. | ||
If there are any version conflicts an error should be raised. | ||
There probably should be a tool to check the available versions easily. |
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 @@ | ||
## Open questions | ||
|
||
- Inter-chunk dependencies (assuming some chunks are different from others) | ||
- Should chunks be standardized somehow | ||
- How to transfer a chunk (which is a folder) reasonably across different scheduler systems? -> tar or shared folder (needs config...) | ||
- Ideally: first version allows relatively flexible slurm configuration | ||
|
||
## Future possibilities | ||
|
||
- The initial version is concerned about submitting one job to a (SLURM) scheduler. However, at a later time multi-node | ||
jobs could be introduced by this job submitting then further jobs to the scheduler. Ideally, it could reuse the same | ||
scheduling interface code as is used for the single-node jobs. | ||
- Internally, we could prepare by making the app runner code that executes the individual chunks more generic. | ||
- Parallel execution of chunks could be introduced. This is actually very similar to the previous point. |
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" | |
[project] | ||
name = "app_runner" | ||
description = "Application runner for B-Fabric apps" | ||
version = "0.0.8" | ||
version = "0.0.9" | ||
license = { text = "GPL-3.0" } | ||
authors = [ | ||
{name = "Leonardo Schwarz", email = "[email protected]"}, | ||
|
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,50 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from bfabric.experimental.workunit_definition import WorkunitDefinition | ||
|
||
from app_runner.specs.app.app_spec import AppSpec | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
from bfabric import Bfabric | ||
from app_runner.specs.app.app_version import AppVersion | ||
|
||
|
||
def resolve_app(versions: AppSpec, workunit_definition: WorkunitDefinition) -> AppVersion: | ||
"""Resolves the app version to use for the provided workunit definition.""" | ||
# TODO this should be more generic in the future about the key for the app version (should be handled in AppSpec) | ||
# TODO logic to define "latest" version (should also be handled in AppSpec) | ||
if "application_version" not in workunit_definition.execution.raw_parameters: | ||
raise ValueError("The workunit definition does not contain an application version.") | ||
app_version = workunit_definition.execution.raw_parameters["application_version"] | ||
# TODO graceful handling of invalid versions | ||
return versions[app_version] | ||
|
||
|
||
def load_workunit_information( | ||
app_spec: Path, client: Bfabric, work_dir: Path, workunit_ref: int | Path | ||
) -> tuple[AppVersion, Path]: | ||
"""Loads the app version and workunit definition from the provided app spec and workunit reference. | ||
:param app_spec: Path to the app spec file. | ||
:param client: The B-Fabric client to use for resolving the workunit. | ||
:param work_dir: Path to the work directory. | ||
:param workunit_ref: Reference to the workunit (ID or YAML file path). | ||
:return app_version: The app version to use. | ||
:return workunit_ref: Path to the workunit definition file. Can be used to reference the workunit in further | ||
steps to avoid unnecessary B-Fabric lookups. (If the workunit_ref was already a path, it will be returned as is, | ||
otherwise the file will be created in the work directory.) | ||
""" | ||
workunit_definition_file = work_dir / "workunit_definition.yml" | ||
workunit_definition = WorkunitDefinition.from_ref(workunit_ref, client, cache_file=workunit_definition_file) | ||
app_versions = AppSpec.load_yaml( | ||
app_spec, | ||
app_id=workunit_definition.registration.application_id, | ||
app_name=workunit_definition.registration.application_name, | ||
) | ||
if isinstance(workunit_ref, int): | ||
workunit_ref = workunit_definition_file | ||
app_version = resolve_app(versions=app_versions, workunit_definition=workunit_definition) | ||
return app_version, workunit_ref |
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
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
Empty file.
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,54 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import yaml | ||
from pydantic import BaseModel | ||
|
||
from app_runner.specs.app.app_version import AppVersion, AppVersionMultiTemplate # noqa: TCH001 | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
|
||
class BfabricAppSpec(BaseModel): | ||
"""Contains the app specification information that is relevant to bfabric...""" | ||
|
||
# TODO unclear if it should be kept | ||
app_runner: str | ||
|
||
|
||
class AppSpecTemplate(BaseModel): | ||
# TODO consider whether to reintroduce | ||
# bfabric: BfabricAppSpec | ||
versions: list[AppVersionMultiTemplate] | ||
|
||
def evaluate(self, app_id: str, app_name: str) -> AppSpec: | ||
"""Evaluates the template to a concrete ``AppSpec`` instance.""" | ||
versions_templates = [expanded for version in self.versions for expanded in version.expand_versions()] | ||
versions = [template.evaluate(app_id=app_id, app_name=app_name) for template in versions_templates] | ||
return AppSpec.model_validate({"versions": versions}) | ||
|
||
|
||
class AppSpec(BaseModel): | ||
"""Parsed app versions from the app spec file.""" | ||
|
||
versions: list[AppVersion] | ||
|
||
@classmethod | ||
def load_yaml(cls, app_yaml: Path, app_id: int | str, app_name: str) -> AppSpec: | ||
"""Loads the app versions from the provided YAML file and evaluates the templates.""" | ||
app_spec_file = AppSpecTemplate.model_validate(yaml.safe_load(app_yaml.read_text())) | ||
return app_spec_file.evaluate(app_id=str(app_id), app_name=str(app_name)) | ||
|
||
@property | ||
def available_versions(self) -> set[str]: | ||
"""The available versions of the app.""" | ||
return {version.version for version in self.versions} | ||
|
||
def __getitem__(self, version: str) -> AppVersion | None: | ||
"""Returns the app version with the provided version number or None if it does not exist.""" | ||
for app_version in self.versions: | ||
if app_version.version == version: | ||
return app_version | ||
return None |
Oops, something went wrong.