ansys-saf-templates 0.2.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. ansys/saf/templates/__init__.py +22 -0
  2. ansys/saf/templates/py.typed +0 -0
  3. ansys/saf/templates/steps/calculator/cookiecutter.json +16 -0
  4. ansys/saf/templates/steps/calculator/hooks/post_gen_project.py +56 -0
  5. ansys/saf/templates/steps/calculator/{{cookiecutter.__solution_module_name}}/solution/{{cookiecutter.__step_module_name}}.py +33 -0
  6. ansys/saf/templates/steps/calculator/{{cookiecutter.__solution_module_name}}/ui/pages/{{cookiecutter.__ui_page_file_name}}.py +104 -0
  7. ansys/saf/templates/steps/hps_job_submission/hps_parametric_study/cookiecutter.json +16 -0
  8. ansys/saf/templates/steps/hps_job_submission/hps_parametric_study/hooks/post_gen_project.py +88 -0
  9. ansys/saf/templates/steps/hps_job_submission/hps_parametric_study/{{cookiecutter.__solution_module_name}}/solution/scripts/{{cookiecutter.__step_module_name}}_calculate_sum.py +41 -0
  10. ansys/saf/templates/steps/hps_job_submission/hps_parametric_study/{{cookiecutter.__solution_module_name}}/solution/{{cookiecutter.__step_module_name}}.py +147 -0
  11. ansys/saf/templates/steps/hps_job_submission/hps_parametric_study/{{cookiecutter.__solution_module_name}}/ui/pages/{{cookiecutter.__ui_page_file_name}}.py +462 -0
  12. ansys/saf/templates/steps/hps_job_submission/hps_simple_job/cookiecutter.json +16 -0
  13. ansys/saf/templates/steps/hps_job_submission/hps_simple_job/hooks/post_gen_project.py +88 -0
  14. ansys/saf/templates/steps/hps_job_submission/hps_simple_job/{{cookiecutter.__solution_module_name}}/solution/scripts/{{cookiecutter.__step_module_name}}_calculate_sum_simple.py +41 -0
  15. ansys/saf/templates/steps/hps_job_submission/hps_simple_job/{{cookiecutter.__solution_module_name}}/solution/{{cookiecutter.__step_module_name}}.py +121 -0
  16. ansys/saf/templates/steps/hps_job_submission/hps_simple_job/{{cookiecutter.__solution_module_name}}/ui/pages/{{cookiecutter.__ui_page_file_name}}.py +330 -0
  17. ansys/saf/templates/steps/instance_management/geometry/cookiecutter.json +16 -0
  18. ansys/saf/templates/steps/instance_management/geometry/hooks/post_gen_project.py +96 -0
  19. ansys/saf/templates/steps/instance_management/geometry/{{cookiecutter.__solution_module_name}}/solution/{{cookiecutter.__step_module_name}}.py +74 -0
  20. ansys/saf/templates/steps/instance_management/geometry/{{cookiecutter.__solution_module_name}}/ui/pages/{{cookiecutter.__ui_page_file_name}}.py +488 -0
  21. ansys/saf/templates/templates.toml +40 -0
  22. ansys_saf_templates-0.2.dev0.dist-info/METADATA +301 -0
  23. ansys_saf_templates-0.2.dev0.dist-info/RECORD +27 -0
  24. ansys_saf_templates-0.2.dev0.dist-info/WHEEL +4 -0
  25. ansys_saf_templates-0.2.dev0.dist-info/entry_points.txt +3 -0
  26. ansys_saf_templates-0.2.dev0.dist-info/licenses/AUTHORS +12 -0
  27. ansys_saf_templates-0.2.dev0.dist-info/licenses/LICENSE +202 -0
@@ -0,0 +1,22 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from pathlib import Path
18
+
19
+
20
+ def get_plugin_path() -> Path:
21
+ """Return the path to this template plugin repository."""
22
+ return Path(__file__).parent.resolve()
File without changes
@@ -0,0 +1,16 @@
1
+ {
2
+ "__solution_name": "my_solution",
3
+ "__solution_module_name": "my_solution",
4
+ "__solution_definition_class_name": "MySolution",
5
+ "__solution_namespace": "ansys.solutions",
6
+ "__solution_namespace_path": "ansys/solutions",
7
+ "__solution_root_dir": "my_solution_dir",
8
+ "__ui_framework": "dash",
9
+ "__step_name": "my_new_step",
10
+ "__step_display_name": "{{ cookiecutter.__step_name | replace('_', ' ') | title }}",
11
+ "__step_name_hyphenated": "{{ cookiecutter.__step_name | replace('_', '-') }}",
12
+ "__step_module_name": "my_new_step",
13
+ "__step_module_name_hyphenated": "{{ cookiecutter.__step_module_name | replace('_', '-') }}",
14
+ "__step_definition_class_name": "MyNewStep",
15
+ "__ui_page_file_name": "my_new_page"
16
+ }
@@ -0,0 +1,56 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from pathlib import Path
18
+ import shutil
19
+
20
+ STEP_FILES = [
21
+ "solution/{{cookiecutter.__step_module_name}}.py",
22
+ ]
23
+
24
+ DASH_UI_FILES = [
25
+ "ui/pages/{{cookiecutter.__ui_page_file_name}}.py",
26
+ ]
27
+
28
+
29
+ if "{{ cookiecutter.__ui_framework }}" == "dash": # pyright: ignore[reportUnnecessaryComparison]
30
+ STEP_FILES.extend(DASH_UI_FILES)
31
+
32
+
33
+ def main() -> None:
34
+ solution_root_dir = Path("{{ cookiecutter.__solution_root_dir }}")
35
+ src_files: list[Path] = []
36
+ dst_files: list[Path] = []
37
+ for file in STEP_FILES:
38
+ src = Path.cwd() / file
39
+ dst = (
40
+ solution_root_dir
41
+ / "src"
42
+ / "{{ cookiecutter.__solution_namespace_path }}"
43
+ / "{{ cookiecutter.__solution_module_name }}"
44
+ / file
45
+ )
46
+ if dst.is_file():
47
+ raise FileExistsError(f"File {dst} already exists.")
48
+ src_files.append(src)
49
+ dst_files.append(dst)
50
+
51
+ for src, dst in zip(src_files, dst_files, strict=True):
52
+ shutil.copy(src, dst)
53
+
54
+
55
+ if __name__ == "__main__":
56
+ main()
@@ -0,0 +1,33 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """Backend of the {{ cookiecutter.__step_name }} step."""
18
+
19
+
20
+ from ansys.saf.glow.solution import StepModel, StepSpec, transaction
21
+
22
+
23
+ class {{ cookiecutter.__step_definition_class_name }}(StepModel):
24
+ """Step definition of the {{ cookiecutter.__step_name }} step."""
25
+
26
+ first_arg: float = 0
27
+ second_arg: float = 0
28
+ result: float = 0
29
+
30
+ @transaction(self=StepSpec(upload=["result"], download=["first_arg", "second_arg"]))
31
+ def calculate(self) -> None:
32
+ """Compute the sum of two numbers."""
33
+ self.result = self.first_arg + self.second_arg
@@ -0,0 +1,104 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """Frontend of {{ cookiecutter.__step_name }}."""
18
+
19
+ from ansys.saf.glow.client import callback
20
+ import dash
21
+ from dash_extensions.enrich import Input, Output, State, dcc, html
22
+ import dash_mantine_components as dmc
23
+
24
+ from {{ cookiecutter.__solution_namespace }}.{{ cookiecutter.__solution_module_name }}.solution.definition import {{ cookiecutter.__solution_definition_class_name }}
25
+
26
+
27
+ dash.register_page(__name__, name="{{ cookiecutter.__step_display_name }}", path_template="/projects/<project_id>/{{ cookiecutter.__step_module_name_hyphenated }}", icon_asset_name="game-icons--crossed-air-flows.svg", icon_asset_path="icons")
28
+
29
+
30
+ def layout(project: {{cookiecutter.__solution_definition_class_name}}):
31
+ """Layout of the {{ cookiecutter.__step_name }} page."""
32
+ step = project.steps.{{ cookiecutter.__step_module_name }}
33
+ return html.Div(
34
+ [
35
+ html.H1("{{ cookiecutter.__step_name }}", className="display-3", style={"font-size": "48px", "fontWeight": "bold"}),
36
+ html.P(
37
+ "Compute the sum of two numbers.",
38
+ className="lead",
39
+ style={"font-size": "20px"},
40
+ ),
41
+ dmc.Space(h=20),
42
+ dmc.NumberInput(
43
+ label="First Argument",
44
+ id="{{ cookiecutter.__step_name }}-first-arg",
45
+ value=step.first_arg,
46
+ placeholder="Enter first argument",
47
+ required=True,
48
+ style={"width": "40%", "display": "inline-block", "marginLeft": "30%"},
49
+ ),
50
+ dmc.Space(h=20),
51
+ dmc.NumberInput(
52
+ label="Second Argument",
53
+ id="{{ cookiecutter.__step_name }}-second-arg",
54
+ value=step.second_arg,
55
+ placeholder="Enter second argument",
56
+ required=True,
57
+ style={"width": "40%", "display": "inline-block", "marginLeft": "30%"},
58
+ ),
59
+ dmc.Space(h=20),
60
+ dmc.Button(
61
+ "Calculate",
62
+ id="{{ cookiecutter.__step_name }}-calculate",
63
+ leftSection=html.Img(src=dash.get_asset_url("icons/dark/streamline--startup-solid.svg")),
64
+ radius="md",
65
+ disabled=False,
66
+ style={"width": "40%", "display": "inline-block", "marginLeft": "30%"},
67
+ ),
68
+ dmc.Space(h=20),
69
+ dmc.NumberInput(
70
+ label="Result",
71
+ id="{{ cookiecutter.__step_name }}-result",
72
+ value=step.result,
73
+ disabled=True,
74
+ style={"width": "40%", "display": "inline-block", "marginLeft": "30%"},
75
+ ),
76
+ dcc.Loading(
77
+ type="circle",
78
+ fullscreen=True,
79
+ color="#ffb71b",
80
+ style={
81
+ "background-color": "rgba(55, 58, 54, 0.1)",
82
+ },
83
+ children=html.Div(id="{{ cookiecutter.__step_name }}_wait_completion"),
84
+ ),
85
+ ]
86
+ )
87
+
88
+
89
+ @callback(
90
+ Output("{{ cookiecutter.__step_name }}-result", "value"),
91
+ Output("{{ cookiecutter.__step_name }}_wait_completion", "children"),
92
+ Input("{{ cookiecutter.__step_name }}-calculate", "n_clicks"),
93
+ State("{{ cookiecutter.__step_name }}-first-arg", "value"),
94
+ State("{{ cookiecutter.__step_name }}-second-arg", "value"),
95
+ State("url", "pathname"),
96
+ prevent_initial_call=True,
97
+ )
98
+ def calculate(n_clicks: int, first_arg: int, second_arg: int, project: {{cookiecutter.__solution_definition_class_name}}):
99
+ """Trigger the computation."""
100
+ step = project.steps.{{ cookiecutter.__step_module_name }}
101
+ step.first_arg = first_arg
102
+ step.second_arg = second_arg
103
+ step.calculate()
104
+ return step.result, True
@@ -0,0 +1,16 @@
1
+ {
2
+ "__solution_name": "my_solution",
3
+ "__solution_module_name": "my_solution",
4
+ "__solution_definition_class_name": "MySolution",
5
+ "__solution_namespace": "ansys.solutions",
6
+ "__solution_namespace_path": "ansys/solutions",
7
+ "__solution_root_dir": "my_solution_dir",
8
+ "__ui_framework": "dash",
9
+ "__step_name": "my_new_step",
10
+ "__step_display_name": "{{ cookiecutter.__step_name | replace('_', ' ') | title }}",
11
+ "__step_name_hyphenated": "{{ cookiecutter.__step_name | replace('_', '-') }}",
12
+ "__step_module_name": "my_new_step",
13
+ "__step_module_name_hyphenated": "{{ cookiecutter.__step_module_name | replace('_', '-') }}",
14
+ "__step_definition_class_name": "MyNewStep",
15
+ "__ui_page_file_name": "my_new_page"
16
+ }
@@ -0,0 +1,88 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ from pathlib import Path
18
+ import re
19
+ import shutil
20
+
21
+ STEP_FILES = [
22
+ "solution/{{cookiecutter.__step_module_name}}.py",
23
+ "solution/scripts/{{cookiecutter.__step_module_name}}_calculate_sum.py",
24
+ ]
25
+
26
+ DASH_UI_FILES = [
27
+ "ui/pages/{{cookiecutter.__ui_page_file_name}}.py",
28
+ ]
29
+
30
+
31
+ if "{{ cookiecutter.__ui_framework }}" == "dash": # pyright: ignore[reportUnnecessaryComparison]
32
+ STEP_FILES.extend(DASH_UI_FILES)
33
+
34
+
35
+ def _patch_page_py(solution_root_dir: Path) -> None:
36
+ step_name = "{{ cookiecutter.__step_name }}"
37
+ page_py = (
38
+ solution_root_dir
39
+ / "src"
40
+ / "{{ cookiecutter.__solution_namespace_path }}"
41
+ / "{{ cookiecutter.__solution_module_name }}"
42
+ / "ui"
43
+ / "pages"
44
+ / "page.py"
45
+ )
46
+ if not page_py.is_file():
47
+ return
48
+ content = page_py.read_text(encoding="utf-8")
49
+ anchor_start = "dmc.MantineProvider(\n ["
50
+ new_div = f' html.Div(id="{step_name}-event-listeners-container"),'
51
+ if re.search(re.escape(new_div.strip()), content):
52
+ return
53
+ anchor_pos = content.find(anchor_start)
54
+ if anchor_pos == -1:
55
+ return
56
+ closing_pos = content.find("\n ],", anchor_pos + len(anchor_start))
57
+ if closing_pos == -1:
58
+ return
59
+ content = content[:closing_pos] + "\n" + new_div + content[closing_pos:]
60
+ page_py.write_text(content, encoding="utf-8")
61
+
62
+
63
+ def main() -> None:
64
+ solution_root_dir = Path("{{ cookiecutter.__solution_root_dir }}")
65
+ src_files: list[Path] = []
66
+ dst_files: list[Path] = []
67
+ for file in STEP_FILES:
68
+ src = Path.cwd() / file
69
+ dst = (
70
+ solution_root_dir
71
+ / "src"
72
+ / "{{ cookiecutter.__solution_namespace_path }}"
73
+ / "{{ cookiecutter.__solution_module_name }}"
74
+ / file
75
+ )
76
+ if dst.is_file():
77
+ raise FileExistsError(f"File {dst} already exists.")
78
+ src_files.append(src)
79
+ dst_files.append(dst)
80
+
81
+ for src, dst in zip(src_files, dst_files, strict=True):
82
+ shutil.copy(src, dst)
83
+
84
+ _patch_page_py(solution_root_dir)
85
+
86
+
87
+ if __name__ == "__main__":
88
+ main()
@@ -0,0 +1,41 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """Module containing function that is executed on HPS by the hps_job_submission_step."""
18
+
19
+ from pathlib import Path
20
+
21
+
22
+ def calculate_sum(
23
+ first_arg: float, # arg passed directly
24
+ second_arg: float, # arg passed directly
25
+ ):
26
+ """Calculate the sum of two arguments, demonstrating various input and output mechanisms."""
27
+ result = first_arg + second_arg
28
+
29
+ with open("logs.txt", "a") as log_file:
30
+ log_file.write(f"Calculation performed with first_arg={first_arg} and second_arg={second_arg}\n")
31
+
32
+ # generate output files
33
+ output_content_str = f"result({first_arg}, {second_arg}) = {result}"
34
+
35
+ # write output to location specified in the HpsOutputFileSpecification evaluation_path
36
+ Path("output.txt").write_text(output_content_str)
37
+
38
+ with open("logs.txt", "a") as log_file:
39
+ log_file.write(f"Calculation done, result={result}\n")
40
+
41
+ return {"result": result}
@@ -0,0 +1,147 @@
1
+ # Copyright (C) 2026 ANSYS, Inc. and/or its affiliates.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """Backend of the {{ cookiecutter.__step_name }} step."""
18
+
19
+
20
+ import json
21
+ import logging
22
+ import time
23
+
24
+ from ansys.saf.glow.solution import EntityHandle, long_running, NO_ENTITY, StepModel, StepSpec, transaction
25
+ from ansys.saf.glow.solution.hps import (
26
+ HpsExecutionSpecification,
27
+ HpsJobEvaluationStatus,
28
+ HpsOutputFileSpecification,
29
+ HpsParametricStudyProject,
30
+ NO_HPS_STUDY_PROJECT,
31
+ )
32
+
33
+ from {{ cookiecutter.__solution_namespace }}.{{ cookiecutter.__solution_module_name }}.solution.scripts.{{cookiecutter.__step_module_name}}_calculate_sum import calculate_sum
34
+
35
+ logger = logging.getLogger(__name__)
36
+
37
+
38
+ NUMBER_OF_DESIGN_POINTS = 4
39
+ TERMINAL_STATUSES = {
40
+ HpsJobEvaluationStatus.EVALUATED.value,
41
+ HpsJobEvaluationStatus.FAILED.value,
42
+ HpsJobEvaluationStatus.ABORTED.value,
43
+ HpsJobEvaluationStatus.TIMEOUT.value,
44
+ }
45
+
46
+ class {{ cookiecutter.__step_definition_class_name }}(StepModel):
47
+ """Step definition of the {{ cookiecutter.__step_name }} step."""
48
+
49
+ first_args: list[float] = [0.0] * NUMBER_OF_DESIGN_POINTS
50
+ second_args: list[float] = [0.0] * NUMBER_OF_DESIGN_POINTS
51
+ results: list[float | None] = [None] * NUMBER_OF_DESIGN_POINTS
52
+ output_file_handles: list[EntityHandle] = [NO_ENTITY] * NUMBER_OF_DESIGN_POINTS
53
+ statuses: list[str] = ["No Job Created"] * NUMBER_OF_DESIGN_POINTS
54
+
55
+ hps_project: HpsParametricStudyProject = NO_HPS_STUDY_PROJECT
56
+
57
+ job_running: bool = False
58
+ has_result: bool = False
59
+ logs: str = ""
60
+
61
+ def _push_statuses(self, statuses: list[str], stream_name: str) -> None:
62
+ self.statuses = statuses
63
+ self.transaction.raise_event(json.dumps(statuses), stream_name=stream_name)
64
+ self.transaction.upload(["statuses"])
65
+
66
+ def _monitor_until_terminal_status(self) -> list[str]:
67
+ """Monitor statuses and logs until all design points reach a terminal state."""
68
+ logger.info("started monitoring HPS parametric study")
69
+ last_full_logs = ""
70
+ while True:
71
+ time.sleep(1)
72
+
73
+ statuses = [status.evaluation_status.value for status in self.hps_project.get_status_of_design_points()]
74
+ self._push_statuses(statuses=statuses, stream_name="{{ cookiecutter.__step_name_hyphenated }}-hps-parametric-status")
75
+
76
+ logs_chunks: list[str] = []
77
+ for index, logs_handle in enumerate(self.hps_project.logs_file):
78
+ if logs_handle and logs_handle != NO_ENTITY:
79
+ content = self.storage_scope.get_text(logs_handle)
80
+ logs_chunks.append(f"Design point {index + 1}:\n{content}")
81
+ if logs_chunks:
82
+ logs_content = "\n\n".join(logs_chunks)
83
+ delta = logs_content[len(last_full_logs):]
84
+ if delta:
85
+ self.logs = logs_content
86
+ self.transaction.upload(["logs"])
87
+ self.transaction.raise_event(json.dumps(delta), stream_name="{{ cookiecutter.__step_name_hyphenated }}-hps-parametric-logs")
88
+ last_full_logs = logs_content
89
+
90
+ if all(status in TERMINAL_STATUSES for status in statuses):
91
+ return statuses
92
+
93
+ @transaction(
94
+ self=StepSpec(
95
+ upload=["statuses", "results", "hps_project", "job_running", "has_result", "logs", "output_file_handles"],
96
+ download=["first_args", "second_args"],
97
+ ),
98
+ )
99
+ @long_running
100
+ def hps_parametric_calculate(self) -> None:
101
+ """Run a four-point parametric study on HPS."""
102
+ self.job_running = True
103
+ self.has_result = False
104
+ self.transaction.upload(["job_running", "has_result"])
105
+
106
+ self.results = [None] * NUMBER_OF_DESIGN_POINTS
107
+ self.output_file_handles = [NO_ENTITY] * NUMBER_OF_DESIGN_POINTS
108
+ self.logs = ""
109
+
110
+ # execute the function that performs the calculation and generates outputs on HPS
111
+ hps_execution_spec = HpsExecutionSpecification(
112
+ function=calculate_sum,
113
+ output_parameters={
114
+ "result": float,
115
+ "output_file": HpsOutputFileSpecification(
116
+ evaluation_path="output.txt",
117
+ return_type=EntityHandle,
118
+ ),
119
+ "logs_file": HpsOutputFileSpecification(
120
+ evaluation_path="logs.txt",
121
+ collect_interval=1,
122
+ return_type=EntityHandle,
123
+ ),
124
+ }
125
+ )
126
+ self.hps_project = hps_execution_spec.execute_parametric_study(
127
+ first_arg=self.first_args,
128
+ second_arg=self.second_args,
129
+ )
130
+
131
+ self.statuses = ["submitted"] * NUMBER_OF_DESIGN_POINTS
132
+ self._push_statuses(statuses=self.statuses, stream_name="{{ cookiecutter.__step_name_hyphenated }}-hps-parametric-status")
133
+
134
+ final_statuses = self._monitor_until_terminal_status()
135
+ self.results = [
136
+ result if status == HpsJobEvaluationStatus.EVALUATED.value else None
137
+ for status, result in zip(final_statuses, self.hps_project.result)
138
+ ]
139
+ self.has_result = any(result is not None for result in self.results)
140
+ self.transaction.raise_event(
141
+ json.dumps(self.results),
142
+ stream_name="{{ cookiecutter.__step_name_hyphenated }}-hps-parametric-results",
143
+ )
144
+ self.output_file_handles = list(self.hps_project.output_file)
145
+ self._push_statuses(final_statuses, stream_name="{{ cookiecutter.__step_name_hyphenated }}-hps-parametric-status")
146
+ self.job_running = False
147
+ logger.info("completed monitoring HPS parametric study")