launch_mapdl_process#
- ansys.mapdl.core.launcher.launch_mapdl_process(exec_file=None, run_location=None, jobname='file', *, nproc=None, port=None, ip=None, mode=None, version=None, start_instance=None, ram=None, timeout=None, cleanup_on_exit=True, clear_on_connect=True, override=False, remove_temp_dir_on_exit=False, set_no_abort=True, additional_switches='', license_type=None, launch_on_hpc=False, running_on_hpc=False, scheduler_options=None, loglevel='ERROR', log_apdl=None, print_com=False, mapdl_output=None, transport_mode=None, uds_dir=None, uds_id=None, certs_dir=None, add_env_vars=None, replace_env_vars=None, license_server_check=False, force_intel=False, graphics_backend=None, start_timeout=None, **kwargs)#
Launch MAPDL process and return connection info without creating client.
This is the specialized entry point for CLI and programmatic use cases that need the process to be launched without immediately creating a client connection. Unlike
launch_mapdl(), this function: :rtype:tuple[str,int,Optional[int]]Does NOT connect to an existing instance
Returns connection info tuple
(ip, port, pid)instead of a clientDoes NOT create a client object
Requires
start_instance=True
This function is primarily used by the CLI to launch MAPDL without creating a client connection. The caller is responsible for managing the launched process lifecycle.
- Parameters:
- exec_file
Optional[str] The location of the MAPDL executable. For instance, on Windows:
C:\Program Files\ANSYS Inc\v252\ansys\bin\mapdl.exe
And on Linux:
/usr/ansys_inc/v252/ansys/bin/mapdl
By default (
None), uses the cached location unless the environment variablePYMAPDL_MAPDL_EXECis set.- run_location
Optional[str] MAPDL working directory. If the directory doesn’t exist, one is created. Defaults to a temporary working directory with name
'ansys_'and a random string.- jobname
str MAPDL jobname. Defaults to
'file'.- nproc
Optional[int] Number of processors. If running on an HPC cluster, adjusted to allocated CPUs unless
running_on_hpc=False. Defaults to2CPUs.- port
Optional[int] Port for MAPDL gRPC. Can be set via
PYMAPDL_PORT. Argument has precedence. Defaults to50052.- ip
Optional[str] IP address to bind MAPDL to. For HPC, typically left empty. Defaults to
'127.0.0.1'.- mode
Optional[str] Launch mode. Options:
'grpc'- Recommended for ANSYS 2021R1 or newer'console'- Legacy console mode, Linux only (not recommended)
This parameter is largely ignored as gRPC is enforced.
- version
Optional[int] MAPDL version to launch. Can be provided as integers (
version=222) or floats (version=22.2). Can be set via environment variablePYMAPDL_MAPDL_VERSION. Defaults to latest installed version.- start_instance
Optional[bool] MUST be :class:`True` for this function. This function always requires launching a new instance. Can be set via environment variable
PYMAPDL_START_INSTANCE. Defaults toTrue.- ram
Optional[int] Total workspace (memory) in megabytes. Negative number forces fixed size. Defaults to
None(2048 MB).- timeout
Optional[int] Maximum time to connect to MAPDL server in seconds. Defaults to 45 seconds (90 seconds on HPC).
- cleanup_on_exitbool
Exit MAPDL when Python exits. Defaults to
True.- clear_on_connectbool
Provide fresh environment when connecting. Defaults to
True.- overridebool
Delete lock file at
run_locationif it exists. Defaults toFalse.- remove_temp_dir_on_exitbool
Delete temporary directory when exiting. Defaults to
False. Not available on HPC.- set_no_abortbool
Do not abort at first error in /BATCH mode. (Development use only). Defaults to
True.- additional_switches
str Additional MAPDL command-line switches. Avoid
-i,-o,-b. Examples:'-smp','-dmp','-mpi intelmpi'. Defaults to empty string.- license_type
Optional[str] License type to request (e.g.,
'meba','ansys'). Defaults toNone(server decides).- launch_on_hpcbool
Launch on HPC cluster using SLURM scheduler. Defaults to
False.- running_on_hpcbool
Whether to detect if running on HPC cluster. Can override with
PYMAPDL_RUNNING_ON_HPC. Defaults toFalse.- scheduler_options
Optional[Dict[str,Any]] HPC scheduler options. Example:
{"nodes": "2", "ntasks-per-node": "8"}- loglevel
str PyMAPDL logging level:
'DEBUG','INFO','WARNING','ERROR'. Defaults to'ERROR'.- log_apdl
Optional[str] Log APDL commands to file. Path or
Truefor'apdl.log'. Defaults toNone(disabled).- print_combool
Print
/COMcommand arguments. Defaults toFalse.- mapdl_output
Optional[str] Redirect MAPDL console output to file. Useful for debugging. Defaults to
None(not redirected).- transport_mode
Optional[str] gRPC transport mode:
'insecure','uds','wnua','mtls'. Defaults toNone(auto-select).- uds_dir
Optional[str] Directory for Unix Domain Socket (UDS) files. Defaults to
None(~/.conn).- uds_id
Optional[str] Identifier for UDS socket file. Defaults to
None(mapdl-{port}).- certs_dir
Optional[str] Directory with certificates for
'mtls'transport. Defaults toNone.- add_env_vars
Optional[Dict[str,str]] Environment variables to add. Extends system environment. Defaults to
None.- replace_env_vars
Optional[Dict[str,str]] Environment variables to replace system ones.
Warning
Use with caution. Replaces ALL system environment variables including MPI and license-related ones. Manually inject if needed.
Defaults to
None(uses system environment).- license_server_checkbool
Check license server availability on MAPDL startup failure. Only on
mode='grpc'. Defaults toFalse.- force_intelbool
Force Intel MPI for ANSYS 2021R0-2022R2. (Development use only). Defaults to
False.- graphics_backend
Optional[str] Graphics backend to use. Defaults to
None.- start_timeout
Optional[int] Deprecated. Use ``timeout`` instead.
- **kwargs
Any Additional arguments. Unknown arguments generate warnings.
- exec_file
- Returns:
- Raises:
ConfigurationErrorInvalid configuration or conflicting settings.
LaunchErrorLaunch failed or MAPDL failed to start.
Notes
This function is primarily used by the CLI to launch MAPDL without creating a client connection. The caller is responsible for:
Managing the launched process
Creating a client connection if needed
Cleaning up resources
For most use cases,
launch_mapdl()is recommended as it automatically creates and manages the client connection.Example CLI workflow:
>>> ip, port, pid = launch_mapdl_process(nproc=8) >>> # Pass connection info to other processes or store it >>> # When ready to connect: >>> from ansys.mapdl.core import launch_mapdl >>> mapdl = launch_mapdl(start_instance=False, ip=ip, port=port)
Examples
Launch MAPDL process and get connection info:
>>> from ansys.mapdl.core.launcher import launch_mapdl_process >>> ip, port, pid = launch_mapdl_process(nproc=4) >>> print(f"MAPDL listening at {ip}:{port} (PID: {pid})") MAPDL listening at 127.0.0.1:50052 (PID: 12345)
Use with specific version and switches:
>>> ip, port, pid = launch_mapdl_process( ... version=222, ... nproc=4, ... additional_switches='-smp' ... )
Launch on HPC and get connection info:
>>> ip, port, pid = launch_mapdl_process( ... launch_on_hpc=True, ... nproc=16, ... scheduler_options={'nodes': '2', 'ntasks-per-node': '8'} ... )