Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8e26595
Adjusted schema to existence of mode
engpas Feb 19, 2025
8751f7a
Added explicit mode to parameters
engpas Feb 19, 2025
c64ab4a
Revert import commenting
engpas Feb 20, 2025
fe18f9a
Enforce coding style
engpas Feb 20, 2025
102f2a8
Removed old code
engpas Feb 24, 2025
a28e886
Merge branch 'main' into pengeler/laki-reqs-parameters
engpas Feb 26, 2025
bcad099
Refactored Ducati
engpas Feb 27, 2025
fa789e7
Merge branch 'main' into pengeler/laki-reqs-parameters
engpas Feb 27, 2025
5b39a4d
Updated test to new jms
engpas Feb 27, 2025
3479793
Merge branch 'pengeler/laki-reqs-parameters' of https://github.com/an…
engpas Feb 27, 2025
7aa3ac3
Adjust docstrings
engpas Feb 28, 2025
6d7cce3
Update metadata description
engpas Feb 28, 2025
c477350
Merge branch 'main' into pengeler/laki-reqs-parameters
engpas Mar 13, 2025
c2adc3f
Merge branch 'main' into pengeler/laki-reqs-parameters
ojkoenig Mar 19, 2025
5469b4f
Added unmapped parameter passing
engpas Mar 19, 2025
f0e34d6
Added selection for unmapped parameter passing
engpas Mar 19, 2025
089fac6
Adjusted test to new signature
engpas Mar 19, 2025
6070c93
Added help text
engpas Mar 20, 2025
190970e
Merge branch 'main' into pengeler/exec-script-param-return
engpas Mar 24, 2025
a3ef2ba
Merge branch 'pengeler/exec-script-param-return' of https://github.co…
engpas Mar 25, 2025
c8c076e
Merge branch 'main' into pengeler/exec-script-param-return
engpas Mar 26, 2025
429a41c
Merge branch 'main' into pengeler/exec-script-param-return
engpas Mar 26, 2025
271868f
Merge branch 'main' into pengeler/exec-script-param-return
engpas Mar 26, 2025
01e6f6a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 26, 2025
29b6a30
Added support for unmapped params
engpas Mar 26, 2025
da4e38c
Added support for unmapped CLI option
engpas Mar 26, 2025
0301398
Added execution script for unmapped parameters
engpas Mar 26, 2025
4288c8a
Added more truss testcases
engpas Mar 26, 2025
e14abcc
Added support for more flags
engpas Mar 26, 2025
39b6946
Merge branch 'main' into pengeler/exec-script-param-return
engpas Mar 27, 2025
4df5818
Added suport for exec scripts and unmapped params
engpas Mar 31, 2025
b1f821a
Fixed task changing, added support for exec scripts and unmapped params
engpas Mar 31, 2025
8e0b292
Added support for exec script and unmapped parameters
engpas Mar 31, 2025
eba0c41
Added execution script
engpas Mar 31, 2025
97178ce
Increased max execution time
engpas Apr 1, 2025
d00e7f3
Changed execution time to incorporate changed tasks
engpas Apr 1, 2025
de03d2c
Fixed merge issue
engpas Apr 1, 2025
18aa0b0
Switch to format strings
engpas Apr 1, 2025
cdb1563
More execution time
engpas Apr 1, 2025
c630032
remove max
engpas Apr 1, 2025
602bf43
Fixed image generation for subscripts
engpas Apr 1, 2025
dbfdc77
Arg incompatibility detection, require output params
engpas Apr 1, 2025
5763990
Adjusted test to changed example
engpas Apr 1, 2025
de9d2f5
Updated documentation, fixed output mapping
engpas Apr 1, 2025
33dfe0f
Updated text
engpas Apr 1, 2025
a48175d
Updated comment
engpas Apr 1, 2025
f130d3a
Fixed invalid log string
engpas Apr 1, 2025
291d3b8
Merge branch 'main' into pengeler/exec-script-param-return
engpas Apr 2, 2025
b1c4b96
Rolled back two bar truss
engpas Apr 2, 2025
af31884
Added unmapped two bar truss
engpas Apr 2, 2025
9fe8114
Handle superset of desired parameters
engpas Apr 2, 2025
656e5f7
Remove unnecessary parts, make more general
engpas Apr 2, 2025
f42daac
Peel off unnecessary weight, consolidate
engpas Apr 2, 2025
f6cd5d2
Delete unnecessary files
engpas Apr 2, 2025
27ef2a5
Rolled back changes, added new test
engpas Apr 2, 2025
86a18f4
More debug printing
engpas Apr 2, 2025
40a7fb1
More cleanup
engpas Apr 2, 2025
34df9c9
Rollback python_linked
engpas Apr 2, 2025
c8e1456
Rolled back exec script
engpas Apr 2, 2025
1415132
Rolled back python multi
engpas Apr 2, 2025
49ddc9e
Re-apply the changes that constitute fixes
engpas Apr 2, 2025
d5b2eec
Renamed folder, adjusted test
engpas Apr 2, 2025
d09cb60
Added path argument
engpas Apr 2, 2025
31a260d
Change local import, add path passing
engpas Apr 2, 2025
4eed975
Moved task_files into utils
engpas Apr 2, 2025
90a1a33
Merge branch 'main' into pengeler/exec-script-param-return
engpas Apr 2, 2025
cc19475
Rollback
engpas Apr 2, 2025
e26d574
Changed example description
engpas Apr 7, 2025
879bdae
Renamed example
engpas Apr 7, 2025
6ace5f1
Rename
engpas Apr 7, 2025
2253d89
Adjusted test to new example directory
engpas Apr 7, 2025
8cdcf77
Fix a typo
engpas Apr 8, 2025
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
2 changes: 1 addition & 1 deletion examples/mapdl_motorbike_frame/exec_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def execute(self):
# Add " around exe if needed for Windows
exe = app["executable"]
if " " in exe and not exe.startswith('"'):
exe = '"%s"' % exe # noqa
exe = f'"{exe}"' # noqa

# Use properties from resource requirements
num_cores = self.context.resource_requirements["num_cores"]
Expand Down
2 changes: 1 addition & 1 deletion examples/python_large_output/exec_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def execute(self):
# Add " around exe if needed for Windows
exe = app["executable"]
if " " in exe and not exe.startswith('"'):
exe = '"%s"' % exe # noqa
exe = f'"{exe}"' # noqa

# Use properties from resource requirements
# None currently
Expand Down
2 changes: 2 additions & 0 deletions examples/python_multi_process_step/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def text(i, txt):
f"{task_definition}",
"--in-subscript",
]
if "images":
cmd.append("--images")
log.info("Run Subscript with: {cmd}")
subprocess.run(cmd, check=False)

Expand Down
16 changes: 7 additions & 9 deletions examples/python_multi_process_step/project_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,20 @@

Author(s): R.Walker

Run *python eval.py --help* for command line arguments.
Run *python project_setup.py --help* for command line arguments.

The project id is generated as
"py_{NUM_PROCESS_STEPS}_ps" and the `_img` is appended if result image is written.

Per default the project is inactive. You can activate the project with the `-a` flag
"Python - {NUM_PROCESS_STEPS} Task Defs (- Img )- Sequential/Parallel"


Example:
-------
```
python project_setup.py -n 100 -c 10 --no-images
python project_setup.py -n 100 -c 10
```
Create 100 design points
Create 100 design points with the default 3 tasks each
and change the first 10 design points
and do not write an result image.
and do not write a result image.

"""

Expand Down Expand Up @@ -235,7 +233,7 @@ def main(
Software(name="Python", version=python_version),
],
execution_command=cmd,
max_execution_time=duration * 1.5,
max_execution_time=duration * 1.5 + 12.0,
resource_requirements=ResourceRequirements(
num_cores=0.2,
memory=100 * 1024 * 1024, # 100 MB
Expand Down Expand Up @@ -280,7 +278,7 @@ def main(
# change dp task files
if change_job_tasks > 0:
log.info(f"Change tasks for {change_job_tasks} jobs")
update_task_files(proj, change_job_tasks, images)
update_task_files(project_api, change_job_tasks, images)

log.info(f"Created project '{proj.name}', ID='{proj.id}'")

Expand Down
34 changes: 21 additions & 13 deletions examples/python_multi_process_step/task_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def update_input_file(task):


def update_eval_script(task):
path = "eval.py"
cwd = os.path.dirname(__file__)
path = os.path.join(cwd, "eval.py")
lines = open(path).readlines()

log.info(f"Update input file {path} for task {task.task_definition_snapshot.name}")
Expand Down Expand Up @@ -82,14 +83,21 @@ def update_eval_script(task):
def update_task_files(project_api, num_jobs, write_images):
log.debug("=== Update Task files ===")

config = project_api.get_job_definitions()[0]
jobs = config.get_jobs(limit=num_jobs)
jobs = project_api.get_jobs(limit=num_jobs)

# Stop the jobs we're about to change
for job in jobs:
job["eval_status"] = "inactive"
project_api.update_jobs(jobs)
for job in jobs:
job["eval_status"] = "pending"

for dp in jobs:
log.debug(f" Update job {dp.name}")
dp.name = dp.name + " Modified"
tasks = dp.get_tasks()
for i, task in enumerate(tasks, 1):
tasks = project_api.get_tasks()
tasks_sel = [t for t in tasks if t.job_id == dp.id]
for i, task in enumerate(tasks_sel):
files = []
# input_file
##input_name = "ps_{}_input".format(i)
Expand All @@ -99,18 +107,18 @@ def update_task_files(project_api, num_jobs, write_images):
## src=os.path.join(cwd, "input.json".format(i)) ) )
# new input_file will be used by subprocess
new_input_file = update_input_file(task)
new_input_name = f"sub_td_{i}_input"
new_input_name = f"sub_td{i}_input"
files.append(
File(
name=new_input_name,
evaluation_path=f"sub_td_{i}_input.json",
evaluation_path=f"sub_td{i}_input.json",
type="application/json",
src=new_input_file,
)
)
# overwrite the eval script: same name --> will be overwritten
new_eval_script = update_eval_script(task)
new_eval_name = f"td_{i}_pyscript"
new_eval_name = f"td{i}_pyscript"
files.append(
File(
name=new_eval_name,
Expand All @@ -126,23 +134,23 @@ def update_task_files(project_api, num_jobs, write_images):
# collect=True, monitor=True,
# type="text/plain" ) )
# new output text
new_out_name = f"sub_td_{i}_results"
new_out_name = f"sub_td{i}_results"
files.append(
File(
name=new_out_name,
evaluation_path=f"sub_td_{i}_results.txt",
evaluation_path=f"sub_td{i}_results.txt",
collect=True,
monitor=True,
type="text/plain",
)
)
# new image
if write_images:
new_image_name = f"sub_td_{i}_results_jpg"
new_image_name = f"sub_td{i}_results_jpg"
files.append(
File(
name=new_image_name,
evaluation_path=f"sub_td_{i}_results.jpg",
evaluation_path=f"sub_td{i}_results.jpg",
type="image/jpeg",
collect=True,
)
Expand All @@ -158,7 +166,7 @@ def update_task_files(project_api, num_jobs, write_images):
task.output_file_ids = output_file_ids
task.input_file_ids = [file_ids[new_input_name], file_ids[new_eval_name]]

project_api.update_tasks(tasks)
project_api.update_tasks(tasks_sel)

project_api.update_jobs(jobs)
log.info(f"Updated {len(jobs)} design points")
92 changes: 92 additions & 0 deletions examples/python_two_bar_truss_params_in_exec_script/evaluate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# ruff: noqa

import json
import math
import os
import sys


def weight(P, d, t, B, H, rho, E):
w = 2 * math.pi * rho * d * t * math.sqrt((0.5 * B) ** 2 + H**2)
return w


def stress(P, d, t, B, H, rho, E):
s = P * math.sqrt((0.5 * B) ** 2 + H**2) / (2 * t * math.pi * d * H)
return s / 1000 # psi to ksi


def buckling_stress(P, d, t, B, H, rho, E):
b = math.pi**2 * E * (d**2 + t**2) / (8 * ((0.5 * B) ** 2 + H**2))
return b / 1000 # psi to ksi


def deflection(P, d, t, B, H, rho, E):
f = P * math.pow((0.5 * B) ** 2 + H**2, 3 / 2) / (2 * t * math.pi * d * H**2 * E)
return f


def filter_params(params):
for key in ["weight", "stress", "buckling_stress", "deflection"]:
params.pop(key)


def rename_params(params):
param_name_to_label = {
"height": "H",
"diameter": "d",
"thickness": "t",
"separation_distance": "B",
"young_modulus": "E",
"density": "rho",
"load": "P",
}
for key in param_name_to_label.keys():
params[param_name_to_label[key]] = params.pop(key)


def main():
# Load, filter and rename parameters
input_file_name = sys.argv[1]
input_file_path = os.path.abspath(input_file_name)
with open(input_file_path) as input_file:
params = json.load(input_file)
filter_params(params)
rename_params(params)

# Calculate results
output_parameters = {}
output_parameters.update(weight=weight(**params))
output_parameters.update(stress=stress(**params))
output_parameters.update(buckling_stress=buckling_stress(**params))
output_parameters.update(deflection=deflection(**params))

# Output results
with open("output_parameters.json", "w") as out_file:
json.dump(output_parameters, out_file, indent=4)


if __name__ == "__main__":
main()
82 changes: 82 additions & 0 deletions examples/python_two_bar_truss_params_in_exec_script/exec_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""Simplistic execution script for Python.

Command formed: python <script_file> <input_file>
"""

import json
import os

from ansys.rep.common.logging import log
from ansys.rep.evaluator.task_manager import ApplicationExecution


class PythonExecution(ApplicationExecution):
def execute(self):
log.info("Start Python execution script")

# Identify files
script_file = next((f for f in self.context.input_files if f["name"] == "script"), None)
assert script_file, "Python script file script missing"
input_filename = "input_parameters.json"
output_filename = "output_parameters.json"

with open(input_filename, "w") as in_file:
json.dump(self.context.parameter_values, in_file, indent=4)

# Identify application
app_name = "Python"
app = next((a for a in self.context.software if a["name"] == app_name), None)
assert app, f"Cannot find app {app_name}"

# Add " around exe if needed for Windows
exe = app["executable"]
if " " in exe and not exe.startswith('"'):
exe = f'"{exe}"' # noqa

# Use properties from resource requirements
# None currently

# Pass env vars correctly
env = dict(os.environ)
env.update(self.context.environment)

# Form command
cmd = f"{exe} {script_file['path']} {input_filename}"

log.debug(f"Executing command: {cmd}")
# Execute
self.run_and_capture_output(cmd, shell=True, env=env)

# Extract parameters if needed
try:
log.debug(f"Loading output parameters from {output_filename}")
with open(output_filename) as out_file:
output_parameters = json.load(out_file)
self.context.parameter_values.update(output_parameters)
log.debug(f"Loaded output parameters: {output_parameters}")
except Exception as ex:
log.error(f"Failed to read output_parameters from file: {ex}")

log.info("End Python execution script")
Loading
Loading