Skip to content

When executing mapdl = launch_mapdl(), it doesn't work #1570

@kenandrn

Description

@kenandrn

Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment
  • I have a fully updated virtual environment (i.e. pip install --upgrade --upgrade-strategy eager ansys-mapdl-core)

Description of the bug

Unable to use pymapdl from python scripts

Steps To Reproduce

Steps:

  • First I ran the following code on jupyter lab:
from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
print(mapdl)

But it didn't work and I got the following error

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In [5], line 2
      1 from ansys.mapdl.core import launch_mapdl
----> 2 mapdl = launch_mapdl()
      3 print(mapdl)

File d:\○○\PyAnsys\lib\site-packages\ansys\mapdl\core\launcher.py:1657, in launch_mapdl(exec_file, run_location, jobname, nproc, ram, mode, override, loglevel, additional_switches, start_timeout, port, cleanup_on_exit, start_instance, ip, clear_on_connect, log_apdl, remove_temp_files, verbose_mapdl, license_server_check, license_type, print_com, add_env_vars, replace_env_vars, **kwargs)
   1654     if license_server_check:
   1655         lic_check.check()
-> 1657     raise exception
   1659 return mapdl

File d:\○○\PyAnsys\lib\site-packages\ansys\mapdl\core\launcher.py:1639, in launch_mapdl(exec_file, run_location, jobname, nproc, ram, mode, override, loglevel, additional_switches, start_timeout, port, cleanup_on_exit, start_instance, ip, clear_on_connect, log_apdl, remove_temp_files, verbose_mapdl, license_server_check, license_type, print_com, add_env_vars, replace_env_vars, **kwargs)
   1630 elif mode == "grpc":
   1631     port, actual_run_location = launch_grpc(
   1632         port=port,
   1633         verbose=verbose_mapdl,
   (...)
   1637         **start_parm,
   1638     )
-> 1639     mapdl = MapdlGrpc(
   1640         ip=ip,
   1641         port=port,
   1642         cleanup_on_exit=cleanup_on_exit,
   1643         loglevel=loglevel,
   1644         set_no_abort=set_no_abort,
   1645         remove_temp_files=remove_temp_files,
   1646         log_apdl=log_apdl,
   1647         **start_parm,
   1648     )
   1649     if run_location is None:
   1650         mapdl._path = actual_run_location

File d:\○○\PyAnsys\lib\site-packages\ansys\mapdl\core\mapdl_grpc.py:356, in MapdlGrpc.__init__(self, ip, port, timeout, loglevel, log_file, cleanup_on_exit, log_apdl, set_no_abort, remove_temp_files, print_com, channel, remote_instance, **start_parm)
    353     self._channel = channel
    355 # connect and validate to the channel
--> 356 self._multi_connect(timeout=timeout)
    358 # double check we have access to the local path if not
    359 # explicitly specified
    360 if "local" not in start_parm:

File d:\○○\PyAnsys\lib\site-packages\ansys\mapdl\core\mapdl_grpc.py:418, in MapdlGrpc._multi_connect(self, n_attempts, timeout, set_no_abort)
    411     self._log.debug(
    412         "Reached either maximum amount of connection attempts (%d) or timeout (%f s).",
    413         n_attempts,
    414         timeout,
    415     )
    417 if not connected:
--> 418     raise IOError(
    419         f"Unable to connect to MAPDL gRPC instance at {self._channel_str}"
    420     )

OSError: Unable to connect to MAPDL gRPC instance at 127.0.0.1:50052

But APDL is runnning in the background at this time. I can confirm APDL running by task manager.

So I shutdown the APDL by task manager.

Steps:
・Secondly, I tried launching APDL in gRPC mode on command prompt using the steps in below links
https://mapdldocs.pyansys.com/getting_started/running_mapdl.html#launching-a-grpc-mapdl-session

APDL started without problems and the following message appeared in the Mechanical APDL 2021 R2 Output Window

Start GRPC Server

##############################
### START GRPC SERVER      ###
##############################

Server Executable   : MapdlGrpc Server
Server listening on : 0.0.0.0:50052

While keeping the APDL in gRPC mode, I tried the following codes on the jupyter lab, but I got error.

from ansys.mapdl.core import Mapdl
ip = 'using PC's IP'
mapdl = Mapdl(ip=ip, port=50052)
print(mapdl)
# Insert your code here

Error

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In [6], line 3
      1 from ansys.mapdl.core import Mapdl
      2 ip = 'using PC's IP address'
----> 3 mapdl = Mapdl(ip=ip, port=50052)
      4 print(mapdl)

File d:\○○\PyAnsys\lib\site-packages\ansys\mapdl\core\mapdl_grpc.py:356, in MapdlGrpc.__init__(self, ip, port, timeout, loglevel, log_file, cleanup_on_exit, log_apdl, set_no_abort, remove_temp_files, print_com, channel, remote_instance, **start_parm)
    353     self._channel = channel
    355 # connect and validate to the channel
--> 356 self._multi_connect(timeout=timeout)
    358 # double check we have access to the local path if not
    359 # explicitly specified
    360 if "local" not in start_parm:

File d:\○○\PyAnsys\lib\site-packages\ansys\mapdl\core\mapdl_grpc.py:418, in MapdlGrpc._multi_connect(self, n_attempts, timeout, set_no_abort)
    411     self._log.debug(
    412         "Reached either maximum amount of connection attempts (%d) or timeout (%f s).",
    413         n_attempts,
    414         timeout,
    415     )
    417 if not connected:
--> 418     raise IOError(
    419         f"Unable to connect to MAPDL gRPC instance at {self._channel_str}"
    420     )

OSError: Unable to connect to MAPDL gRPC instance at using PC's IP:50052

The results of the execution of the following code are appended.

from ansys.mapdl import core as pymapdl; print(pymapdl.Report())
-------------------------------------------------------------------------------


PyMAPDL Software and Environment Report


Packages Requirements
*********************

Core packages
-------------
ansys.mapdl.core    : 0.63.3
numpy               : 1.23.4
appdirs             : 1.4.4
scipy               : 1.9.2
grpc                : Package not found
ansys.api.mapdl.v0  : Package not found
ansys.mapdl.reader  : 0.52.2
google.protobuf     : Package not found

Optional packages
-----------------
matplotlib          : 3.6.1
pyvista             : 0.36.1
pyiges              : 0.2.1
tqdm                : 4.64.1


Ansys Installation
******************
Version   Location
------------------
212       C:\Program Files\ANSYS Inc\v212


Ansys Environment Variables
***************************
ANSYS212_DIR                   C:\Program Files\ANSYS Inc\v212\ANSYS
AWP_LOCALE212                  ja
AWP_ROOT212                    C:\Program Files\ANSYS Inc\v212
CADOE_LIBDIR212                C:\Program Files\ANSYS Inc\v212\CommonFiles\Language\ja

Which Operating System are you using?

Windows

Which Python version are you using?

3.9

PyMAPDL Report

Show the Report!
The error masseges are attached above.

Installed packages

Show the installed packages!

aiohttp==3.8.3
aiosignal==1.2.0
ansys-api-mapdl==0.5.1
ansys-api-platform-instancemanagement==1.0.0b3
ansys-mapdl-core==0.63.3
ansys-mapdl-reader==0.52.2
ansys-platform-instancemanagement==1.0.2
anyio==3.6.2
appdirs==1.4.4
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
asttokens==2.0.8
async-timeout==4.0.2
attrs==22.1.0
Babel==2.10.3
backcall==0.2.0
beautifulsoup4==4.11.1
bleach==5.0.1
certifi==2022.9.24
cffi==1.15.1
charset-normalizer==2.1.1
colorama==0.4.5
contourpy==1.0.5
cycler==0.11.0
debugpy==1.6.3
decorator==5.1.1
defusedxml==0.7.1
entrypoints==0.4
executing==1.1.1
fastjsonschema==2.16.2
fonttools==4.37.4
frozenlist==1.3.1
geomdl==5.3.1
googleapis-common-protos==1.56.4
grpcio==1.50.0
idna==3.4
imageio==2.22.2
importlib-metadata==5.0.0
ipykernel==6.16.0
ipython==8.5.0
ipython-genutils==0.2.0
jedi==0.18.1
Jinja2==3.1.2
json5==0.9.10
jsonschema==4.16.0
jupyter-server==1.21.0
jupyter_client==7.4.3
jupyter_core==4.11.2
jupyterlab==3.4.8
jupyterlab-pygments==0.2.2
jupyterlab_server==2.16.1
kiwisolver==1.4.4
MarkupSafe==2.1.1
matplotlib==3.6.1
matplotlib-inline==0.1.6
mistune==2.0.4
multidict==6.0.2
nbclassic==0.4.5
nbclient==0.7.0
nbconvert==7.2.2
nbformat==5.7.0
nest-asyncio==1.5.6
notebook==6.5.1
notebook_shim==0.2.0
numpy==1.23.4
packaging==21.3
pandocfilters==1.5.0
parso==0.8.3
pickleshare==0.7.5
Pillow==9.2.0
prometheus-client==0.15.0
prompt-toolkit==3.0.31
protobuf==3.20.3
protoc-gen-swagger==0.1.0
psutil==5.9.3
pure-eval==0.2.2
pycparser==2.21
Pygments==2.13.0
pyiges==0.2.1
pyparsing==3.0.9
pyrsistent==0.18.1
python-dateutil==2.8.2
pytz==2022.5
pyvista==0.36.1
pywin32==304
pywinpty==2.0.8
pyzmq==24.0.1
requests==2.28.1
scipy==1.9.2
scooby==0.6.0
Send2Trash==1.8.0
six==1.16.0
sniffio==1.3.0
soupsieve==2.3.2.post1
stack-data==0.5.1
terminado==0.16.0
tinycss2==1.2.1
tomli==2.0.1
tornado==6.2
tqdm==4.64.1
traitlets==5.5.0
urllib3==1.26.12
vtk==9.2.2
wcwidth==0.2.5
webencodings==0.5.1
websocket-client==1.4.1
wslink==1.8.4
yarl==1.8.1
zipp==3.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions