Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions generate_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@
"class": "JobSelection",
"resource_filename": "selection",
},
{
"schema": "TemplateSoftwareSchema",
"schema_filename": "task_definition_template",
"rest_name": None,
"additional_fields": [],
"class": "TemplateSoftware",
"resource_filename": "task_definition_template",
},
{
"schema": "TemplatePropertySchema",
"schema_filename": "task_definition_template",
Expand Down
33 changes: 30 additions & 3 deletions src/ansys/hps/client/jms/resource/task_definition_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,35 @@
TemplateOutputFileSchema,
TemplatePropertySchema,
TemplateResourceRequirementsSchema,
TemplateSoftwareSchema,
)
from .task_definition import HpcResources, Software, WorkerContext
from .task_definition import HpcResources, WorkerContext


class TemplateSoftware(Object):
"""Provides the template software resource.

Parameters
----------
name : str
Name of the app.
versions : list, optional
Versions of the app.

"""

class Meta:
schema = TemplateSoftwareSchema
rest_name = "None"

def __init__(self, name: str = missing, versions: list = missing, **kwargs):
self.name = name
self.versions = versions

self.obj_type = self.__class__.__name__


TemplateSoftwareSchema.Meta.object_class = TemplateSoftware


class TemplateProperty(Object):
Expand Down Expand Up @@ -242,7 +269,7 @@ class TaskDefinitionTemplate(Object):
Version of the template.
description : str, optional
Description of the template.
software_requirements : list[Software], optional
software_requirements : list[TemplateSoftware], optional
List of required software.
resource_requirements : TemplateResourceRequirements, optional
Hardware requirements such as the number of cores, memory, and disk space.
Expand Down Expand Up @@ -279,7 +306,7 @@ def __init__(
name: str = missing,
version: str = missing,
description: str = missing,
software_requirements: list[Software] = missing,
software_requirements: list[TemplateSoftware] = missing,
resource_requirements: TemplateResourceRequirements = missing,
worker_context: WorkerContext = missing,
execution_context: dict[str, TemplateProperty] = missing,
Expand Down
14 changes: 12 additions & 2 deletions src/ansys/hps/client/jms/schema/task_definition_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,17 @@

from ansys.hps.client.common import BaseSchema, ObjectSchema

from .task_definition import HpcResourcesSchema, SoftwareSchema, WorkerContextSchema
from .task_definition import HpcResourcesSchema, WorkerContextSchema


class TemplateSoftwareSchema(BaseSchema):
class Meta(BaseSchema.Meta):
pass

name = fields.String(metadata={"description": "Name of the app."})
versions = fields.List(
fields.String(), allow_none=True, metadata={"description": "Versions of the app."}
)


class TemplatePropertySchema(BaseSchema):
Expand Down Expand Up @@ -126,7 +136,7 @@ class Meta(ObjectSchema.Meta):
)

software_requirements = fields.Nested(
SoftwareSchema,
TemplateSoftwareSchema,
many=True,
allow_none=True,
metadata={"description": "List of required software."},
Expand Down
16 changes: 8 additions & 8 deletions tests/jms/test_task_definition_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_template_deserialization():
"software_requirements": [
{
"name": "Ansys Mechanical APDL",
"version": "21.1",
"versions": ["21.1"],
}
],
"input_files": [],
Expand Down Expand Up @@ -112,12 +112,12 @@ def test_template_deserialization():
)
assert not template.resource_requirements.hpc_resources.custom_orchestration_options["bval"]

json_data["software_requirements"][0]["version"] = "2022 R2"
json_data["software_requirements"][0]["versions"] = ["2023 R2", "2024 R2"]
json_data["execution_command"] = "my command line"
json_data["execution_context"] = {"my_new_field": {"default": "value", "type": "string"}}

template = TaskDefinitionTemplateSchema().load(json_data)
assert template.software_requirements[0].version == "2022 R2"
assert template.software_requirements[0].versions == ["2023 R2", "2024 R2"]
assert template.execution_command == "my command line"
assert template.execution_context["my_new_field"].default == "value"

Expand All @@ -142,7 +142,7 @@ def test_template_integration(client):
if templates:
assert "software_requirements" in templates[0].keys()
assert "name" in templates[0]["software_requirements"][0].keys()
assert "version" in templates[0]["software_requirements"][0].keys()
assert "versions" in templates[0]["software_requirements"][0].keys()

templates = jms_api.get_task_definition_templates(fields=["name"])
if templates:
Expand All @@ -163,14 +163,14 @@ def test_template_integration(client):
assert template.name == template_name

# Modify template
template.software_requirements[0].version = "2.0.1"
template.software_requirements[0].versions = ["2025 R1", "2025 R2"]
template.resource_requirements = TemplateResourceRequirements(
hpc_resources=HpcResources(num_gpus_per_node=2)
)
templates = jms_api.update_task_definition_templates([template])
assert len(templates) == 1
template = templates[0]
assert template.software_requirements[0].version == "2.0.1"
assert template.software_requirements[0].versions == ["2025 R1", "2025 R2"]
assert template.name == template_name
assert template.resource_requirements.hpc_resources.num_gpus_per_node == 2

Expand All @@ -191,8 +191,8 @@ def test_template_integration(client):
assert original_template.version == new_template.version
assert original_template.version == new_template.version
assert (
original_template.software_requirements[0].version
== original_template.software_requirements[0].version
original_template.software_requirements[0].versions
== original_template.software_requirements[0].versions
)
jms_api.delete_task_definition_templates([new_template])

Expand Down
Loading