`start_instance` set silently to `False` when using `PYMAPDL_IP` env var
germa89 opened this issue · comments
Current behaviour
If the env var PYMAPDL_IP
is set, the start_instance
is set to False
silently. Because PyMAPDL assumes that if you are using an IP, you are not launching MAPDL, just connecting to a remote instance. If you were going to connect to a local instance, already launched, the natural choice is to set start_instance
to False
, such as:
mapdl = launch_mapdl(start_instance=False, port=50052) # port is optional
WSL edge case
When working on WSL (MAPDL installed in Windows, and PyMAPDL running on WSL), you can have a bit of a contradicting case, where you need to launch MAPDL in another IP.
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl(
exec_file="/mnt/c/Program Files/ANSYS Inc/v231/ANSYS/bin/winx64/ANSYS231.exe",
)
For more info check: https://mapdl.docs.pyansys.com/version/stable/getting_started/wsl.html#launch-mapdl-in-the-windows-host-os
Internally, PyMAPDL sets start_instance
equal to
Issues
Clearly, setting the start_instance
to False
silently is a problem. PyMAPDL should be more explicit.
Options
Option A:
Raise an exception.
If PYMAPDL_IP
is used and start_instance=True
is passed to launch_mapdl
or the env var PYMAPDL_START_INSTANCE
is present.
Option B:
Just print a warning, it makes sense if you are using PYMAPDL_IP
you want to connect.
Option C:
If you are using start_instance=True
is clear you want to start PyMAPDL, forget about the PyMAPDL_IP
env var.
Option D:
Dont assume the start instance is False
Collorary
What should the expected output from this code:
mapdl = launch_mapdl(start_instance=True, ip="127.2.0.12")
should it raise an exception? should it connect to the given instance IP?
TL,DR
Which should have priority and override the other arguments?
a) Env vars have the priority
b) The script arguments (i.e. launch_mapdl(start_instance=False)
)
While writing this issue I realised what the right behaviour:
Solution
Regarding parameters/env var conflict
If both env vars or arguments are given:
export PYMAPDL_START_INSTANCE=True
export PYMAPDL_IP="123.11.22.33"
python my_script.py
or
mapdl = launch_mapdl(start_instance=True, ip="12.22.33.44") # and not on WSL
then, PyMAPDL will raise an exception. I think this is a consistent behaviour.
Priority
The priority should be given to the env vars.
This was an stupid question, CICD depends on this.