### Start a Project using a Python File Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/functions.rst Starts a project by running a specified Python file and then initiating the project. Ensure the example file path is correct. ```python from ansys.optislang.core import examples path_to_file = examples.get_files("simple_calculator")[0] osl.application.project.run_python_file(file_path=path_to_file) osl.application.project.start() ``` -------------------------------- ### Open and Start an Existing Project Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/index.rst Opens an existing OptiSLang project and starts its execution using the start() method. Ensure the project path points to a valid project file. ```python from ansys.optislang.core import Optislang from ansys.optislang.core import examples project_path = examples.get_files("simple_calculator")[1][0] with Optislang(project_path=project_path) as osl: osl.application.project.start() ``` -------------------------------- ### new Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Creates a new, empty optiSLang project. This is the starting point for creating a new simulation or optimization setup. ```APIDOC ## new ### Description Creates a new, empty optiSLang project. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### start Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Starts the optiSLang server or a simulation/optimization process. This command initiates execution. ```APIDOC ## start ### Description Starts the optiSLang server or a simulation/optimization process. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Install PyOptiSLang from Wheelhouse (Linux) Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Install PyOptiSLang and its dependencies from a local wheelhouse on Linux. Ensure the wheelhouse zip file is unzipped to a 'wheelhouse' directory. ```bash unzip PyOptiSLang-v0.1.0-wheelhouse-Linux-3.10.zip wheelhouse pip install ansys-optislang-core -f wheelhouse --no-index --upgrade --ignore-installed ``` -------------------------------- ### Clone Repository and Install PyOptiSLang Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/contributing/index.rst Clone the PyOptiSLang repository and install the latest release in development mode. Ensure pip is up-to-date before installation. ```bash git clone https://github.com/ansys/pyoptislang cd pyoptislang pip install pip -U pip install -e . ``` -------------------------------- ### Verify PyOptiSLang Installation Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/getting_started/index.rst Verify that PyOptiSLang is installed correctly by importing the Optislang class and creating an instance. This confirms that the core functionality is accessible. ```python from ansys.optislang.core import Optislang osl = Optislang() print(osl) osl.dispose() ``` -------------------------------- ### Initialize Optislang and Access Application Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/functions.rst Initializes an Optislang instance and retrieves the application object. This is the starting point for most operations. ```python from ansys.optislang.core import Optislang osl = Optislang() application = osl.application ``` -------------------------------- ### Launch OptiSLang with a Specific Project Path Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Initializes an OptiSLang instance and creates or opens a project at the specified path. The project file is created in the current working directory in this example. ```python from ansys.optislang.core import Optislang from ansys.optislang.core.pathlib import Path path = Path.cwd() project_name = "test.opf" osl = Optislang(project_path=path / project_name) print(osl) osl.dispose() ``` -------------------------------- ### Get General Project Information Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/functions.rst Prints general information about the Optislang instance. This provides a quick overview of the current state. ```python print(osl) ``` -------------------------------- ### Install Latest PyOptiSLang from GitHub Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Install the latest development version of PyOptiSLang directly from its GitHub repository. This is useful for testing the newest features or contributing to the project. ```bash pip install git+https://github.com/ansys/pyoptislang.git ``` -------------------------------- ### Install Latest PyOptiSLang from PyPI Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Install the latest release of the PyOptiSLang package from the Python Package Index (PyPI). This is the standard method for end-users. ```bash pip install ansys-optislang-core ``` -------------------------------- ### Launch OptiSLang Server Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/index.rst Launches the OptiSLang server. By default, it starts in a temporary directory. You can specify a project path to open an existing project or create a new one. ```python import os from ansys.optislang.core import Optislang from pathlib import Path path = Path.cwd() file_name = "test_optislang.opf" with Optislang(project_path=path / file_name) as osl: print(osl) ``` -------------------------------- ### create_start_designs Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Creates initial designs for the optimization process. These serve as starting points for the simulation or optimization runs. ```APIDOC ## create_start_designs ### Description Creates initial designs for the optimization process. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Create and Save a New Project Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/functions.rst Creates a new project and immediately saves it to a specified path. This is useful for starting a new design. ```python new_project = Path().cwd() / "new_project.opf" osl.application.new() osl.application.save_as(new_project) ``` -------------------------------- ### Get Specific Placeholder Information Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/placeholders_howto.rst Fetches detailed configuration and current value for a given placeholder ID. Can be used to get info for one or all placeholders. ```python # Get detailed information about a specific placeholder placeholder_info = osl.project.get_placeholder("thickness") print(f"Placeholder ID: {placeholder_info.placeholder_id}") print(f"Type: {placeholder_info.type}") print(f"User Level: {placeholder_info.user_level}") print(f"Description: {placeholder_info.description}") print(f"Current Value: {placeholder_info.value}") # Get information about all placeholders placeholder_ids = osl.project.get_placeholder_ids() for placeholder_id in placeholder_ids: info = osl.project.get_placeholder(placeholder_id) print(f"ID: {info.placeholder_id}, Type: {info.type}, Value: {info.value}") ``` -------------------------------- ### Retrieve Project Parameters Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Shows how to get all defined parameters (Optimization, Stochastic, Mixed, Dependent) and their names from a parametric system. ```python # ... parameter_manager = root_system.parameter_manager parameters = parameter_manager.get_parameters() parameters_names = parameter_manager.get_parameters_names() ``` -------------------------------- ### set_start_designs Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Sets the initial designs for the optimization process. This command replaces any existing start designs. ```APIDOC ## set_start_designs ### Description Sets the initial designs for the optimization process. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Get Specific Project Details Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/functions.rst Retrieves and prints specific details about the Optislang application and project, such as version and working directory. ```python print(f"Version: {osl.application.get_version_string()}") print(f"Working directory: {osl.application.project.get_working_dir()}") ``` -------------------------------- ### Developer Installation of PyOptiSLang Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Clone the PyOptiSLang repository and install it in editable mode for local development. This allows direct modification of the package files and immediate reflection of changes after restarting the Python kernel. ```bash git clone https://github.com/ansys/pyoptislang.git cd pyoptislang pip install -e . ``` -------------------------------- ### Launch Specific OptiSLang Version by Executable Path Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Launches a specific OptiSLang version by providing the full path to its executable file. This is useful for non-standard installations or specific version requirements. ```python from ansys.optislang.core import Optislang osl = Optislang( executable=r"C:\\Program Files\\Dynardo\\Ansys optiSLang\\2023 R1\\optislang.com" ) print(osl) osl.dispose() ``` -------------------------------- ### Run Pre-commit Hooks for Code Styling Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/contributing/index.rst Install and run pre-commit to ensure code meets PEP8 standards. This command checks all files in the repository. ```bash pip install pre-commit pre-commit run --all-files ``` -------------------------------- ### Using Optislang as a Context Manager Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst This snippet demonstrates how to use the `Optislang` class as a context manager. This ensures that the optiSLang instance and its connection are automatically shut down gracefully, even if errors occur. It starts a new project within the optiSLang application. ```python from ansys.optislang.core import Optislang with Optislang() as osl: print(osl) osl.application.project.start() ``` -------------------------------- ### Optislang with Manual Server Shutdown Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst This example shows how to use `Optislang` with `shutdown_on_finished=False`. When the context manager exits, the connection is closed, but the optiSLang server remains running. The `shutdown()` method is explicitly called to stop the server. ```python from ansys.optislang.core import Optislang with Optislang(shutdown_on_finished=False) as osl: print(osl) osl.start() osl.shutdown() ``` -------------------------------- ### Install Pre-commit Hook Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/contributing/index.rst Install pre-commit as a Git hook to automatically check code style before each commit. This prevents pushing code that fails style checks. ```bash pre-commit install ``` -------------------------------- ### apply_wizard Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Applies a wizard to the current project. This command is used to automate the setup of certain project configurations using predefined wizard templates. ```APIDOC ## apply_wizard ### Description Applies a wizard to the current project. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Run Static Type Checking with Mypy Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/contributing/index.rst Install the necessary packages for type checking, including typing extras, and then run mypy on the source folder to ensure type safety. ```bash python -m pip install "'.[typing]'" python -m mypy src ``` -------------------------------- ### reset Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Resets the project to a previous state or to its initial configuration. This is useful for starting over or undoing changes. ```APIDOC ## reset ### Description Resets the project to a previous state or to its initial configuration. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Get Project Responses Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Retrieve all defined responses from the project's response manager. This is useful for inspecting existing response configurations. ```python # ... response_manager = root_system.response_manager responses = response_manager.get_responses() responses_names = response_manager.get_responses_names() ``` -------------------------------- ### Validate Custom Executable Path Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/security_considerations.rst Shows how to validate a custom optiSLang executable path to ensure it points to a legitimate and untampered installation before initializing the Optislang class. ```python from ansys.optislang.core import Optislang from pathlib import Path # Validate the executable exists and is from a trusted location trusted_executable = Path("/path/to/trusted/optislang") if trusted_executable.exists(): osl = Optislang(executable=trusted_executable) ``` -------------------------------- ### Get All Placeholder IDs Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/placeholders_howto.rst Retrieves a list of all placeholder IDs currently present in the project. Useful for iterating and inspecting all placeholders. ```python # Get all placeholder IDs in the project placeholder_ids = osl.project.get_placeholder_ids() print(f"Found {len(placeholder_ids)} placeholders:") for placeholder_id in placeholder_ids: print(f" - {placeholder_id}") ``` -------------------------------- ### Get Project Criteria Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Retrieve all defined criteria from the project's criteria manager. This is useful for inspecting existing criteria configurations. ```python # ... criteria_manager = root_system.criteria_manager criteria = criteria_manager.get_criteria() criteria_names = criteria_manager.get_criteria_names() ``` -------------------------------- ### Create Placeholder Directly from Node Property Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/placeholders_howto.rst Creates a placeholder directly from an existing node property. This is an alternative to creating a stand-alone placeholder and then assigning it. This example shows the initial node creation step. ```python from ansys.optislang.core import node_types # Get a node reference root_system = osl.project.root_system mop_solver_node = root_system.create_node( type_=node_types.Mopsolver, name="MOPSolver Node" ) ``` -------------------------------- ### Run Python Command in optiSLang Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/run_python.rst Execute a single Python command within optiSLang to get information about an actor. A new Python context is created for each call to `run_python_script`. ```python from ansys.optislang.core import Optislang osl = Optislang() print(osl.application.project.run_python_script("""help(actors.SensitivityActor)""")) osl.dispose() ``` -------------------------------- ### Initialize and Log Message Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/logging.rst Demonstrates how to initialize the PyOptiSLang client with a specific log level and log an informational message. ```python from ansys.optislang.core import Optislang osl = Optislang(loglevel="INFO") osl.log.info("This is an useful message") ``` -------------------------------- ### Access and Save Project Information Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Demonstrates how to load a project, save a copy, and retrieve basic project details like name, location, and status. ```python from ansys.optislang.core import Optislang from ansys.optislang.core import examples from pathlib import Path example = examples.get_files("calculator_with_params")[1][0] osl = Optislang(project_path=example) osl.application.save_copy(Path.cwd() / "project_content.opf") project = osl.application.project # print project info print(project) # obtain these information directly name = project.get_name() location = project.get_location() status = project.get_status() ``` -------------------------------- ### open Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Opens an optiSLang project. This command is similar to 'load' and is used to bring a project into the active session. ```APIDOC ## open ### Description Opens an optiSLang project. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Connect to optiSLang and Query Server Info Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/osl_server_usage.rst Connect to an optiSLang instance using Optislang and query basic project and server information. This snippet demonstrates how to obtain handles to the internal TcpOslServer and use its methods to retrieve project details. ```python from ansys.optislang.core import Optislang from ansys.optislang.core.project_parametric import Design from ansys.optislang.core import examples from pathlib import Path # open project with defined parameters parametric_project = examples.get_files("calculator_with_params")[1][0] osl = Optislang(project_path=parametric_project) # Query basic server/project info. print(f"Basic project info: {osl.osl_server.get_basic_project_info()}") print(f"Server info: {osl.osl_server.get_server_info()}") print(f"Full project tree: {osl.osl_server.get_full_project_tree()}") ``` -------------------------------- ### Open Project and Access Root System Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/design_evaluation.rst Opens a parametric project using Optislang and retrieves the root system. Ensures the original project file is not modified by saving a copy. ```python from ansys.optislang.core import Optislang from ansys.optislang.core.project_parametric import Design from ansys.optislang.core import examples from pathlib import Path # open project with defined parameters parametric_project = examples.get_files("calculator_with_params")[1][0] osl = Optislang(project_path=parametric_project) # do not modify original file osl.application.save_as(Path.cwd() / "parametric_project.opf") # get root system root_system = osl.application.project.root_system ``` -------------------------------- ### Connect to Running optiSLang Instance Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Connects to an already running optiSLang instance using TCP/IP communication. Requires specifying the host and port of the running instance. ```python from ansys.optislang.core import Optislang host = "127.0.0.1" port = 5310 osl = Optislang(host=host, port=port) osl.dispose() ``` -------------------------------- ### Basic PyOptiSLang Usage Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Launches optiSLang locally, runs a Python script, saves the project, and closes the connection. Ensure the script path is correct. ```python from ansys.optislang.core import Optislang osl = Optislang() file_path = r"C:\Users\Username\my_scripts\myscript.py" osl.application.project.run_python_file(path=file_path) osl.application.save_copy("MyNewProject.opf") osl.dispose() ``` -------------------------------- ### Launch OptiSLang with TCP/IP Communication Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Launches OptiSLang locally with TCP/IP communication enabled, listening on all interfaces. Note: This uses an insecure mode without TLS and is not recommended for production. ```python from ansys.optislang.core import Optislang from ansys.optislang.core.communication_channels import CommunicationChannel osl = Optislang( communication_channel=CommunicationChannel.TCP, server_address="0.0.0.0" ) print(osl) osl.dispose() ``` -------------------------------- ### Get and Filter Designs Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Retrieve and filter result designs for a given state. This allows for targeted analysis of simulation outcomes based on various criteria. ```python # ... parametric_system: ParametricSystem hids = parametric_system.get_states_ids() design_manager = parametric_system.design_manager designs = design_manager.get_designs(hids[0]) design = design_manager.get_design(hids[0] + ".1") ``` ```python # ... sorted_designs = design_manager.sort_designs_by_hid(designs) ``` ```python # ... filtered_designs = design_manager.filter_designs_by( designs=designs, hid=None, status=DesignStatus.SUCCEEDED, pareto_design=None, feasible=True, ) ``` -------------------------------- ### Find All Supported OptiSLang Executables Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Retrieves and prints a list of all supported OptiSLang executable files found on the system. ```python from ansys.optislang.core import utils print(utils.find_all_osl_exec()) ``` -------------------------------- ### Launch optiSLang Locally Source: https://github.com/ansys/pyoptislang/blob/main/README.rst Launches an optiSLang instance locally using default communication channels. The instance is disposed of after use. ```python from ansys.optislang.core import Optislang osl = Optislang() osl.dispose() ``` -------------------------------- ### load Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Loads an existing optiSLang project from a file. This command is used to open and continue working on a previously saved project. ```APIDOC ## load ### Description Loads an existing optiSLang project from a file. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Connect Nodes Using Slot Instances Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/create_workflow.rst Connects nodes by obtaining their input and output slot instances and then using the connect_to method. This approach provides fine-grained control over connections, especially for inner slots of parametric systems. ```python # ... IIDesign = root_system.get_inner_input_slots("IIDesign")[0] IODesign = root_system.get_inner_output_slots("IODesign")[0] IReferenceDesign = sensitivity.get_input_slots("IReferenceDesign")[0] OReferenceDesign = sensitivity.get_output_slots("OReferenceDesign")[0] IODesign.connect_to(IReferenceDesign) OReferenceDesign.connect_to(IIDesign) ``` -------------------------------- ### Assign Existing Placeholder to Node Property Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/placeholders_howto.rst Assigns a pre-created placeholder to a specific property of a node. The placeholder and property must share the same data type. This example assumes the 'global_max_parallel' placeholder has already been created. ```python from ansys.optislang.core import node_types # Get a node reference root_system = osl.project.root_system mop_solver_node = root_system.create_node( type_=node_types.Mopsolver, name="MOPSolver Node" ) # Assign the placeholder to a node property mop_solver_node.assign_placeholder( property_name="MaxParallel", placeholder_id="global_max_parallel" ) ``` -------------------------------- ### Create Design from Scratch Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/design_evaluation.rst Create a design directly using the Design() class or create an empty design and add parameters afterward. Parameters can also be removed or cleared. ```python # design created directly using Design() class direct_design = Design(parameters={"a": 3, "b": 4}) # create empty design and add parameters afterward empty_design = Design() empty_design.set_parameter_by_name(name="a", value=3) empty_design.set_parameter_by_name(name="c", value=4) # Remove a parameter if desired empty_design.remove_parameter(name="c") # Remove all parameters if desired empty_design.clear_parameters() ``` -------------------------------- ### Connect to Local OptiSLang Instance by Server ID Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Connects to an already running local OptiSLang instance using its unique server ID. This ID is the Named Pipe name on Windows or the Unix Domain Socket path on Linux. ```python from ansys.optislang.core import Optislang local_server_id = "local_osl_server_id" osl = Optislang(local_server_id=local_server_id) print(osl) osl.dispose() ``` -------------------------------- ### Shut Down Optislang Server with shutdown() and dispose() Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Use both shutdown() and dispose() methods to shut down the optiSLang server when the instance is initialized with shutdown_on_finished=False. This ensures the server is terminated gracefully. ```python from ansys.optislang.core import Optislang osl = Optislang(shutdown_on_finished=False) print(osl) osl.shutdown() osl.dispose() ``` -------------------------------- ### Secure subprocess.Popen Usage Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/security_considerations.rst Illustrates a secure pattern for using subprocess.Popen to launch the optiSLang application, emphasizing shell=False and argument validation. ```python # Security: This subprocess call is safe because: # 1. shell=False is explicitly set to prevent shell injection # 2. The executable path is validated to exist in __init__ # 3. All arguments are constructed from validated internal state # 4. This is a controlled call to start the optiSLang application self.__process = subprocess.Popen( # nosec B603 args, env=env_vars, cwd=os.getcwd(), stderr=subprocess.PIPE if self.__log_process_stderr else subprocess.DEVNULL, stdout=subprocess.PIPE if self.__log_process_stdout else subprocess.DEVNULL, shell=False, creationflags=creation_flags, ) ``` -------------------------------- ### Add New Optimization Parameter Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Demonstrates how to create and add a new OptimizationParameter to the project's parameter manager. ```python # ... from ansys.optislang.core.project_parametric import OptimizationParameter new_parameter = OptimizationParameter( name="new_parameter", reference_value=2.5, range=(-5, 10) ) parameter_manager.add_parameter(new_parameter) ``` -------------------------------- ### server_info Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves general information about the optiSLang server. ```APIDOC ## server_info ### Description Retrieves general information about the optiSLang server. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.server_info() ``` ### Response General server information, such as version and build details. Specific fields are not detailed in the source. ``` -------------------------------- ### System Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/base_node_classes.rst Represents a system within the PyOptiLang structure. It inherits from Node and provides base functionality for systems. ```APIDOC ## System ### Description Represents a system within the PyOptiLang structure. It inherits from Node and provides base functionality for systems. ### Class System ``` -------------------------------- ### save_as Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Saves the current optiSLang project to a new file. This allows creating a copy or renaming the project. ```APIDOC ## save_as ### Description Saves the current optiSLang project to a new file. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Application Class Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/application.rst The Application class provides access to the OptiLang application instance. It serves as the main entry point for interacting with the OptiLang solver and its functionalities. ```APIDOC ## Application Class ### Description The Application class is the primary interface for controlling and interacting with the OptiLang application. It allows users to manage the solver, load/save projects, and access various functionalities. ### Methods - **__init__(self, solver_instance)**: Initializes the Application object with a given solver instance. - **load_project(self, project_path)**: Loads an OptiLang project from the specified file path. - **save_project(self, project_path)**: Saves the current OptiLang project to the specified file path. - **solve(self)**: Executes the optimization process. - **get_solver_instance(self)**: Returns the underlying solver instance. ### Properties - **project_path**: The current path of the loaded project. - **solver**: The solver instance associated with the application. ``` -------------------------------- ### Helper Functions Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/design_study_templates.rst Provides helper functions for navigating and interacting with OptiSLang, such as navigating to the OptiSLang environment. ```APIDOC ## Helper Functions ### Description Provides helper functions for navigating and interacting with OptiSLang, such as navigating to the OptiSLang environment. ### Available Functions: - go_to_optislang ``` -------------------------------- ### Traverse Project Node Structure Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/project_content.rst Illustrates how to recursively process all nodes within a project's system hierarchy, printing information about each node. ```python # ... def print_node_info(node): name = node.get_name() type_ = node.get_type() status = node.get_status() print(name, type_, status) def process_nodes(nodes): for node in nodes: print_node_info(node) if isinstance(node, System): process_nodes(node.get_nodes()) root_system = project.root_system nodes = root_system.get_nodes() process_nodes(nodes) ``` -------------------------------- ### Secure Local Communication (Default) Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/security_considerations.rst This snippet demonstrates the default secure local domain communication. No explicit configuration is needed as it is the recommended and most secure option for local use. ```python from ansys.optislang.core import Optislang # Default: Secure local domain communication (recommended) osl = Optislang() ``` -------------------------------- ### Keep Optislang Server Running with dispose() Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Use only the dispose() method to keep the optiSLang server running after the Optislang instance is no longer in use. This is applicable when the instance is initialized with shutdown_on_finished=False. ```python from ansys.optislang.core import Optislang osl = Optislang(shutdown_on_finished=False) print(osl) osl.dispose() ``` -------------------------------- ### Connect to Remote OptiSLang Instance by Host and Port Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/launch.rst Connects to a running OptiSLang instance on a specified host and port. This is used for remote connections to an OptiSLang server. ```python from ansys.optislang.core import Optislang host = "127.0.0.1" # specify host port = 5310 # specify port osl = Optislang(host=host, port=port) print(osl) osl.dispose() ``` -------------------------------- ### RootSystem Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/base_node_classes.rst Represents the root system of a PyOptiLang model. It inherits from ParametricSystem and typically serves as the entry point for the system hierarchy. ```APIDOC ## RootSystem ### Description Represents the root system of a PyOptiLang model. It inherits from ParametricSystem and typically serves as the entry point for the system hierarchy. ### Class RootSystem ``` -------------------------------- ### server_is_alive Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Checks if the optiSLang server is currently running and responsive. ```APIDOC ## server_is_alive ### Description Checks if the optiSLang server is currently running and responsive. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.server_is_alive() ``` ### Response A boolean value indicating whether the server is alive (True) or not (False). ``` -------------------------------- ### Create a Sensitivity Node Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/create_workflow.rst Creates a new Sensitivity node using the create_node method and a predefined node type constant. Ensure Optislang and necessary node types are imported. ```python from ansys.optislang.core import Optislang from ansys.optislang.core.nodes import DesignFlow import ansys.optislang.core.node_types as node_types osl = Optislang() root_system = osl.application.project.root_system sensitivity = root_system.create_node( type_=node_types.Sensitivity, ) ``` -------------------------------- ### Save Project Using save_as Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/functions.rst Saves the current project to a specified path using the save_as method. This is useful for preserving the project state. ```python from pathlib import Path project_path = Path().cwd() / "test_project.opf" osl.application.save_as(project_path) ``` -------------------------------- ### Modify Placeholder Configuration and Set Value Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/placeholders_howto.rst Updates an existing placeholder's configuration, such as its description or value, by overwriting it. Also shows how to specifically set a placeholder's value. ```python # Modify one or multiple configuration entries of a placeholder osl.project.create_placeholder( placeholder_id="global_max_parallel", value=18, description="Adapted description for maximum number of parallel executions", overwrite=True, ) # Set a placeholder value specifically osl.project.set_placeholder_value("thickness", 7.5) ``` -------------------------------- ### System Settings Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/design_study_templates.rst Provides access to system settings for parametric studies, including general parametric system settings and general algorithm settings. ```APIDOC ## System Settings ### Description Provides access to system settings for parametric studies, including general parametric system settings and general algorithm settings. ### Available Classes: - GeneralParametricSystemSettings - GeneralAlgorithmSettings ``` -------------------------------- ### basic_project_info Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves basic information about the current project. ```APIDOC ## basic_project_info ### Description Retrieves basic information about the current project on the optiSLang server. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.basic_project_info() ``` ### Response Basic project information, such as project name and ID. Specific fields are not detailed in the source. ``` -------------------------------- ### project_tree_systems_with_properties Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves the project tree structure focusing on systems, including their properties. ```APIDOC ## project_tree_systems_with_properties ### Description Retrieves the project tree structure, focusing on systems and including their associated properties, from the optiSLang server. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.project_tree_systems_with_properties() ``` ### Response The hierarchical structure of the project's systems with their properties. Specific fields are not detailed in the source. ``` -------------------------------- ### show_dialog Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Displays a dialog box within the optiSLang GUI. This command is typically used for user interaction or to present information. ```APIDOC ## show_dialog ### Description Displays a dialog box within the optiSLang GUI. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### find_all_osl_exec Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/utils.rst Finds all available Optislang executables on the system. ```APIDOC ## find_all_osl_exec ### Description Finds all available Optislang executables on the system. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters None ### Request Example ```python from ansys.optislang.core import utils osl_executables = utils.find_all_osl_exec() print("Found Optislang executables:") for exec_path in osl_executables: print(f"- {exec_path}") ``` ### Response #### Success Response - **list[str]**: A list of absolute paths to found Optislang executables. #### Response Example ``` [ "/path/to/ansys/optislang/bin/osl", "/another/path/to/optislang/bin/osl" ] ``` ``` -------------------------------- ### Create Stand-alone Placeholders Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/placeholders_howto.rst Creates various types of stand-alone placeholders (real, string, integer) using the Project API. Ensure you have connected to optiSLang and imported necessary types. ```python from ansys.optislang.core import Optislang from ansys.optislang.core.placeholder_types import PlaceholderType, UserLevel # Connect to optiSLang osl = Optislang() # Create a real number placeholder for thickness thickness_id = osl.project.create_placeholder( value=5.0, placeholder_id="thickness", type_=PlaceholderType.REAL, user_level=UserLevel.COMPUTATION_ENGINEER, description="Plate thickness in mm", ) # Create a string placeholder for material name material_id = osl.project.create_placeholder( value="Steel", placeholder_id="material_name", type_=PlaceholderType.STRING, user_level=UserLevel.FLOW_ENGINEER, description="Material name", ) # Create an integer placeholder for maximum number of parallel executions global_max_parallel_id = osl.project.create_placeholder( value=8, placeholder_id="global_max_parallel", type_=PlaceholderType.UINT, user_level=UserLevel.FLOW_ENGINEER, description="Maximum number of parallel executions", ) ``` -------------------------------- ### File Class Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/utils.rst Represents a file within the Optislang environment. ```APIDOC ## File Class ### Description Base class for representing files in the Optislang environment. It provides a common interface for file operations. ### Usage This is a base class and is typically subclassed by more specific file types like `RegisteredFile`. ``` -------------------------------- ### full_project_status_info Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves comprehensive status information for the entire project. ```APIDOC ## full_project_status_info ### Description Retrieves comprehensive status information for the entire project on the optiSLang server. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.full_project_status_info() ``` ### Response Detailed status information for the project, including statuses of all actors and components. Specific fields are not detailed in the source. ``` -------------------------------- ### Import subprocess with Inline Exclusion Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/user_guide/security_considerations.rst Demonstrates how to import the subprocess module with an inline exclusion comment for security vulnerability scanning tools like Bandit. ```python # Subprocess is required for legitimate optiSLang process management. # All arguments are validated and shell=False is enforced. See security audit in __start_in_python. import subprocess # nosec B404 ``` -------------------------------- ### full_project_tree Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves the complete project tree structure. ```APIDOC ## full_project_tree ### Description Retrieves the complete project tree structure from the optiSLang server. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.full_project_tree() ``` ### Response The hierarchical structure of the project. Specific fields are not detailed in the source. ``` -------------------------------- ### save Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Saves the current state of the optiSLang project. This command overwrites the existing project file. ```APIDOC ## save ### Description Saves the current state of the optiSLang project. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### get_osl_exec Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/utils.rst Retrieves the path to the Optislang executable. ```APIDOC ## get_osl_exec ### Description Retrieves the path to the Optislang executable. ### Method Not applicable (Python function) ### Endpoint Not applicable (Python function) ### Parameters None ### Request Example ```python from ansys.optislang.core import utils osl_exec_path = utils.get_osl_exec() print(f"Optislang executable path: {osl_exec_path}") ``` ### Response #### Success Response - **str**: The absolute path to the Optislang executable. #### Response Example ``` "/path/to/ansys/optislang/bin/osl" ``` ``` -------------------------------- ### full_project_tree_with_properties Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves the complete project tree structure along with properties for each element. ```APIDOC ## full_project_tree_with_properties ### Description Retrieves the complete project tree structure, including properties for each element, from the optiSLang server. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.full_project_tree_with_properties() ``` ### Response The hierarchical structure of the project with associated properties. Specific fields are not detailed in the source. ``` -------------------------------- ### Project Class Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/project.rst The Project class provides an interface to interact with OptiSLang projects. It allows users to create, load, save, and manage project-related operations. ```APIDOC ## Project Class ### Description Represents and manages an OptiSLang project. ### Methods * **__init__(self, project_path=None, read_only=False)**: Initializes a new Project instance. Can load an existing project from `project_path` or create a new one. * **load(self, project_path)**: Loads an existing OptiSLang project from the specified path. * **save(self, project_path=None)**: Saves the current project. If `project_path` is provided, it saves to that path; otherwise, it saves to the project's current path. * **close(self)**: Closes the current project, releasing associated resources. * **create_design(self, design_name)**: Creates a new design within the project. * **get_design(self, design_name)**: Retrieves an existing design from the project. * **delete_design(self, design_name)**: Deletes a design from the project. * **get_designs(self)**: Returns a list of all design names in the project. * **add_design_variable(self, design_name, variable_name, variable_type, lower_bound, upper_bound)**: Adds a design variable to a specified design. * **get_design_variable(self, design_name, variable_name)**: Retrieves a specific design variable. * **delete_design_variable(self, design_name, variable_name)**: Deletes a design variable from a specified design. * **add_objective(self, design_name, objective_name, expression)**: Adds an objective function to a specified design. * **get_objective(self, design_name, objective_name)**: Retrieves a specific objective function. * **delete_objective(self, design_name, objective_name)**: Deletes an objective function from a specified design. * **add_constraint(self, design_name, constraint_name, expression)**: Adds a constraint to a specified design. * **get_constraint(self, design_name, constraint_name)**: Retrieves a specific constraint. * **delete_constraint(self, design_name, constraint_name)**: Deletes a constraint from a specified design. * **run_simulation(self, design_name)**: Executes the simulation for a specified design. * **get_simulation_results(self, design_name)**: Retrieves the results of a simulation for a specified design. ### Parameters * **project_path** (str, optional): The file path to an existing OptiSLang project file (.slp). If not provided, a new project is created. * **read_only** (bool, optional): If True, the project is opened in read-only mode. Defaults to False. * **design_name** (str): The name of the design. * **variable_name** (str): The name of the design variable. * **variable_type** (str): The type of the design variable (e.g., 'double', 'integer'). * **lower_bound** (float): The lower bound for the design variable. * **upper_bound** (float): The upper bound for the design variable. * **objective_name** (str): The name of the objective function. * **expression** (str): The mathematical expression defining the objective function. * **constraint_name** (str): The name of the constraint. * **constraint_expression** (str): The mathematical expression defining the constraint. ### Returns * The `Project` object itself for chained operations. * `Design` object for `get_design`. * List of strings for `get_designs`. * `DesignVariable` object for `get_design_variable`. * `Objective` object for `get_objective`. * `Constraint` object for `get_constraint`. * Simulation results data structure for `get_simulation_results`. ### Example ```python from ansys.optislang.core.project import Project # Create a new project project = Project() # Add a design design = project.create_design("MyDesign") # Add a design variable project.add_design_variable("MyDesign", "x1", "double", 0.0, 10.0) # Add an objective project.add_objective("MyDesign", "obj1", "x1 * x1") # Save the project project.save("my_project.slp") # Load an existing project loaded_project = Project(project_path="my_project.slp") # Close the project project.close() loaded_project.close() ``` ``` -------------------------------- ### project_tree_systems Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_queries.rst Retrieves the project tree structure, focusing on systems. ```APIDOC ## project_tree_systems ### Description Retrieves the project tree structure from the optiSLang server, with a focus on systems. ### Method Not specified (assumed to be a function call within the SDK) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented for this function signature. ### Request Example ```python # Example usage within the Python SDK optislang_client.server_queries.project_tree_systems() ``` ### Response The hierarchical structure of the project, emphasizing systems. Specific fields are not detailed in the source. ``` -------------------------------- ### Node Settings Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/design_study_templates.rst Provides access to various node settings for design studies, including general, MOP solver, proxy solver, and Python solver settings. ```APIDOC ## Node Settings ### Description Provides access to various node settings for design studies, including general, MOP solver, proxy solver, and Python solver settings. ### Available Classes: - GeneralNodeSettings - MopSolverNodeSettings - ProxySolverNodeSettings - PythonSolverNodeSettings ``` -------------------------------- ### restart Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Restarts the optiSLang server or the current simulation process. This can be used to recover from errors or to re-initialize the system. ```APIDOC ## restart ### Description Restarts the optiSLang server or the current simulation process. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### close Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Closes the current optiSLang project. This command should be used with caution as it may discard unsaved changes. ```APIDOC ## close ### Description Closes the current optiSLang project. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### ProjectRelativePath Class Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/utils.rst Represents a path relative to the Optislang project directory. ```APIDOC ## ProjectRelativePath Class ### Description Represents a path that is relative to the root directory of the Optislang project. Inherits from `OptislangPathType`. ### Usage Ideal for referencing files that are part of the project structure, ensuring portability. ``` -------------------------------- ### save_copy Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/osl_server_api/optislang_server_commands.rst Saves a copy of the current optiSLang project. This is similar to 'save_as' but specifically implies creating a backup or duplicate. ```APIDOC ## save_copy ### Description Saves a copy of the current optiSLang project. ### Method (Not specified in source) ### Endpoint (Not specified in source) ### Parameters (No parameters explicitly documented) ### Request Example (No request example provided) ### Response (No response details provided) ``` -------------------------------- ### Default Log Output Format Source: https://github.com/ansys/pyoptislang/blob/main/doc/source/api/logging.rst Shows the default format of log messages generated by PyOptiSLang, including session information and detailed event logs. ```bash =============================================================================== NEW SESSION - 08/26/2022, 10:02:25 =============================================================================== LEVEL - MODULE - CLASS - FUNCTION - MESSAGE INFO - osl_process - optiSLang_2827215940360 - __init__ - optiSLang executable has been found for version 222 on path: C:\\Program Files\\ANSYS Inc\\v222\\optiSLang\\optislang.com INFO - tcp_osl_server - optiSLang_2827215940360 - __listen_port - optiSLang server port has been received: 5310 INFO - tcp_osl_server - optiSLang_2827215940360 - connect - Connection has been established to host 127.0.0.1 and port 5310. INFO - tmp1 - optiSLang_2827215940360 - - This is an useful message ```