Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/ansys/actions-8
Browse files Browse the repository at this point in the history
  • Loading branch information
widerschein authored Oct 17, 2024
2 parents 0e60cb7 + 1946dcc commit 41ddb1f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
12 changes: 12 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is the list of PyOptiSLang's significant contributors.
#
# This file does not necessarily list everyone who has contributed code.
#
# For contributions made under a Corporate CLA, the organization is
# added to this file.
#
# If you have contributed to the repository and want to be added to this file,
# submit a request.
#
#
ANSYS, Inc.
File renamed without changes.
41 changes: 30 additions & 11 deletions examples/workflow_creation/03_proxy_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
This example demonstrates how to obtain designs from parametric system and process them externally.
It creates a proxy solver node inside parametric system and solves it's designs externally.
This is a unified approach for "optiSLang inside" solutions.
"""

#########################################################
Expand Down Expand Up @@ -144,22 +146,38 @@ def calculate(designs):
proxy_solver.set_property("MultiDesignLaunchNum", multi_design_launch_num)
proxy_solver.set_property("ForwardHPCLicenseContextEnvironment", True)

# Add parameters to the algorithm system and register them in the proxy solver.
# Load the available parameters and responses.

load_json = {}
load_json["parameters"] = []
load_json["responses"] = []

for i in range(1, 6):
parameter = {"dir": {"value": "input"}, "name": f"X{i}", "value": 1.0}
load_json["parameters"].append(parameter)

response = {"dir": {"value": "output"}, "name": "Y", "value": 3.0}
load_json["responses"].append(response)

proxy_solver.load(args=load_json)

# Register parameters and responses to be available in the algorithm system

proxy_solver.register_locations_as_parameter()
proxy_solver.register_locations_as_response()

# Change parameter bounds.

for i in range(1, 6):
parameter = OptimizationParameter(name=f"X{i}", reference_value=1.0, range=(-3.14, 3.14))
algorithm_system.parameter_manager.add_parameter(parameter)
proxy_solver.register_location_as_parameter(
{"dir": {"value": "input"}, "name": parameter.name, "value": parameter.reference_value}
algorithm_system.parameter_manager.modify_parameter(
OptimizationParameter(name=f"X{i}", reference_value=1.0, range=(-3.14, 3.14))
)

# Register response in the proxy solver and create criterion in algorithm
# Create a criterion in the algorithm system

proxy_solver.register_location_as_response({"dir": {"value": "output"}, "name": "Y", "value": 3.0})
criterion = ObjectiveCriterion(
name="obj", expression="Y", expression_value=3.0, criterion=ComparisonType.MIN
algorithm_system.criteria_manager.add_criterion(
ObjectiveCriterion(name="obj", expression="Y", criterion=ComparisonType.MIN)
)
algorithm_system.criteria_manager.add_criterion(criterion)


#########################################################
Expand Down Expand Up @@ -191,7 +209,7 @@ def calculate(designs):
if len(design_list):
responses_dict = calculate(design_list)
proxy_solver.set_designs(responses_dict)
time.sleep(0.1)
# time.sleep(0.1)

print("Solved Successfully!")

Expand All @@ -206,6 +224,7 @@ def calculate(designs):
# View generated workflow
# ~~~~~~~~~~~~~~~~~~~~~~~
# This image shows the generated workflow.
# However, it is important to note, that this workflow is only usable through pyoptislang and cannot be used interactively!
#
# .. image:: ../../_static/03_ProxySolver.png
# :width: 400
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ tests = [
"matplotlib>=3.5.3",
]
doc = [
"ansys-sphinx-theme==1.0.11",
"ansys-sphinx-theme==1.1.2",
"matplotlib==3.9.2",
"numpydoc==1.8.0",
"pypandoc==1.13",
"Sphinx==7.4.7",
"sphinx-copybutton==0.5.2",
"sphinx-gallery==0.17.1",
"sphinx-gallery==0.18.0",
"sphinxcontrib-images==0.9.4",
]
build = [
Expand Down

0 comments on commit 41ddb1f

Please sign in to comment.