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:
- host
Optional
[str
],optional
A string representation of an IPv4/v6 address or domain name of running optiSLang server. Defaults to
None
.- port
Optional
[int
],optional
A numeric port number of running optiSLang server. Defaults to
None
.- executable
Optional
[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_path
Optional
[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 toFalse
. Defaults toFalse
...note:: Cannot be used in combination with batch mode.
- port_range
Optional
[Tuple
[int
,int
]],optional
Defines the port range for optiSLang server. Defaults to
None
.- no_run
Optional
[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_id
Optional
[str
],optional
Specific unique ID for the TCP listener. Defaults to
None
.- multi_listener
Optional
[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_timeout
float
,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.
- password
Optional
[str
],optional
The server password. Use when communication with the server requires the request to contain a password entry. Defaults to
None
.- logger
Optional
[Any
],optional
Object for logging. If
None
, standard logging object is used. Defaults toNone
.- 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_vars
Optional
[Mapping
[str
,str
]],optional
Additional environmental variables (key and value) for the optiSLang server process. Defaults to
None
.- import_project_properties_file
Optional
[Union
[str
,pathlib.Path
]],optional
Optional path to a project properties file to import. Defaults to
None
.- export_project_properties_file
Optional
[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_file
Optional
[Union
[str
,pathlib.Path
]],optional
Optional path to a placeholders file to import. Defaults to
None
.- export_placeholders_file
Optional
[Union
[str
,pathlib.Path
]],optional
Optional path to a placeholders file to export. Defaults to
None
.Note
Only supported in batch mode.
- output_file
Optional
[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_state
Optional
[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_file
Optional
[Union
[str
,pathlib.Path
]],optional
Optional path to an OPX project definition file. Defaults to
None
.Note
Only supported in batch mode.
- additional_args
Optional
[Iterable
[str
]],optional
Additional command line arguments used for execution of the optiSLang server process. Defaults to
None
.
- host
- 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.
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.
Get currently registered internal variables for a certain (integration) actor.
Get properties of actor defined by uid.
Get currently registered input slots for a certain (integration) actor.
Get currently registered output slots for a certain (integration) actor.
Get currently registered parameters for a certain (integration) actor.
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.
Get available input locations for a certain (integration) actor, if supported.
Get available node types for current oSL server.
Get available output locations for a certain (integration) actor, if supported.
Get basic project info, like name, location, global settings and status.
Get information about all existing criterion from the system.
TcpOslServer.get_criterion
(uid, name)Get existing criterion from the system.
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.
Get full project status info.
Get full project tree.
Get full project tree with properties.
Get full status info for a sub tree.
Get optiSLang server address or domain name.
Get hpc licensing forwarded environment for certain actor.
TcpOslServer.get_input_slot_value
(uid, hid, ...)Get input slot value of actor defined by uid.
Get version of used optiSLang.
Get version of used optiSLang.
TcpOslServer.get_output_slot_value
(uid, hid, ...)Get output slot value of actor defined by uid.
Get the port the osl server is listening on.
Get description of optiSLang project.
Get path to the optiSLang project file.
Get name of the optiSLang project.
Get status of the optiSLang project.
Get project tree systems without properties.
Get project tree systems with properties.
Get project uid.
TcpOslServer.get_result_design
(uid, design_id)Get specific result design values defined by actor uid and design ID.
Get information about the application, the server configuration and the open projects.
Get info whether the server is alive.
Get project status info, including systems only.
Get current timeout value for execution of commands.
Get path to the optiSLang project working directory.
TcpOslServer.load
(uid[, args])Explicit load of node.
Create a new project.
TcpOslServer.open
(file_path[, force, ...])Open a new project.
Adjust all input locations with the already registered parameters.
Adjust all input locations with the already registered responses.
Register a certain (input) location as a input slot.
Register a certain (output) location as an internal variable.
Register a certain (output) location as a output slot.
Register a certain (input) location as a parameter.
Register a certain (output) location as a response.
Register all input locations as parameters initially.
Registration of all input locations as responses initially.
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.
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
Get optiSLang server address or domain name.
Determines whether the optiSLang server does not run on localhost.
Register with maximum number of attempts to be executed for individual functions.
Version of used optiSLang.
Version of used optiSLang.
Get the port the osl server is listening on.
Get default timeout value for execution of commands.
Register with timeout for a single attempt of execution for individual functions.