.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/api/01_basic_queries.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_api_01_basic_queries.py: .. _ref_api_basic_queries: Basic API queries ----------------- This example demonstrates the usage of the explicit API to perform basic queries on root project level. .. GENERATED FROM PYTHON SOURCE LINES 35-38 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform the required imports. .. GENERATED FROM PYTHON SOURCE LINES 38-46 .. code-block:: Python from pathlib import Path import tempfile from ansys.optislang.core import Optislang import ansys.optislang.core.examples as examples from ansys.optislang.core.nodes import ParametricSystem, System .. GENERATED FROM PYTHON SOURCE LINES 47-50 Helper functions ~~~~~~~~~~~~~~~~ Define a few helper functions. .. GENERATED FROM PYTHON SOURCE LINES 50-82 .. code-block:: Python def print_node(node): print(node) def print_parameters(node): if isinstance(node, ParametricSystem): print(f"** Parameters of {node.get_name()} **") [print(parameter) for parameter in node.parameter_manager.get_parameters()] def print_responses(node): if isinstance(node, ParametricSystem): print(f"** Responses of {node.get_name()} **") [print(response) for response in node.response_manager.get_responses()] def print_criteria(node): if isinstance(node, ParametricSystem): print(f"** Criteria of {node.get_name()} **") [print(criterion) for criterion in node.criteria_manager.get_criteria()] def for_each_child_node(node, function, recursive=False): for child_node in node.get_nodes(): function(child_node) if recursive: if isinstance(child_node, System): for_each_child_node(child_node, function) .. GENERATED FROM PYTHON SOURCE LINES 83-86 Create optiSLang instance ~~~~~~~~~~~~~~~~~~~~~~~~~ Create the optiSLang instance. .. GENERATED FROM PYTHON SOURCE LINES 86-89 .. code-block:: Python osl = Optislang(ini_timeout=60) .. GENERATED FROM PYTHON SOURCE LINES 90-94 Get paths of example scripts and run them ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get the paths of the example scripts and then run these scripts. .. GENERATED FROM PYTHON SOURCE LINES 94-101 .. code-block:: Python paths1 = examples.get_files("oscillator_sensitivity_mop") paths2 = examples.get_files("oscillator_optimization_on_mop") osl.run_python_file(paths1[0]) osl.run_python_file(paths2[0]) .. GENERATED FROM PYTHON SOURCE LINES 102-107 Query project tree ~~~~~~~~~~~~~~~~~~ Print each project node/system. Print parameters/responses/criteria for each parametric system in the project. .. GENERATED FROM PYTHON SOURCE LINES 107-120 .. code-block:: Python print("*** Project Nodes ***") for_each_child_node(osl.application.project.root_system, print_node, recursive=True) print("*** Registered parameters of parametric systems ***") for_each_child_node(osl.application.project.root_system, print_parameters, recursive=True) print("*** Registered responses of parametric systems ***") for_each_child_node(osl.application.project.root_system, print_responses, recursive=True) print("*** Defined criteria of parametric systems ***") for_each_child_node(osl.application.project.root_system, print_criteria, recursive=True) .. GENERATED FROM PYTHON SOURCE LINES 121-124 Stop and cancel project ~~~~~~~~~~~~~~~~~~~~~~~ Stop and cancel the project. .. GENERATED FROM PYTHON SOURCE LINES 124-126 .. code-block:: Python osl.dispose() .. _sphx_glr_download_examples_api_01_basic_queries.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_basic_queries.ipynb <01_basic_queries.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_basic_queries.py <01_basic_queries.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_