Skip to content

Commit

Permalink
Change the structure of the proxy solver example a bit. First load th…
Browse files Browse the repository at this point in the history
…e parametric, then register it and at the end modify the parameter bounds and create a criterium.
  • Loading branch information
optislangdeveloper committed Oct 8, 2024
1 parent 222a526 commit d532156
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 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,34 @@ 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.

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}
)
load_json = {}
load_json["parameters"] = []
load_json["responses"] = []

# Register response in the proxy solver and create criterion in algorithm
for i in range(1,6):
parameter = {"dir": {"value": "input"}, "name": f"X{i}", "value": 1.0}
load_json["parameters"].append(parameter)

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(criterion)
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):
algorithm_system.parameter_manager.modify_parameter(OptimizationParameter(name = f"X{i}", reference_value = 1.0, range = (-3.14, 3.14)))

# Create a criterion in the algorithm system

algorithm_system.criteria_manager.add_criterion(ObjectiveCriterion(name="obj", expression="Y", criterion=ComparisonType.MIN))


#########################################################
Expand Down Expand Up @@ -191,7 +205,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 +220,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

0 comments on commit d532156

Please sign in to comment.