TcpOslServer#

class ansys.optislang.core.tcp.osl_server.TcpOslServer(host: str | None = None, port: int | None = None, executable: str | Path | None = None, project_path: str | Path | None = None, batch: bool = True, service: bool = False, port_range: Tuple[int, int] | None = None, no_run: bool | None = None, no_save: bool = False, force: bool = True, reset: bool = False, auto_relocate: bool = False, listener_id: str | None = None, multi_listener: Iterable[Tuple[str, int, str | None]] | None = None, ini_timeout: float = 60, password: str | None = None, logger: Any | None = None, shutdown_on_finished: bool = True, env_vars: Mapping[str, str] | None = None, import_project_properties_file: str | Path | None = None, export_project_properties_file: str | Path | None = None, import_placeholders_file: str | Path | None = None, export_placeholders_file: str | Path | None = None, output_file: str | Path | None = None, dump_project_state: str | Path | None = None, opx_project_definition_file: str | Path | None = None, additional_args: Iterable[str] | None = None)#

Class which provides access to optiSLang server using plain TCP/IP communication protocol.

TcpOslServer class provides explicit methods for accessing specific optiSLang API endpoints. Additionally, the generic send_command method can be used in conjunction with the convenience functions from the ansys.optislang.core.tcp.tcp_server_queries and ansys.optislang.core.tcp.tcp_server_commands modules.

For remote connection, it is assumed that the optiSLang server process is already running on remote (or local) host. In that case, the host and port must be specified and other parameters are ignored.

Parameters:
hostOptional[str], optional

A string representation of an IPv4/v6 address or domain name of running optiSLang server. Defaults to None.

portOptional[int], optional

A numeric port number of running optiSLang server. Defaults to None.

executableOptional[Union[str, pathlib.Path]], optional

Path to the optiSLang executable file which supposed to be executed on localhost. It is ignored when the host and port parameters are specified. Defaults to None.

project_pathOptional[Union[str, pathlib.Path]], optional

Path to the optiSLang project file which is supposed to be used by new local optiSLang server. It is ignored when the host and port parameters are specified. - If the project file exists, it is opened. - If the project file does not exist, a new project is created on the specified path. - If the path is None, a new project is created in the temporary directory. Defaults to None.

batchbool, optional

Determines whether to start optiSLang server in batch mode. Defaults to True.

..note:: Cannot be used in combination with service mode.

service: bool, optional

Determines whether to start optiSLang server in service mode. If True, batch argument is set to False. Defaults to False.

..note:: Cannot be used in combination with batch mode.

port_rangeOptional[Tuple[int, int]], optional

Defines the port range for optiSLang server. Defaults to None.

no_runOptional[bool], optional

Determines whether not to run the specified project when started in batch mode. Defaults to None.

Note

Only supported in batch mode.

no_savebool, optional

Determines whether not to save the specified project after all other actions are completed. It is ignored when the host and port parameters are specified. Defaults to False.

Note

Only supported in batch mode.

forcebool, optional

Determines whether to force opening/processing specified project when started in batch mode even if issues occur. Defaults to True.

Note

Only supported in batch mode.

resetbool, optional

Determines whether to reset specified project after load. Defaults to False.

Note

Only supported in batch mode.

auto_relocatebool, optional

Determines whether to automatically relocate missing file paths. Defaults to False.

Note

Only supported in batch mode.

listener_idOptional[str], optional

Specific unique ID for the TCP listener. Defaults to None.

multi_listenerOptional[Iterable[Tuple[str, int, Optional[str]]]], optional

Multiple remote listeners (plain TCP/IP based) to be registered at optiSLang server. Each listener is a combination of host, port and (optionally) listener ID. Defaults to None.

ini_timeoutfloat, optional

Time in seconds to listen to the optiSLang server port. If the port is not listened for specified time, the optiSLang server is not started and RuntimeError is raised. It is ignored when the host and port parameters are specified. Defaults to 20 s.

passwordOptional[str], optional

The server password. Use when communication with the server requires the request to contain a password entry. Defaults to None.

loggerOptional[Any], optional

Object for logging. If None, standard logging object is used. Defaults to None.

shutdown_on_finished: bool, optional

Shut down when execution is finished and there are not any listeners registered. It is ignored when the host and port parameters are specified. Defaults to True.

Note

Only supported in batch mode.

env_varsOptional[Mapping[str, str]], optional

Additional environmental variables (key and value) for the optiSLang server process. Defaults to None.

import_project_properties_fileOptional[Union[str, pathlib.Path]], optional

Optional path to a project properties file to import. Defaults to None.

export_project_properties_fileOptional[Union[str, pathlib.Path]], optional

Optional path to a project properties file to export. Defaults to None.

Note

Only supported in batch mode.

import_placeholders_fileOptional[Union[str, pathlib.Path]], optional

Optional path to a placeholders file to import. Defaults to None.

export_placeholders_fileOptional[Union[str, pathlib.Path]], optional

Optional path to a placeholders file to export. Defaults to None.

Note

Only supported in batch mode.

output_fileOptional[Union[str, pathlib.Path]], optional

Optional path to an output file for writing project run results to. Defaults to None.

Note

Only supported in batch mode.

dump_project_stateOptional[Union[str, pathlib.Path]], optional

Optional path to a project state dump file to export. If a relative path is provided, it is considered to be relative to the project working directory. Defaults to None.

Note

Only supported in batch mode.

opx_project_definition_fileOptional[Union[str, pathlib.Path]], optional

Optional path to an OPX project definition file. Defaults to None.

Note

Only supported in batch mode.

additional_argsOptional[Iterable[str]], optional

Additional command line arguments used for execution of the optiSLang server process. Defaults to None.

Raises:
RuntimeError

Port listener cannot be started. -or- optiSLang server port is not listened for specified timeout value.

Examples

Start local optiSLang server, get optiSLang version and shutdown the server.

>>> from ansys.optislang.core.tcp_osl_server import TcpOslServer
>>> osl_server = TcpOslServer()
>>> osl_version = osl_server.osl_version_string
>>> print(osl_version)
>>> osl_server.dispose()

Connect to the remote optiSLang server, get optiSLang version and shutdown the server.

>>> from ansys.optislang.core.tcp_osl_server import TcpOslServer
>>> host = "192.168.101.1"  # IP address of the remote host
>>> port = 49200            # Port of the remote optiSLang server
>>> osl_server = TcpOslServer(host, port)
>>> osl_version = osl_server.osl_version_string
>>> print(osl_version)
>>> osl_server.dispose()

Methods

TcpOslServer.add_criterion(uid, ...[, limit])

Create criterion for the system.

TcpOslServer.connect_nodes(from_actor_uid, ...)

Connect 2 nodes.

TcpOslServer.create_input_slot(actor_uid[, ...])

Create custom input slot.

TcpOslServer.create_node(type_[, name, ...])

Create a new node of given type.

TcpOslServer.create_output_slot(actor_uid[, ...])

Create custom output slot.

TcpOslServer.disconnect_slot(uid, slot_name, ...)

Remove all connections for a given slot.

TcpOslServer.dispose()

Terminate all local threads and unregister listeners.

TcpOslServer.evaluate_design(evaluate_dict)

Evaluate requested design.

TcpOslServer.get_actor_info(uid[, ...])

Get info about actor defined by uid.

TcpOslServer.get_actor_internal_variables(uid)

Get currently registered internal variables for a certain (integration) actor.

TcpOslServer.get_actor_properties(uid)

Get properties of actor defined by uid.

TcpOslServer.get_actor_registered_input_slots(uid)

Get currently registered input slots for a certain (integration) actor.

TcpOslServer.get_actor_registered_output_slots(uid)

Get currently registered output slots for a certain (integration) actor.

TcpOslServer.get_actor_registered_parameters(uid)

Get currently registered parameters for a certain (integration) actor.

TcpOslServer.get_actor_registered_responses(uid)

Get currently registered responses for a certain (integration) actor.

TcpOslServer.get_actor_states(uid[, ...])

Get available actor states for a certain actor.

TcpOslServer.get_actor_status_info(uid, hid)

Get status info about actor defined by actor uid and state Hid.

TcpOslServer.get_actor_supports(uid, ...)

Get supported features of actor defined by uid.

TcpOslServer.get_available_input_locations(uid)

Get available input locations for a certain (integration) actor, if supported.

TcpOslServer.get_available_nodes()

Get available node types for current oSL server.

TcpOslServer.get_available_output_locations(uid)

Get available output locations for a certain (integration) actor, if supported.

TcpOslServer.get_basic_project_info()

Get basic project info, like name, location, global settings and status.

TcpOslServer.get_criteria(uid)

Get information about all existing criterion from the system.

TcpOslServer.get_criterion(uid, name)

Get existing criterion from the system.

TcpOslServer.get_designs(uid)

Get pending designs from parent node.

TcpOslServer.get_doe_size(uid, ...)

Get the DOE size for given sampling type and number of levels for a specific actor.

TcpOslServer.get_full_project_status_info([...])

Get full project status info.

TcpOslServer.get_full_project_tree()

Get full project tree.

TcpOslServer.get_full_project_tree_with_properties()

Get full project tree with properties.

TcpOslServer.get_full_subtree_status_info(uid)

Get full status info for a sub tree.

TcpOslServer.get_host()

Get optiSLang server address or domain name.

TcpOslServer.get_hpc_licensing_forwarded_environment(uid)

Get hpc licensing forwarded environment for certain actor.

TcpOslServer.get_input_slot_value(uid, hid, ...)

Get input slot value of actor defined by uid.

TcpOslServer.get_osl_version()

Get version of used optiSLang.

TcpOslServer.get_osl_version_string()

Get version of used optiSLang.

TcpOslServer.get_output_slot_value(uid, hid, ...)

Get output slot value of actor defined by uid.

TcpOslServer.get_port()

Get the port the osl server is listening on.

TcpOslServer.get_project_description()

Get description of optiSLang project.

TcpOslServer.get_project_location()

Get path to the optiSLang project file.

TcpOslServer.get_project_name()

Get name of the optiSLang project.

TcpOslServer.get_project_status()

Get status of the optiSLang project.

TcpOslServer.get_project_tree_systems()

Get project tree systems without properties.

TcpOslServer.get_project_tree_systems_with_properties()

Get project tree systems with properties.

TcpOslServer.get_project_uid()

Get project uid.

TcpOslServer.get_result_design(uid, design_id)

Get specific result design values defined by actor uid and design ID.

TcpOslServer.get_server_info()

Get information about the application, the server configuration and the open projects.

TcpOslServer.get_server_is_alive()

Get info whether the server is alive.

TcpOslServer.get_systems_status_info([...])

Get project status info, including systems only.

TcpOslServer.get_timeout()

Get current timeout value for execution of commands.

TcpOslServer.get_working_dir()

Get path to the optiSLang project working directory.

TcpOslServer.load(uid[, args])

Explicit load of node.

TcpOslServer.new()

Create a new project.

TcpOslServer.open(file_path[, force, ...])

Open a new project.

TcpOslServer.re_register_locations_as_parameter(uid)

Adjust all input locations with the already registered parameters.

TcpOslServer.re_register_locations_as_response(uid)

Adjust all input locations with the already registered responses.

TcpOslServer.register_location_as_input_slot(...)

Register a certain (input) location as a input slot.

TcpOslServer.register_location_as_internal_variable(...)

Register a certain (output) location as an internal variable.

TcpOslServer.register_location_as_output_slot(...)

Register a certain (output) location as a output slot.

TcpOslServer.register_location_as_parameter(...)

Register a certain (input) location as a parameter.

TcpOslServer.register_location_as_response(...)

Register a certain (output) location as a response.

TcpOslServer.register_locations_as_parameter(uid)

Register all input locations as parameters initially.

TcpOslServer.register_locations_as_response(uid)

Registration of all input locations as responses initially.

TcpOslServer.remove_criteria(uid)

Remove all criteria from the system.

TcpOslServer.remove_criterion(uid, name)

Remove existing criterion from the system.

TcpOslServer.remove_node(actor_uid)

Remove node specified by uid.

TcpOslServer.reset([actor_uid, hid])

Reset complete project or a specific actor state.

TcpOslServer.run_python_file(file_path[, args])

Read python script from the file, load it in a project context and execute it.

TcpOslServer.run_python_script(script[, args])

Load a Python script in a project context and execute it.

TcpOslServer.save()

Save the changed data and settings of the current project.

TcpOslServer.save_as(file_path[, force, ...])

Save and open the current project at a new location.

TcpOslServer.save_copy(file_path)

Save the current project as a copy to a location.

TcpOslServer.send_command(command, **kwargs)

Send command or query to the optiSLang server.

TcpOslServer.set_actor_property(actor_uid, ...)

Set an actor property.

TcpOslServer.set_criterion_property(uid, ...)

Set the properties of existing criterion for the system.

TcpOslServer.set_designs(actor_uid, designs)

Set an actor property.

TcpOslServer.set_timeout([timeout])

Set timeout value for execution of commands.

TcpOslServer.shutdown([force])

Shutdown the optiSLang server.

TcpOslServer.start([wait_for_started, ...])

Start project execution.

TcpOslServer.stop([wait_for_finished])

Stop project execution.

Attributes

TcpOslServer.host

Get optiSLang server address or domain name.

TcpOslServer.is_remote

Determines whether the optiSLang server does not run on localhost.

TcpOslServer.max_request_attempts_register

Register with maximum number of attempts to be executed for individual functions.

TcpOslServer.osl_version

Version of used optiSLang.

TcpOslServer.osl_version_string

Version of used optiSLang.

TcpOslServer.port

Get the port the osl server is listening on.

TcpOslServer.timeout

Get default timeout value for execution of commands.

TcpOslServer.timeouts_register

Register with timeout for a single attempt of execution for individual functions.