ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
431 stars 121 forks source link

MAPDL error when trying to launch with Python #352

Closed daleher closed 3 years ago

daleher commented 3 years ago

I have gone through the different installation processes stated in https://github.com/pyansys/pymapdl and they all work successfully.

However, I keep getting this error when trying to launch MAPDL locally from Python(v3.7.8).

I am trying to launch everything in a Conda environment, run from a Windows Subsystem for Linux.

ansys-mapdl

akaszynski commented 3 years ago

I am trying to launch everything in a Conda environment, run from a Windows Subsystem for Linux.

I'm guessing that there's a mismatch between the version numpy I used to compile ansys.mapdl.reader, and the version you have installed locally. Can you let me know what version of numpy you have installed?

daleher commented 3 years ago

Currently numpy-1.20.0 is installed.

I should say I've been able to run the MAPDL launcher when using

import pyansys mapdl = pyansys.launch_mapdl()

as opposed to

from ansys.mapdl.core import launch_mapdl

akaszynski commented 3 years ago

The legacy pyansys module was compiled with an older version of numpy and depending on which version of ansys-mapdl-reader you have installed, I might have compiled it with an incompatible version of numpy. Which version of ansys-mapdl-reader do you have installed? If it's not the latest, can you try upgrading with:

pip install ansys-mapdl-reader --upgrade
akaszynski commented 3 years ago

Something else I can do as well is remove the requirement to load the reader when running ansys-mapdl-core. The reader module is a bit heavy on dependencies and if you don't want to visualize, it's not a necessary component.

daleher commented 3 years ago

First of all, many thanks for the quick responses!

Now these are the versions I'm currently using for the different ansys-mapdl modules

ansys-mapdl_v2

I'm not sure whether they are the most up-to-date ones, but I've reinstalled with the --upgrade command on the mapdl-reader and I keep getting the same error. Maybe it's worth trying without the requirement of loading that module.

akaszynski commented 3 years ago

Did a little more research and came across this: https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

Seems that we're not alone with this issue. It might even be a Python 3.7 issue. Can you try Python 3.8 and see if that helps?

akaszynski commented 3 years ago

Just had a thought. Can you try downgrading the reader to 0.50.1? It might be that it's because it's compiled against numpy 1.20.1

Either way, I'll be removing this runtime dependency in the future so we won't have this issue. Best to keep it simple until we need the functionality.

daleher commented 3 years ago

Downgrading the reader to 0.50.1 works, as it successfully imports the launch_mapdl class from ansys-mapdl-core. However, when trying to run the example, a new error arises

image

Upgrading to python3.8 would cause some conflicts in my environment so unfortunately cannot be an option at the moment.

akaszynski commented 3 years ago

First off, I think the problem was with the build of 0.50.2, which I've fixed by yanking the build and rebuilding it as 0.50.3, which you can install sometime in the future. For whatever reason, on the day numpy==1.20.1 came out, any builds from that day were broken. When possible, I'd like to verify it works on your machine, but there's no rush.

As for the launcher, it looks like pymapdl can't find your locally installed ansys, and we should a more helpful error when this occurs on Linux. Since it seems like you're trying to launch Ansys while running on WSL, is Ansys installed as a windows application or a Linux Application? If it's Linux, you can launch it by providing the executable directory as an argument to launch_mapdl. If you want to connect to the Windows executable, you first need to launch MAPDL in gRPC mode and then "connect" to it. First, launch with

<ANSYS executable> -grpc

Here's the interesting part. You have an instance of MAPDL running on Windows, but you need to talk to it via WLS, which means that you can't just talk to 127.0.0.1 on WSL since it's on a different IP address. Within windows, you need to run ipconfig, and look for the WSL adapter. For example:

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 192.168.198.241
   Subnet Mask . . . . . . . . . . . : 255.255.255.240
   Default Gateway . . . . . . . . . :

That's the IP address assigned to WSL from within windows. You then connect to that address from python within WSL using:

>>> from ansys.mapdl.core import Mapdl
>>> mapdl = Mapdl('192.168.198.241')  # can specify non-default ports with port=50053
>>> mapdl.prep7()
*** ANSYS - ENGINEERING ANALYSIS SYSTEM  RELEASE 2021 R1          21.1     ***
DISTRIBUTED ANSYS Mechanical Enterprise                       

 00000000  VERSION=WINDOWS x64   08:59:02  FEB 10, 2021 CP=      1.266

          ***** ANSYS ANALYSIS DEFINITION (PREP7) *****

Note that despite running from Linux, I'm still talking to a "remote instance" of MAPDL on Windows.

daleher commented 3 years ago

Launching MAPDL in gRPC mode seems to generate that instance of MAPDL on Windows, but it does not stick and disappears in a mater of a second. It seems I cannot connect the WLS via the IP address before the MAPDL gRPC instance stops running.

image

jgd10 commented 3 years ago

I've also encountered a very similar issue to this in the latest release. I'm not sure if it's exactly the same though, as my situation is a bit different.

pip installed pyansys just today and fired up ipython to try it out; imported the package and got the same error as daleher did to begin with, but with these versions.

image

I'm on Windows and using python 3.8.6 and numpy 1.19 (also tried with 1.18 - same error). I was able to fix the issue in two separate ways:

Including my findings in case they can be of help :)

daleher commented 3 years ago

Were you able to launch_mapdl() or Mapdl() successfully @jgd10 ?

jgd10 commented 3 years ago

Yep. I was able to do it successfully after each of the bullet points (and I reset my system to the breaking setup between as well).

image

I also executed the function, but the results there are inconclusive. It didn't error, but also it didn't complete. I suspect I have an issue with my Ansys installation, but that's a separate issue.

akaszynski commented 3 years ago

It didn't error, but also it didn't complete. I suspect I have an issue with my Ansys installation, but that's a separate issue.

I've had problems launching MAPDL as well, and when launching in gRPC mode, the console window will pop up in the background without being able to see what the process standard output is.

To debug this, I'd first attempt to launch MAPDL without gRPC and see if it launches at all. If it does, then the window popping up and hiding is merely MAPDL running in the background

It seems I cannot connect the WLS via the IP address before the MAPDL gRPC instance stops running.

If you're sure the process is running (you can see the MAPDL process in the process tree). I'd verify that you can connect to the MAPDL instance from Windows first, and then trying it from WSL. Also, you're sure that the ip address is the address of the Windows adapter?

akaszynski commented 3 years ago

Finally have a solution for the ansys-mapdl-reader woes. Turns out the issue is that any package compiled with numpy>=1.20.0 cannot be loaded in an environment with numpy<1.20.0. It seems that it's backwards compatible though, so my fix will simply be to build on numpy<1.20.0, and then the package can be loaded on an environment with a modern but not bleeding edge of numpy.

jgd10 commented 3 years ago

I think this issue can now be closed, the only loose thread is my own hanging launch_mapdl() command which I have since discovered was due to an invalid license! So I'll close this issue as fixed for now.