The ``launcher.py`` module
==========================
.. py:module:: ansys.dyna.core.solver.launcher
Summary
-------
.. py:currentmodule:: launcher
.. tab-set::
.. tab-item:: Classes
.. list-table::
:header-rows: 0
:widths: auto
* - :py:obj:`~ansys.dyna.core.solver.launcher.ServerThread`
- Provides server thread properties.
.. tab-item:: Functions
.. list-table::
:header-rows: 0
:widths: auto
* - :py:obj:`~check_ports`
- Check the state of ports in a port range.
* - :py:obj:`~port_in_use`
- Determine if a port is in use at a given host.
* - :py:obj:`~launch_grpc`
- Launch the solver service locally in gRPC mode.
* - :py:obj:`~launch_remote_dyna`
- Start DYNA remotely using the product instance management API.
* - :py:obj:`~launch_dyna`
- Start DYNA locally.
.. tab-item:: Constants
.. list-table::
:header-rows: 0
:widths: auto
* - :py:obj:`~LOCALHOST`
-
* - :py:obj:`~DYNA_DEFAULT_PORT`
-
* - :py:obj:`~SERVER_SOLVER_VERSION`
-
* - :py:obj:`~MAX_MESSAGE_LENGTH`
-
.. toctree::
:titlesonly:
:maxdepth: 1
:hidden:
ServerThread
Description
-----------
Module for launching the pydyna solver service locally.
..
!! processed by numpydoc !!
Module detail
-------------
.. py:function:: check_ports(port_range, ip='localhost')
Check the state of ports in a port range.
:Parameters:
**port_range**
..
**ip** : :class:`python:str`, :obj:`optional`
IP address. The default is ``"localhost"``, in which case
``"127.0.0.1"``is used.
..
!! processed by numpydoc !!
.. py:function:: port_in_use(port, host=LOCALHOST)
Determine if a port is in use at a given host.
:Parameters:
**port** : :class:`python:int`
Port.
**host**
Host. The default is ``LOCALHOST``, in which case ``"127.0.0.1"``
is used.
:Returns:
``True`` :obj:`when` :obj:`a` :obj:`port` :obj:`is` :obj:`in` :obj:`use` :obj:`at` :obj:`the` :obj:`given` :obj:`host`, ``False`` otherwise.
..
.. rubric:: Notes
The port must "bind" the address. Just checking if a socket can be created
is insufficient because it is possible to run into permission
errors like this one:
"An attempt was made to access a socket in a way forbidden by its
access permissions."
..
!! processed by numpydoc !!
.. py:function:: launch_grpc(port=DYNA_DEFAULT_PORT, ip=LOCALHOST, server_path='', product_version=None) -> tuple
Launch the solver service locally in gRPC mode.
:Parameters:
**port** : :class:`python:int`, :obj:`optional`
Port to launch the solver service on. The default is ``DYNAPRE_DEFAULT_PORT``.
The final port is the first port available after (or including) this
port.
**ip** : :class:`python:str`, :obj:`optional`
IP address. The default is ``LOCALHOST``, in which case ``"127.0.0.1"``
is used.
**server_path** : :class:`python:str`, :obj:`optional`
Path to the solver service. The default is ``None``.
:Returns:
:class:`python:int`
Port number that the gRPC instance started on.
..
!! processed by numpydoc !!
.. py:function:: launch_remote_dyna(version=None, cleanup_on_exit=True) -> ansys.dyna.core.solver.DynaSolver
Start DYNA remotely using the product instance management API.
When calling this method, you need to ensure that you are in an environment where PyPIM is configured.
This can be verified with :func:`pypim.is_configured `.
:Parameters:
**version** : :class:`python:str`, :obj:`optional`
The DYNA version to run, in the 3 digits format, such as "212".
If unspecified, the version will be chosen by the server.
**cleanup_on_exit** : :ref:`bool `, :obj:`optional`
Exit DYNA when python exits or the dyna Python instance is
garbage collected.
If unspecified, it will be cleaned up.
:Returns:
:obj:`ansys.dyna.core.solver.DynaSolver`
An instance of DynaSolver.
..
!! processed by numpydoc !!
.. py:function:: launch_dyna(product_version: int = None, port=None, ip=None) -> ansys.dyna.core.solver.DynaSolver
Start DYNA locally.
:Parameters:
**product_version: int, optional**
The product version to be started. Goes from v20.1 to
the latest. Default is ``None``.
If a specific product version is requested but not installed locally,
a SystemError will be raised.
**Ansys products versions and their corresponding int values:**
* ``241`` : Ansys 24R1
* ``242`` : Ansys 24R2
**port** : :class:`python:int`
Port to launch DYNA gRPC on. Final port will be the first
port available after (or including) this port. Defaults to
5000.
**ip** : :ref:`bool `, :obj:`optional`
You can provide a hostname as an alternative to an IP address.
Defaults to ``'127.0.0.1'``.
.. rubric:: Examples
Launch DYNA using the best protocol.
>>> from ansys.dyna.core.solver import launch_dyna
>>> solution = launch_dyna()
Connect to an existing instance of DYNA at IP 192.168.1.30 and
port 5000.
>>> solution = launch_dyna(ip='192.168.1.30',port=5000)
..
!! processed by numpydoc !!
.. py:data:: LOCALHOST
:value: '127.0.0.1'
.. py:data:: DYNA_DEFAULT_PORT
:value: 5000
.. py:data:: SERVER_SOLVER_VERSION
:value: 'v0.4.13'
.. py:data:: MAX_MESSAGE_LENGTH
:value: 8388608