Skip to content

Commit

Permalink
app runner version
Browse files Browse the repository at this point in the history
  • Loading branch information
leoschwarz committed Jan 20, 2025
1 parent 7e9549c commit d6b66a9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
class WorkunitWrapperData(BaseModel):
workunit_definition: WorkunitDefinition
app_version: AppVersion
app_runner_version: str
5 changes: 4 additions & 1 deletion app_runner/src/app_runner/bfabric_app/wrapper_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def get_data(self) -> WorkunitWrapperData:
app = self._workunit.application
app_spec = app_spec_template.evaluate(app_id=str(app.id), app_name=app["name"])
app_version = resolve_app(versions=app_spec, workunit_definition=workunit_definition)
return WorkunitWrapperData(workunit_definition=workunit_definition, app_version=app_version)
app_runner_version = app_spec.bfabric.app_runner
return WorkunitWrapperData(
workunit_definition=workunit_definition, app_version=app_version, app_runner_version=app_runner_version
)

def run(self) -> None:
data = self.get_data()
Expand Down
7 changes: 4 additions & 3 deletions app_runner/src/app_runner/specs/app/app_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ class BfabricAppSpec(BaseModel):


class AppSpecTemplate(BaseModel):
# TODO consider whether to reintroduce
# bfabric: BfabricAppSpec
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})
# TODO add interpolation for bfabric config
return AppSpec.model_validate({"versions": versions, "bfabric": self.bfabric})


class AppSpec(BaseModel):
"""Parsed app versions from the app spec file."""

bfabric: BfabricAppSpec
versions: list[AppVersion]

@classmethod
Expand Down
19 changes: 14 additions & 5 deletions app_runner/src/app_runner/submitter/slurm_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class SlurmSubmitterUserParams(BaseModel):
{workunit_definition_yml}
YAML
bfabric-app-runner app run --app-spec app_version.yml --workunit-ref workunit_definition.yml --work-dir "$(pwd)"
"""
set -euxo pipefail
app_runner="uv run --with app_runner@git+https://github.com/fgcz/bfabricPy.git@{app_runner_version}#egg=app_runner&subdirectory=app_runner bfabric-app-runner"
$app_runner app run --app-spec app_version.yml --workunit-ref workunit_definition.yml --work-dir "$(pwd)"
""" # noqa: E501


class SlurmSubmitter:
Expand All @@ -63,15 +65,22 @@ def _compose_script(self, main_command: str, specific_params: dict[str, str | No
script_header = self._compose_script_header(concrete_params)
return f"{script_header}\n\n{main_command}"

def _interpolate_main(self, app_version_yml: str, workunit_definition_yml: str) -> str:
def _interpolate_main(self, app_version_yml: str, workunit_definition_yml: str, app_runner_version: str) -> str:
return _MAIN_BASH_TEMPLATE.format(
app_version_yml=app_version_yml, workunit_definition_yml=workunit_definition_yml
app_version_yml=app_version_yml,
workunit_definition_yml=workunit_definition_yml,
app_runner_version=app_runner_version,
)

def _get_main_command(self, workunit_wrapper_data: WorkunitWrapperData) -> str:
app_version_yml = yaml.safe_dump(workunit_wrapper_data.app_version.model_dump(mode="json"))
workunit_definition_yml = yaml.safe_dump(workunit_wrapper_data.workunit_definition.model_dump(mode="json"))
return self._interpolate_main(app_version_yml=app_version_yml, workunit_definition_yml=workunit_definition_yml)
app_runner_version = workunit_wrapper_data.app_runner_version
return self._interpolate_main(
app_version_yml=app_version_yml,
workunit_definition_yml=workunit_definition_yml,
app_runner_version=app_runner_version,
)

def submit(self, workunit_wrapper_data: WorkunitWrapperData, specific_params: dict[str, str | None]) -> None:
# Determine the script path
Expand Down

0 comments on commit d6b66a9

Please sign in to comment.